Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Rake::Pipeline::PipelineFinalizingFilter
Change the filter we add to the end of every pipeline from
a ConcatFilter (which copies all inputs) to a PipelineFinalizingFilter,
which only copies the files that the pipeline created.
  • Loading branch information
dudleyf committed Jan 25, 2012
1 parent 76144b2 commit 4975f47
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
6 changes: 2 additions & 4 deletions lib/rake-pipeline/dsl.rb
@@ -1,5 +1,6 @@
module Rake
class Pipeline

# This class exists purely to provide a convenient DSL for
# configuring a pipeline.
#
Expand All @@ -22,9 +23,7 @@ class DSL
# @return [void]
def self.evaluate(pipeline, &block)
new(pipeline).instance_eval(&block)
copy_filter = Rake::Pipeline::ConcatFilter.new
copy_filter.output_name_generator = proc { |input| input }
pipeline.add_filter(copy_filter)
pipeline.add_filter(Rake::Pipeline::PipelineFinalizingFilter.new)
end

# Create a new {DSL} to configure a pipeline.
Expand Down Expand Up @@ -159,4 +158,3 @@ def concat(*args, &block)
end
end


1 change: 1 addition & 0 deletions lib/rake-pipeline/filters.rb
@@ -1,2 +1,3 @@
require "rake-pipeline/filters/concat_filter"
require "rake-pipeline/filters/ordering_concat_filter"
require "rake-pipeline/filters/pipeline_finalizing_filter"
18 changes: 18 additions & 0 deletions lib/rake-pipeline/filters/pipeline_finalizing_filter.rb
@@ -0,0 +1,18 @@
module Rake
class Pipeline
# @private
#
# A built-in filter that copies a pipeline's generated files over
# to its output.
class PipelineFinalizingFilter < ConcatFilter

# @return [Array[FileWrapper]] a list of the pipeline's
# output files, excluding any files that were originally
# inputs to the pipeline, meaning they weren't processed
# by any filter and should not be copied to the output.
def input_files
super.reject { |file| pipeline.input_files.include?(file) }
end
end
end
end
11 changes: 10 additions & 1 deletion spec/project_spec.rb
Expand Up @@ -33,8 +33,10 @@ def assetfile_digest
(Digest::SHA1.new << File.read(assetfile_path)).to_s
end

let(:unmatched_file) { input_file("junk.txt") }

let(:input_files) do
%w(jquery.js ember.js).map { |f| input_file(f) }
[input_file("jquery.js"), input_file("ember.js"), unmatched_file]
end

let(:output_files) do
Expand Down Expand Up @@ -83,6 +85,7 @@ def assetfile_digest
digest_dir = File.join(tmp, "tmp", "rake-pipeline-#{assetfile_digest}")
File.exist?(digest_dir).should be_true
end

end

describe "#invoke_clean" do
Expand Down Expand Up @@ -145,6 +148,12 @@ def rakep_tmpdirs
project.clean
output_files.each { |f| f.should_not exist }
end

it "leaves the pipeline's unmatched input files alone" do
project.invoke
project.clean
unmatched_file.should exist
end
end

describe ".add_to_digest" do
Expand Down
26 changes: 22 additions & 4 deletions spec/rake_acceptance_spec.rb
Expand Up @@ -26,10 +26,14 @@
}
HERE

"app/index.html" => <<-HERE
"app/index.html" => <<-HERE,
<html></html>
HERE

"app/junk.txt" => <<-HERE
junk
HERE

}

EXPECTED_JS_OUTPUT = <<-HERE
Expand Down Expand Up @@ -256,14 +260,17 @@ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
html = File.join(tmp, "public/index.html")
File.exists?(html).should be_true
File.read(html).should == EXPECTED_HTML_OUTPUT

junk = File.join(tmp, "public/junk.txt")
File.exists?(junk).should be_false
end

it_behaves_like "the pipeline DSL"

before do
@pipeline = Rake::Pipeline.build do
tmpdir "temporary"
input File.join(tmp, "app"), "**/*.{js,css,html}"
input File.join(tmp, "app")
output "public"

match "**/*.js" do
Expand All @@ -274,6 +281,10 @@ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
match "**/*.css" do
filter concat_filter, "stylesheets/application.css"
end

match "**/*.html" do
filter concat_filter
end
end
end
end
Expand Down Expand Up @@ -321,6 +332,9 @@ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
html = File.join(tmp, "public/index.html")
File.exists?(html).should be_true
File.read(html).should == EXPECTED_HTML_OUTPUT

junk = File.join(tmp, "public/junk.txt")
File.exists?(junk).should be_false
end

before do
Expand All @@ -329,8 +343,8 @@ def output_should_exist(expected=EXPECTED_JS_OUTPUT)

@pipeline = Rake::Pipeline.build do
tmpdir "temporary"
input File.join(tmp1, "app"), "**/*.{js,css,html}"
input File.join(tmp2, "app"), "**/*.{js,css,html}"
input File.join(tmp1, "app")
input File.join(tmp2, "app")

output "public"

Expand All @@ -342,6 +356,10 @@ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
match "**/*.css" do
filter concat_filter, "stylesheets/application.css"
end

match "**/*.html" do
filter concat_filter
end
end
end
end
Expand Down

0 comments on commit 4975f47

Please sign in to comment.