Skip to content

Commit

Permalink
Merge pull request #57 from twinturbo/uglify-patch
Browse files Browse the repository at this point in the history
Only skip files with the ".min.js" postfix
  • Loading branch information
krisselden committed Nov 16, 2012
2 parents 53c3774 + 63a34d6 commit 7eb2863
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/rake-pipeline-web-filters/uglify_filter.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UglifyFilter < Rake::Pipeline::Filter
# {#output_name_generator}. # {#output_name_generator}.
def initialize(options={}, &block) def initialize(options={}, &block)
block ||= proc { |input| block ||= proc { |input|
if input =~ %r{min.js$} if input =~ %r{.min.js$}
input input
else else
input.sub(/\.js$/, '.min.js') input.sub(/\.js$/, '.min.js')
Expand All @@ -49,7 +49,7 @@ def initialize(options={}, &block)
# object representing the output. # object representing the output.
def generate_output(inputs, output) def generate_output(inputs, output)
inputs.each do |input| inputs.each do |input|
if input.path =~ %r{min.js$} if input.path =~ %r{.min.js$}
output.write input.read output.write input.read
else else
output.write Uglifier.compile(input.read, options) output.write Uglifier.compile(input.read, options)
Expand Down
34 changes: 25 additions & 9 deletions spec/uglify_filter_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,18 +47,34 @@ def setup_filter(filter)
file.encoding.should == "UTF-8" file.encoding.should == "UTF-8"
end end


it "skips minified files" do describe "Skipping" do
filter = setup_filter UglifyFilter.new it "skips files ending in .min.js" do
filter.input_files = [input_file("name.min.js", 'fake-js')] 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 = filter.generate_rake_tasks
tasks.each(&:invoke) tasks.each(&:invoke)


file = MemoryFileWrapper.files["/path/to/output/name.min.js"] file = MemoryFileWrapper.files["/path/to/output/name.min.js"]
file.body.should == 'fake-js' file.body.should == 'fake-js'
file.encoding.should == "UTF-8" 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 end


describe "naming output files" do describe "naming output files" do
Expand Down

0 comments on commit 7eb2863

Please sign in to comment.