Skip to content
Browse files

Merge pull request #38 from dudleyf/final-filter

Add Rake::Pipeline::PipelineFinalizingFilter
  • Loading branch information...
2 parents 76144b2 + 4975f47 commit 5ab27c33bcecdc6f156c2e1ead5d5e831bc1acbd @wycats wycats committed
View
6 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.
#
@@ -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.
@@ -159,4 +158,3 @@ def concat(*args, &block)
end
end
-
View
1 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"
View
18 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
View
11 spec/project_spec.rb
@@ -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
@@ -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
@@ -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
View
26 spec/rake_acceptance_spec.rb
@@ -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
@@ -256,6 +260,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
it_behaves_like "the pipeline DSL"
@@ -263,7 +270,7 @@ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
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
@@ -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
@@ -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
@@ -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"
@@ -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

0 comments on commit 5ab27c3

Please sign in to comment.
Something went wrong with that request. Please try again.