rake-pipeline-fork 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +12 -0
  5. data/.yardopts +2 -0
  6. data/GETTING_STARTED.md +268 -0
  7. data/Gemfile +14 -0
  8. data/LICENSE +20 -0
  9. data/README.markdown +11 -0
  10. data/README.yard +178 -0
  11. data/Rakefile +21 -0
  12. data/bin/rakep +4 -0
  13. data/examples/copying_files.md +12 -0
  14. data/examples/minifying_files.md +37 -0
  15. data/examples/modifying_pipelines.md +67 -0
  16. data/examples/multiple_pipelines.md +77 -0
  17. data/lib/generators/rake/pipeline/install/install_generator.rb +70 -0
  18. data/lib/rake-pipeline.rb +462 -0
  19. data/lib/rake-pipeline/cli.rb +56 -0
  20. data/lib/rake-pipeline/dsl.rb +9 -0
  21. data/lib/rake-pipeline/dsl/pipeline_dsl.rb +246 -0
  22. data/lib/rake-pipeline/dsl/project_dsl.rb +108 -0
  23. data/lib/rake-pipeline/dynamic_file_task.rb +194 -0
  24. data/lib/rake-pipeline/error.rb +17 -0
  25. data/lib/rake-pipeline/file_wrapper.rb +182 -0
  26. data/lib/rake-pipeline/filter.rb +249 -0
  27. data/lib/rake-pipeline/filters.rb +4 -0
  28. data/lib/rake-pipeline/filters/concat_filter.rb +63 -0
  29. data/lib/rake-pipeline/filters/gsub_filter.rb +56 -0
  30. data/lib/rake-pipeline/filters/ordering_concat_filter.rb +38 -0
  31. data/lib/rake-pipeline/filters/pipeline_finalizing_filter.rb +21 -0
  32. data/lib/rake-pipeline/graph.rb +178 -0
  33. data/lib/rake-pipeline/manifest.rb +86 -0
  34. data/lib/rake-pipeline/manifest_entry.rb +34 -0
  35. data/lib/rake-pipeline/matcher.rb +141 -0
  36. data/lib/rake-pipeline/middleware.rb +72 -0
  37. data/lib/rake-pipeline/precompile.rake +8 -0
  38. data/lib/rake-pipeline/project.rb +335 -0
  39. data/lib/rake-pipeline/rails_plugin.rb +10 -0
  40. data/lib/rake-pipeline/railtie.rb +34 -0
  41. data/lib/rake-pipeline/reject_matcher.rb +29 -0
  42. data/lib/rake-pipeline/server.rb +15 -0
  43. data/lib/rake-pipeline/sorted_pipeline.rb +19 -0
  44. data/lib/rake-pipeline/version.rb +6 -0
  45. data/rails/init.rb +2 -0
  46. data/rake-pipeline.gemspec +24 -0
  47. data/spec/cli_spec.rb +71 -0
  48. data/spec/concat_filter_spec.rb +37 -0
  49. data/spec/dsl/pipeline_dsl_spec.rb +165 -0
  50. data/spec/dsl/project_dsl_spec.rb +41 -0
  51. data/spec/dynamic_file_task_spec.rb +119 -0
  52. data/spec/encoding_spec.rb +106 -0
  53. data/spec/file_wrapper_spec.rb +132 -0
  54. data/spec/filter_spec.rb +332 -0
  55. data/spec/graph_spec.rb +56 -0
  56. data/spec/gsub_filter_spec.rb +87 -0
  57. data/spec/manifest_entry_spec.rb +46 -0
  58. data/spec/manifest_spec.rb +67 -0
  59. data/spec/matcher_spec.rb +141 -0
  60. data/spec/middleware_spec.rb +199 -0
  61. data/spec/ordering_concat_filter_spec.rb +42 -0
  62. data/spec/pipeline_spec.rb +232 -0
  63. data/spec/project_spec.rb +295 -0
  64. data/spec/rake_acceptance_spec.rb +738 -0
  65. data/spec/rake_tasks_spec.rb +21 -0
  66. data/spec/reject_matcher_spec.rb +31 -0
  67. data/spec/sorted_pipeline_spec.rb +27 -0
  68. data/spec/spec_helper.rb +38 -0
  69. data/spec/support/spec_helpers/file_utils.rb +35 -0
  70. data/spec/support/spec_helpers/filters.rb +37 -0
  71. data/spec/support/spec_helpers/input_helpers.rb +23 -0
  72. data/spec/support/spec_helpers/memory_file_wrapper.rb +31 -0
  73. data/spec/support/spec_helpers/memory_manifest.rb +19 -0
  74. data/tools/perfs +101 -0
  75. metadata +215 -0
