Permalink
Browse files

Merge pull request #57 from twinturbo/uglify-patch

Only skip files with the ".min.js" postfix
  • Loading branch information...
2 parents 53c3774 + 63a34d6 commit 7eb2863f8a6370333a348dddb2667fcded1d8b14 @krisselden krisselden committed Nov 16, 2012
Showing with 27 additions and 11 deletions.
  1. +2 −2 lib/rake-pipeline-web-filters/uglify_filter.rb
  2. +25 −9 spec/uglify_filter_spec.rb
@@ -28,7 +28,7 @@ class UglifyFilter < Rake::Pipeline::Filter
# {#output_name_generator}.
def initialize(options={}, &block)
block ||= proc { |input|
- if input =~ %r{min.js$}
+ if input =~ %r{.min.js$}
input
else
input.sub(/\.js$/, '.min.js')
@@ -49,7 +49,7 @@ def initialize(options={}, &block)
# object representing the output.
def generate_output(inputs, output)
inputs.each do |input|
- if input.path =~ %r{min.js$}
+ if input.path =~ %r{.min.js$}
output.write input.read
else
output.write Uglifier.compile(input.read, options)
@@ -47,18 +47,34 @@ def setup_filter(filter)
file.encoding.should == "UTF-8"
end
- it "skips minified files" do
- filter = setup_filter UglifyFilter.new
- filter.input_files = [input_file("name.min.js", 'fake-js')]
+ describe "Skipping" do
+ it "skips files ending in .min.js" do
+ filter = setup_filter UglifyFilter.new
+ filter.input_files = [input_file("name.min.js", 'fake-js')]
- filter.output_files.should == [output_file("name.min.js")]
+ filter.output_files.should == [output_file("name.min.js")]
- tasks = filter.generate_rake_tasks
- tasks.each(&:invoke)
+ tasks = filter.generate_rake_tasks
+ tasks.each(&:invoke)
- file = MemoryFileWrapper.files["/path/to/output/name.min.js"]
- file.body.should == 'fake-js'
- file.encoding.should == "UTF-8"
+ file = MemoryFileWrapper.files["/path/to/output/name.min.js"]
+ file.body.should == 'fake-js'
+ file.encoding.should == "UTF-8"
+ end
+
+ it "does not count files ending in min.js as preminified" do
+ filter = setup_filter UglifyFilter.new
+ filter.input_files = [input_file("min.js", js_input)]
+
+ filter.output_files.should == [output_file("min.min.js")]
+
+ tasks = filter.generate_rake_tasks
+ tasks.each(&:invoke)
+
+ file = MemoryFileWrapper.files["/path/to/output/min.min.js"]
+ file.body.should == expected_js_output
+ file.encoding.should == "UTF-8"
+ end
end
describe "naming output files" do

0 comments on commit 7eb2863

Please sign in to comment.