Class: Rake::Pipeline::Web::Filters::UglifyFilter
- Inherits:
-
Filter
- Object
- Filter
- Rake::Pipeline::Web::Filters::UglifyFilter
- Includes:
- FilterWithDependencies
- Defined in:
- lib/rake-pipeline-web-filters/uglify_filter.rb
Overview
A filter that uses the Uglify JS compressor to compress JavaScript input files.
Requires uglifier.
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
A hash of options to pass to Uglify when compiling.
Instance Method Summary collapse
-
#generate_output(inputs, output) ⇒ Object
Implement the #generate_output method required by the Filter API.
-
#initialize(options = {}, &block) ⇒ UglifyFilter
constructor
A new instance of UglifyFilter.
Constructor Details
#initialize(options = {}, &block) ⇒ UglifyFilter
Returns a new instance of UglifyFilter.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rake-pipeline-web-filters/uglify_filter.rb', line 29 def initialize(={}, &block) block ||= proc { |input| if input =~ %r{min.js$} input else input.sub(/\.js$/, '.min.js') end } super(&block) @options = end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns a hash of options to pass to Uglify when compiling.
24 25 26 |
# File 'lib/rake-pipeline-web-filters/uglify_filter.rb', line 24 def @options end |
Instance Method Details
#generate_output(inputs, output) ⇒ Object
Implement the #generate_output method required by the Filter API. Compiles each input file with Uglify.
50 51 52 53 54 55 56 57 58 |
# File 'lib/rake-pipeline-web-filters/uglify_filter.rb', line 50 def generate_output(inputs, output) inputs.each do |input| if input.path =~ %r{min.js$} output.write input.read else output.write Uglifier.compile(input.read, ) end end end |