@@ -0,0 +1,10 @@
1
+ require 'rake-pipeline/middleware'
2
+
3
+ Rails.configuration.after_initialize do
4
+ if defined?(RAKEP_ENABLED) && RAKEP_ENABLED
5
+ assetfile = defined?(RAKEP_ASSETFILE) ? RAKEP_ASSETFILE : 'Assetfile'
6
+ project = Rake::Pipeline::Project.new assetfile
7
+
8
+ Rails.configuration.middleware.use Rake::Pipeline::Middleware, project
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ require "rake-pipeline/middleware"
2
+
3
+ module Rake
4
+ class Pipeline
5
+ # Use Rake::Pipeline inside of Rails 3.x. To use, simply add
6
+ # Rake::Pipeline to your +Gemfile+:
7
+ #
8
+ # !!!ruby
9
+ # gem 'rake-pipeline'
10
+ #
11
+ # Then, activate it in development mode. In config/development.rb:
12
+ #
13
+ # !!!ruby
14
+ # config.rake_pipeline_enabled = true
15
+ #
16
+ class Railtie < ::Rails::Railtie
17
+ config.rake_pipeline_enabled = false
18
+ config.rake_pipeline_assetfile = 'Assetfile'
19
+
20
+ rake_tasks do
21
+ load "rake-pipeline/precompile.rake"
22
+ end
23
+
24
+ initializer "rake-pipeline.assetfile" do |app|
25
+ if config.rake_pipeline_enabled
26
+ assetfile = File.join(Rails.root, config.rake_pipeline_assetfile)
27
+ project = Rake::Pipeline::Project.new assetfile
28
+
29
+ config.app_middleware.insert ActionDispatch::Static, Rake::Pipeline::Middleware, project
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ module Rake
2
+ class Pipeline
3
+ # A RejectMatcher is a pipeline that does no processing. It
4
+ # simply filters out some files. You can use this when
5
+ # you have more complex logic that doesn't fit nicely
6
+ # in a glob.
7
+ #
8
+ # You can pass a block or a glob (just like {DSL#match}).
9
+ # Files matching the glob will be rejected from the pipeline.
10
+ # Files are rejected when the block evaluates to true. Specify
11
+ # either a glob or a block.
12
+ #
13
+ # In general, you should not use RejectMatcher directly. Instead use
14
+ # {DSL#reject} in the block passed to {Pipeline.build}.
15
+ class RejectMatcher < Matcher
16
+ attr_accessor :block
17
+
18
+ def output_files
19
+ input_files.reject do |file|
20
+ if block
21
+ block.call file
22
+ else
23
+ file.path =~ @pattern
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ require "rake-pipeline/middleware"
2
+ require "rack/server"
3
+
4
+ module Rake
5
+ class Pipeline
6
+ class Server < Rack::Server
7
+ def app
8
+ not_found = proc { [404, { "Content-Type" => "text/plain" }, ["not found"]] }
9
+ project = Rake::Pipeline::Project.new "Assetfile"
10
+
11
+ Middleware.new(not_found, project)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Rake
2
+ class Pipeline
3
+ class SortedPipeline < Pipeline
4
+ attr_accessor :pipeline, :comparator
5
+
6
+ def output_files
7
+ input_files.sort(&comparator)
8
+ end
9
+
10
+ # Override {Pipeline#finalize} to do nothing. We want to pass
11
+ # on our unmatched inputs to the next part of the pipeline.
12
+ #
13
+ # @return [void]
14
+ # @api private
15
+ def finalize
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ module Rake
2
+ class Pipeline
3
+ # @version 0.8.0
4
+ VERSION = "0.8.0"
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ # For Rails 2
2
+ require 'rake-pipeline'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rake-pipeline/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Yehuda Katz", "Tom Dale"]
6
+ gem.email = ["wycats@gmail.com"]
7
+ gem.description = "Simple Asset Management"
8
+ gem.summary = "Simple Asset Management"
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "rake-pipeline-fork"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Rake::Pipeline::VERSION
17
+
18
+ gem.add_dependency "rake", "~> 10.0.0"
19
+ gem.add_dependency "thor"
20
+ gem.add_dependency "json"
21
+
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "rack-test"
24
+ end
@@ -0,0 +1,71 @@
1
+ describe "Rake::Pipeline::CLI" do
2
+ attr_reader :project, :pipeline
3
+
4
+ before do
5
+ @project = Rake::Pipeline::Project.new
6
+ @project.stub(:clean)
7
+ @project.stub(:invoke)
8
+ @project.stub(:output_files).and_return([])
9
+ Rake::Pipeline::Project.stub(:new).and_return(@project)
10
+ end
11
+
12
+ def rakep(*args)
13
+ Rake::Pipeline::CLI.start(args)
14
+ end
15
+
16
+ describe "build" do
17
+ context "with no arguments" do
18
+ it "invokes a project" do
19
+ project.should_receive :invoke
20
+ rakep "build"
21
+ end
22
+
23
+ it "cleans up the tmpdir" do
24
+ project.should_receive :cleanup_tmpdir
25
+ rakep "build"
26
+ end
27
+ end
28
+
29
+ context "with a --pretend argument" do
30
+ it "doesn't invoke a project" do
31
+ project.should_not_receive :invoke
32
+ rakep "build", "--pretend"
33
+ end
34
+ end
35
+
36
+ context "with a --clean argument" do
37
+ it "cleans a project" do
38
+ project.should_receive :clean
39
+ rakep "build", "--clean"
40
+ end
41
+
42
+ it "invokes a project" do
43
+ project.should_receive :invoke
44
+ rakep "build", "--clean"
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "clean" do
50
+ context "with no arguments" do
51
+ it "cleans a project" do
52
+ project.should_receive :clean
53
+ rakep "clean"
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "server" do
59
+ let(:server) { double "server" }
60
+
61
+ before do
62
+ require 'rake-pipeline/server'
63
+ Rake::Pipeline::Server.stub(:new).and_return(server)
64
+ end
65
+
66
+ it "starts a Rake::Pipeline::Server" do
67
+ server.should_receive :start
68
+ rakep "server"
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,37 @@
1
+ describe "ConcatFilter" do
2
+ MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
3
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
4
+
5
+ let(:input_files) {
6
+ [
7
+ MemoryFileWrapper.new("/path/to/input", "javascripts/jquery.js", "UTF-8", "jQuery = {};"),
8
+ MemoryFileWrapper.new("/path/to/input", "javascripts/sproutcore.js", "UTF-8", "SC = {};")
9
+ ]
10
+ }
11
+
12
+ it "generates output" do
13
+ filter = Rake::Pipeline::ConcatFilter.new { "application.js" }
14
+ filter.manifest = MemoryManifest.new
15
+ filter.last_manifest = MemoryManifest.new
16
+ filter.file_wrapper_class = MemoryFileWrapper
17
+ filter.output_root = "/path/to/output"
18
+ filter.input_files = input_files
19
+
20
+ filter.output_files.should == [MemoryFileWrapper.new("/path/to/output", "application.js", "BINARY")]
21
+
22
+ tasks = filter.generate_rake_tasks
23
+ tasks.each(&:invoke)
24
+
25
+ file = MemoryFileWrapper.files["/path/to/output/application.js"]
26
+ file.body.should == "jQuery = {};SC = {};"
27
+ file.encoding.should == "BINARY"
28
+ end
29
+
30
+ it "accepts a string to use as the output file name" do
31
+ filter = Rake::Pipeline::ConcatFilter.new("app.js")
32
+ filter.file_wrapper_class = MemoryFileWrapper
33
+ filter.output_root = "/path/to/output"
34
+ filter.input_files = input_files
35
+ filter.output_files.should == [MemoryFileWrapper.new("/path/to/output", "app.js", "BINARY")]
36
+ end
37
+ end
@@ -0,0 +1,165 @@
1
+ describe "Rake::Pipeline::PipelineDSL" do
2
+ ConcatFilter = Rake::Pipeline::SpecHelpers::Filters::ConcatFilter
3
+
4
+ let(:pipeline) { Rake::Pipeline.new }
5
+ let(:dsl) { Rake::Pipeline::DSL::PipelineDSL.new(pipeline) }
6
+
7
+ def filter
8
+ pipeline.filters.last
9
+ end
10
+
11
+ it "accepts a pipeline in its constructor" do
12
+ dsl.pipeline.should == pipeline
13
+ end
14
+
15
+ describe "#input" do
16
+ it "adds an input to the pipeline" do
17
+ dsl.input "/app"
18
+ pipeline.inputs["/app"].should == '**/*'
19
+ end
20
+
21
+ it "configures the input's glob" do
22
+ dsl.input "/app", "*.js"
23
+ pipeline.inputs['/app'].should == "*.js"
24
+ end
25
+
26
+ it "defaults input's glob to **/*" do
27
+ dsl.input "/app"
28
+ pipeline.inputs['/app'].should == "**/*"
29
+ end
30
+ end
31
+
32
+ describe "#filter" do
33
+
34
+ it "adds a new instance of the filter class to the pipeline's filters" do
35
+ pipeline.filters.should be_empty
36
+ dsl.filter ConcatFilter
37
+ pipeline.filters.should_not be_empty
38
+ filter.should be_kind_of(ConcatFilter)
39
+ end
40
+
41
+ it "takes a block to configure the filter's output file names" do
42
+ generator = proc { |input| "main.js" }
43
+ dsl.filter(ConcatFilter, &generator)
44
+ filter.output_name_generator.should == generator
45
+ end
46
+
47
+ it "passes any extra arguments to the filter's constructor" do
48
+ filter_class = Class.new(Rake::Pipeline::Filter) do
49
+ attr_reader :args
50
+ def initialize(*args)
51
+ @args = args
52
+ end
53
+ end
54
+
55
+ dsl.filter filter_class, "foo", "bar"
56
+ filter.args.should == %w(foo bar)
57
+ end
58
+ end
59
+
60
+ describe "#match" do
61
+ it "creates a Matcher for the given glob" do
62
+ matcher = dsl.match("*.glob") {}
63
+ matcher.should be_kind_of(Rake::Pipeline::Matcher)
64
+ matcher.glob.should == "*.glob"
65
+ end
66
+
67
+ it "adds the new matcher to the pipeline's filters" do
68
+ matcher = dsl.match("*.glob") {}
69
+ filter.should == matcher
70
+ end
71
+ end
72
+
73
+ describe "#output" do
74
+ it "configures the pipeline's output_root" do
75
+ dsl.output "/path/to/output"
76
+ pipeline.output_root.should == "/path/to/output"
77
+ end
78
+ end
79
+
80
+ describe "#concat" do
81
+ it "creates a ConcatFilter" do
82
+ dsl.concat "octopus"
83
+ filter.should be_kind_of(Rake::Pipeline::ConcatFilter)
84
+ end
85
+
86
+ context "passed an Array first argument" do
87
+ it "creates an OrderingConcatFilter" do
88
+ dsl.concat ["octopus"]
89
+ filter.should be_kind_of(Rake::Pipeline::OrderingConcatFilter)
90
+ end
91
+ end
92
+ end
93
+
94
+ describe "#sort" do
95
+ it "adds a SortedPipeline for the given comparator" do
96
+ comparator = proc { }
97
+ matcher = dsl.sort(&comparator)
98
+ matcher.should be_kind_of(Rake::Pipeline::SortedPipeline)
99
+ matcher.comparator.should == comparator
100
+ end
101
+ end
102
+
103
+ describe "#copy" do
104
+ it "creates a ConcatFilter" do
105
+ dsl.copy
106
+ filter.should be_kind_of(Rake::Pipeline::ConcatFilter)
107
+ end
108
+ end
109
+
110
+ describe "#reject" do
111
+ it "creates a new RejectMatcher for the given glob" do
112
+ matcher = dsl.reject("*.glob") {}
113
+ matcher.should be_kind_of(Rake::Pipeline::RejectMatcher)
114
+ matcher.glob.should == "*.glob"
115
+ end
116
+
117
+ it "creates a new RejectMatcher with the given block" do
118
+ block = proc { }
119
+ matcher = dsl.reject(&block)
120
+ matcher.should be_kind_of(Rake::Pipeline::RejectMatcher)
121
+ matcher.block.should == block
122
+ end
123
+
124
+ it "adds the new reject matcher to the pipeline's filters" do
125
+ matcher = dsl.reject("*.glob") {}
126
+ filter.should == matcher
127
+ end
128
+ end
129
+
130
+ describe "#skip" do
131
+ it "adds a new RejectMatcher" do
132
+ dsl.skip "*.glob"
133
+ filter.should be_kind_of(Rake::Pipeline::RejectMatcher)
134
+ end
135
+ end
136
+
137
+ describe "#exclude" do
138
+ it "adds a new RejectMatcher" do
139
+ dsl.exclude "*.glob"
140
+ filter.should be_kind_of(Rake::Pipeline::RejectMatcher)
141
+ end
142
+ end
143
+
144
+ describe "#gsub" do
145
+ it "creates a GsubFilter" do
146
+ dsl.gsub
147
+ filter.should be_kind_of(Rake::Pipeline::GsubFilter)
148
+ end
149
+ end
150
+
151
+ describe "#replace" do
152
+ it "creates a GsubFilter" do
153
+ dsl.replace
154
+ filter.should be_kind_of(Rake::Pipeline::GsubFilter)
155
+ end
156
+ end
157
+
158
+ describe "#strip" do
159
+ it "creates a GsubFilter with no replacement" do
160
+ regex = /mock/
161
+ dsl.should_receive(:filter).with(Rake::Pipeline::GsubFilter, regex, '')
162
+ dsl.strip /mock/
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,41 @@
1
+ describe "Rake::Pipeline::ProjectDSL" do
2
+ ConcatFilter ||= Rake::Pipeline::SpecHelpers::Filters::ConcatFilter
3
+
4
+ let(:project) { Rake::Pipeline::Project.new }
5
+ let(:dsl) { Rake::Pipeline::DSL::ProjectDSL.new(project) }
6
+
7
+ it "accepts a project in its constructor" do
8
+ dsl.project.should == project
9
+ end
10
+
11
+ describe "#output" do
12
+ it "configures the project's default_output_root" do
13
+ dsl.output "/path/to/output"
14
+ project.default_output_root.should == "/path/to/output"
15
+ end
16
+ end
17
+
18
+ describe "#tmpdir" do
19
+ it "sets the project's tmpdir" do
20
+ dsl.tmpdir "/path/to/tmpdir"
21
+ project.tmpdir.should == "/path/to/tmpdir"
22
+ end
23
+ end
24
+
25
+ describe "#input" do
26
+ it "uses Project#build_pipeline to add a new pipeline to the project" do
27
+ project.should_receive(:build_pipeline)
28
+ dsl.input("app") {}
29
+ end
30
+ end
31
+
32
+ describe "#map" do
33
+ it "saves the block in a hash on the project" do
34
+ project.maps.keys.size.should == 0
35
+ run_me = lambda { }
36
+ dsl.map("foo", &run_me)
37
+ dsl.project.maps["foo"].should == run_me
38
+ end
39
+ end
40
+ end
41
+