benoit 0.1.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 (164) hide show
  1. data/.gitignore +4 -0
  2. data/.gitmodules +3 -0
  3. data/.rspec +1 -0
  4. data/.rspec-turnip +1 -0
  5. data/.ruby-version +1 -0
  6. data/Assetfile +44 -0
  7. data/Gemfile +5 -0
  8. data/Gemfile.lock +110 -0
  9. data/Rakefile +9 -0
  10. data/benoit.gemspec +50 -0
  11. data/bin/benoit +121 -0
  12. data/bin/bundle-development +1 -0
  13. data/bin/bundle-sandbox +1 -0
  14. data/lib/benoit.rb +36 -0
  15. data/lib/benoit/cadenza.rb +11 -0
  16. data/lib/benoit/cadenza/output_filters.rb +21 -0
  17. data/lib/benoit/cleaner.rb +10 -0
  18. data/lib/benoit/compiler_error.rb +49 -0
  19. data/lib/benoit/configuration.rb +24 -0
  20. data/lib/benoit/current_site.rb +12 -0
  21. data/lib/benoit/file_wrapper_extensions.rb +13 -0
  22. data/lib/benoit/filters.rb +15 -0
  23. data/lib/benoit/filters/base_filter.rb +44 -0
  24. data/lib/benoit/filters/blacklist_filter.rb +18 -0
  25. data/lib/benoit/filters/cadenza_filter.rb +75 -0
  26. data/lib/benoit/filters/content_page_filter.rb +45 -0
  27. data/lib/benoit/filters/markdown_filter.rb +19 -0
  28. data/lib/benoit/filters/metadata_cleaner.rb +30 -0
  29. data/lib/benoit/filters/move_to_root_filter.rb +22 -0
  30. data/lib/benoit/filters/pagination_filter.rb +23 -0
  31. data/lib/benoit/filters/pass_thru_filter.rb +22 -0
  32. data/lib/benoit/filters/sass_filter.rb +74 -0
  33. data/lib/benoit/filters/set_metadata_filter.rb +15 -0
  34. data/lib/benoit/logger.rb +69 -0
  35. data/lib/benoit/page.rb +88 -0
  36. data/lib/benoit/page_metadata.rb +8 -0
  37. data/lib/benoit/page_metadata/container.rb +74 -0
  38. data/lib/benoit/page_metadata/json_converter.rb +28 -0
  39. data/lib/benoit/page_metadata/parser.rb +38 -0
  40. data/lib/benoit/page_metadata/store.rb +75 -0
  41. data/lib/benoit/pipeline.rb +1 -0
  42. data/lib/benoit/pipeline/dsl_extensions.rb +8 -0
  43. data/lib/benoit/pipeline/pagination_matcher.rb +53 -0
  44. data/lib/benoit/pipeline_project.rb +81 -0
  45. data/lib/benoit/site_context.rb +123 -0
  46. data/lib/benoit/utils/finds_layouts_for_template.rb +77 -0
  47. data/lib/benoit/utils/normalizes_path_to_template.rb +43 -0
  48. data/lib/benoit/utils/paginated_list.rb +102 -0
  49. data/lib/benoit/version.rb +3 -0
  50. data/lib/build_notifiers/file_built_notifier.rb +20 -0
  51. data/lib/build_notifiers/progress_notifier.rb +57 -0
  52. data/lib/cli.rb +39 -0
  53. data/spec/.rbenv-gemsets +1 -0
  54. data/spec/Gemfile +9 -0
  55. data/spec/Gemfile.lock +57 -0
  56. data/spec/bin/autospec +16 -0
  57. data/spec/bin/cucumber +16 -0
  58. data/spec/bin/htmldiff +16 -0
  59. data/spec/bin/ldiff +16 -0
  60. data/spec/bin/rspec +16 -0
  61. data/spec/features/build_command.feature +46 -0
  62. data/spec/features/frontmatter_metadata.feature +99 -0
  63. data/spec/features/javascript_files.feature +35 -0
  64. data/spec/features/output_filters.feature +20 -0
  65. data/spec/features/page_layouts.feature +72 -0
  66. data/spec/features/pagination.feature +58 -0
  67. data/spec/features/sass_files.feature +30 -0
  68. data/spec/features/version.feature +5 -0
  69. data/spec/lib/filters/base_filter_spec.rb +141 -0
  70. data/spec/lib/filters/markdown_filter_spec.rb +65 -0
  71. data/spec/lib/filters/sass_filter_spec.rb +73 -0
  72. data/spec/lib/metadata_json_converter_spec.rb +65 -0
  73. data/spec/lib/metadata_store_spec.rb +148 -0
  74. data/spec/lib/page_spec.rb +19 -0
  75. data/spec/lib/site_context_spec.rb +106 -0
  76. data/spec/spec_helper.rb +16 -0
  77. data/spec/steps/output_file_steps.rb +45 -0
  78. data/spec/steps/run_steps.rb +71 -0
  79. data/spec/steps/staticly_steps.rb +194 -0
  80. data/spec/support/aruba/rspec.rb +66 -0
  81. data/spec/support/files/img.png +0 -0
  82. data/spec/support/files/input.css.scss +7 -0
  83. data/spec/support/files/input.scss +7 -0
  84. data/spec/support/spec_helpers/file_helpers.rb +8 -0
  85. data/spec/support/spec_helpers/memory_file_wrapper.rb +43 -0
  86. data/spec/support/spec_helpers/memory_manifest.rb +19 -0
  87. data/spec/turnip_helper.rb +19 -0
  88. data/vendor/frontmatter/frontmatter.gemspec +24 -0
  89. data/vendor/frontmatter/lib/frontmatter.rb +92 -0
  90. data/vendor/frontmatter/lib/frontmatter/version.rb +3 -0
  91. data/vendor/rake-pipeline/.gitignore +18 -0
  92. data/vendor/rake-pipeline/.rspec +1 -0
  93. data/vendor/rake-pipeline/.travis.yml +12 -0
  94. data/vendor/rake-pipeline/.yardopts +2 -0
  95. data/vendor/rake-pipeline/GETTING_STARTED.md +268 -0
  96. data/vendor/rake-pipeline/Gemfile +14 -0
  97. data/vendor/rake-pipeline/LICENSE +20 -0
  98. data/vendor/rake-pipeline/README.markdown +11 -0
  99. data/vendor/rake-pipeline/README.yard +178 -0
  100. data/vendor/rake-pipeline/Rakefile +21 -0
  101. data/vendor/rake-pipeline/bin/rakep +4 -0
  102. data/vendor/rake-pipeline/examples/copying_files.md +12 -0
  103. data/vendor/rake-pipeline/examples/minifying_files.md +37 -0
  104. data/vendor/rake-pipeline/examples/modifying_pipelines.md +67 -0
  105. data/vendor/rake-pipeline/examples/multiple_pipelines.md +77 -0
  106. data/vendor/rake-pipeline/lib/generators/rake/pipeline/install/install_generator.rb +70 -0
  107. data/vendor/rake-pipeline/lib/rake-pipeline.rb +509 -0
  108. data/vendor/rake-pipeline/lib/rake-pipeline/cli.rb +57 -0
  109. data/vendor/rake-pipeline/lib/rake-pipeline/dsl.rb +9 -0
  110. data/vendor/rake-pipeline/lib/rake-pipeline/dsl/pipeline_dsl.rb +246 -0
  111. data/vendor/rake-pipeline/lib/rake-pipeline/dsl/project_dsl.rb +108 -0
  112. data/vendor/rake-pipeline/lib/rake-pipeline/dynamic_file_task.rb +194 -0
  113. data/vendor/rake-pipeline/lib/rake-pipeline/error.rb +17 -0
  114. data/vendor/rake-pipeline/lib/rake-pipeline/file_wrapper.rb +195 -0
  115. data/vendor/rake-pipeline/lib/rake-pipeline/filter.rb +267 -0
  116. data/vendor/rake-pipeline/lib/rake-pipeline/filters.rb +4 -0
  117. data/vendor/rake-pipeline/lib/rake-pipeline/filters/concat_filter.rb +63 -0
  118. data/vendor/rake-pipeline/lib/rake-pipeline/filters/gsub_filter.rb +56 -0
  119. data/vendor/rake-pipeline/lib/rake-pipeline/filters/ordering_concat_filter.rb +38 -0
  120. data/vendor/rake-pipeline/lib/rake-pipeline/filters/pipeline_finalizing_filter.rb +21 -0
  121. data/vendor/rake-pipeline/lib/rake-pipeline/graph.rb +178 -0
  122. data/vendor/rake-pipeline/lib/rake-pipeline/manifest.rb +82 -0
  123. data/vendor/rake-pipeline/lib/rake-pipeline/manifest_entry.rb +34 -0
  124. data/vendor/rake-pipeline/lib/rake-pipeline/matcher.rb +141 -0
  125. data/vendor/rake-pipeline/lib/rake-pipeline/middleware.rb +73 -0
  126. data/vendor/rake-pipeline/lib/rake-pipeline/precompile.rake +8 -0
  127. data/vendor/rake-pipeline/lib/rake-pipeline/project.rb +338 -0
  128. data/vendor/rake-pipeline/lib/rake-pipeline/rails_plugin.rb +10 -0
  129. data/vendor/rake-pipeline/lib/rake-pipeline/railtie.rb +34 -0
  130. data/vendor/rake-pipeline/lib/rake-pipeline/reject_matcher.rb +29 -0
  131. data/vendor/rake-pipeline/lib/rake-pipeline/server.rb +15 -0
  132. data/vendor/rake-pipeline/lib/rake-pipeline/sorted_pipeline.rb +19 -0
  133. data/vendor/rake-pipeline/lib/rake-pipeline/version.rb +6 -0
  134. data/vendor/rake-pipeline/rails/init.rb +2 -0
  135. data/vendor/rake-pipeline/rake-pipeline.gemspec +24 -0
  136. data/vendor/rake-pipeline/spec/cli_spec.rb +73 -0
  137. data/vendor/rake-pipeline/spec/concat_filter_spec.rb +37 -0
  138. data/vendor/rake-pipeline/spec/dsl/pipeline_dsl_spec.rb +165 -0
  139. data/vendor/rake-pipeline/spec/dsl/project_dsl_spec.rb +41 -0
  140. data/vendor/rake-pipeline/spec/dynamic_file_task_spec.rb +119 -0
  141. data/vendor/rake-pipeline/spec/encoding_spec.rb +106 -0
  142. data/vendor/rake-pipeline/spec/file_wrapper_spec.rb +132 -0
  143. data/vendor/rake-pipeline/spec/filter_spec.rb +367 -0
  144. data/vendor/rake-pipeline/spec/graph_spec.rb +56 -0
  145. data/vendor/rake-pipeline/spec/gsub_filter_spec.rb +87 -0
  146. data/vendor/rake-pipeline/spec/manifest_entry_spec.rb +46 -0
  147. data/vendor/rake-pipeline/spec/manifest_spec.rb +67 -0
  148. data/vendor/rake-pipeline/spec/matcher_spec.rb +141 -0
  149. data/vendor/rake-pipeline/spec/middleware_spec.rb +199 -0
  150. data/vendor/rake-pipeline/spec/ordering_concat_filter_spec.rb +42 -0
  151. data/vendor/rake-pipeline/spec/pipeline_spec.rb +232 -0
  152. data/vendor/rake-pipeline/spec/project_spec.rb +295 -0
  153. data/vendor/rake-pipeline/spec/rake_acceptance_spec.rb +720 -0
  154. data/vendor/rake-pipeline/spec/rake_tasks_spec.rb +21 -0
  155. data/vendor/rake-pipeline/spec/reject_matcher_spec.rb +31 -0
  156. data/vendor/rake-pipeline/spec/sorted_pipeline_spec.rb +27 -0
  157. data/vendor/rake-pipeline/spec/spec_helper.rb +38 -0
  158. data/vendor/rake-pipeline/spec/support/spec_helpers/file_utils.rb +35 -0
  159. data/vendor/rake-pipeline/spec/support/spec_helpers/filters.rb +37 -0
  160. data/vendor/rake-pipeline/spec/support/spec_helpers/input_helpers.rb +23 -0
  161. data/vendor/rake-pipeline/spec/support/spec_helpers/memory_file_wrapper.rb +35 -0
  162. data/vendor/rake-pipeline/spec/support/spec_helpers/memory_manifest.rb +19 -0
  163. data/vendor/rake-pipeline/tools/perfs +101 -0
  164. metadata +497 -0
@@ -0,0 +1,720 @@
1
+ require "rake-pipeline/filters"
2
+
3
+ describe "A realistic project" do
4
+
5
+ INPUTS = {
6
+
7
+ "app/javascripts/jquery.js" => <<-HERE,
8
+ var jQuery = {};
9
+ HERE
10
+
11
+ "app/javascripts/sproutcore.js" => <<-HERE,
12
+ var SC = {};
13
+ assert(SC);
14
+ SC.hi = function() { console.log("hi"); };
15
+ HERE
16
+
17
+ "app/stylesheets/jquery.css" => <<-HERE,
18
+ #jquery {
19
+ color: red;
20
+ }
21
+ HERE
22
+
23
+ "app/stylesheets/sproutcore.css" => <<-HERE,
24
+ #sproutcore {
25
+ color: green;
26
+ }
27
+ HERE
28
+
29
+ "app/index.html" => <<-HERE,
30
+ <html></html>
31
+ HERE
32
+
33
+ "app/junk.txt" => <<-HERE,
34
+ junk
35
+ HERE
36
+
37
+ "app/main.dynamic" => <<-HERE,
38
+ # main.dynamic
39
+ static content
40
+ @import("variables")
41
+ HERE
42
+
43
+ "variables.import" => <<-HERE,
44
+ $rakep = awesome
45
+ HERE
46
+ }
47
+
48
+ EXPECTED_JS_OUTPUT = <<-HERE
49
+ var jQuery = {};
50
+ var SC = {};
51
+
52
+ SC.hi = function() { console.log("hi"); };
53
+ HERE
54
+
55
+ EXPECTED_CSS_OUTPUT = <<-HERE
56
+ #jquery {
57
+ color: red;
58
+ }
59
+ #sproutcore {
60
+ color: green;
61
+ }
62
+ HERE
63
+
64
+ EXPECTED_HTML_OUTPUT = <<-HERE
65
+ <html></html>
66
+ HERE
67
+
68
+ EXPECTED_DYNAMIC_OUTPUT = <<-HERE
69
+ # main.dynamic
70
+ static content
71
+ @import("variables")
72
+ $rakep = awesome
73
+ HERE
74
+
75
+ def input_wrapper(path)
76
+ Rake::Pipeline::FileWrapper.new(tmp, path)
77
+ end
78
+
79
+ def output_should_exist(expected = EXPECTED_JS_OUTPUT)
80
+ output = File.join(tmp, "public/javascripts/application.js")
81
+ temp = File.join(tmp, "temporary")
82
+
83
+ File.exists?(output).should be_true
84
+ File.exists?(temp).should be_true
85
+
86
+ File.read(output).should == expected
87
+ end
88
+
89
+ concat_filter = Rake::Pipeline::ConcatFilter
90
+ dynamic_import_filter = Rake::Pipeline::SpecHelpers::Filters::DynamicImportFilter
91
+ strip_asserts_filter = Rake::Pipeline::SpecHelpers::Filters::StripAssertsFilter
92
+ memory_manifest = Rake::Pipeline::SpecHelpers::MemoryManifest
93
+
94
+ def copy_files
95
+ INPUTS.each do |name, string|
96
+ mkdir_p File.dirname(File.join(tmp, name))
97
+ File.open(File.join(tmp, name), "w") { |file| file.write(string) }
98
+ end
99
+ end
100
+
101
+ def delete_files
102
+ FileUtils.rm_rf File.join(tmp, "app/javascripts/jquery.js")
103
+ end
104
+
105
+ before do
106
+ Rake.application = Rake::Application.new
107
+ copy_files
108
+ end
109
+
110
+ describe "a pipeline" do
111
+ it "can successfully apply filters" do
112
+ concat = concat_filter.new
113
+ concat.manifest = memory_manifest.new
114
+ concat.last_manifest = memory_manifest.new
115
+ concat.input_files = INPUTS.keys.select { |key| key =~ /javascript/ }.map { |file| input_wrapper(file) }
116
+ concat.output_root = File.join(tmp, "temporary", "concat_filter")
117
+ concat.output_name_generator = proc { |input| "javascripts/application.js" }
118
+
119
+ strip_asserts = strip_asserts_filter.new
120
+ strip_asserts.manifest = memory_manifest.new
121
+ strip_asserts.last_manifest = memory_manifest.new
122
+ strip_asserts.input_files = concat.output_files
123
+ strip_asserts.output_root = File.join(tmp, "public")
124
+ strip_asserts.output_name_generator = proc { |input| input }
125
+
126
+ concat.generate_rake_tasks
127
+ Rake::Task.define_task(:default => strip_asserts.generate_rake_tasks)
128
+ Rake.application[:default].invoke
129
+
130
+ output_should_exist
131
+ end
132
+
133
+ it "supports filters with multiple outputs per input" do
134
+ concat = concat_filter.new
135
+ concat.manifest = memory_manifest.new
136
+ concat.last_manifest = memory_manifest.new
137
+ concat.input_files = INPUTS.keys.select { |key| key =~ /javascript/ }.map { |file| input_wrapper(file) }
138
+ concat.output_root = File.join(tmp, "temporary", "concat_filter")
139
+ concat.output_name_generator = proc { |input| [ "javascripts/application.js", input.sub(/^app\//, '') ] }
140
+
141
+ strip_asserts = strip_asserts_filter.new
142
+ strip_asserts.manifest = memory_manifest.new
143
+ strip_asserts.last_manifest = memory_manifest.new
144
+ strip_asserts.input_files = concat.output_files
145
+ strip_asserts.output_root = File.join(tmp, "public")
146
+ strip_asserts.output_name_generator = proc { |input| input }
147
+
148
+ concat.generate_rake_tasks
149
+ Rake::Task.define_task(:default => strip_asserts.generate_rake_tasks)
150
+ Rake.application[:default].invoke
151
+
152
+ output_should_exist
153
+
154
+ expected_files = {
155
+ "javascripts/jquery.js" => "var jQuery = {};\n",
156
+ "javascripts/sproutcore.js" => "var SC = {};\n\nSC.hi = function() { console.log(\"hi\"); };\n"
157
+ }
158
+
159
+ expected_files.each do |file, expected|
160
+ output_file = File.join(tmp, "public", file)
161
+ output = nil
162
+
163
+ lambda { output = File.read(output_file) }.should_not raise_error
164
+ output.should == expected
165
+ end
166
+ end
167
+
168
+ it "can be configured using the pipeline" do
169
+ pipeline = Rake::Pipeline.new
170
+ pipeline.project = Rake::Pipeline::Project.new
171
+ pipeline.add_input tmp, 'app/javascripts/*.js'
172
+ pipeline.output_root = File.expand_path("public")
173
+ pipeline.tmpdir = "temporary"
174
+
175
+ concat = concat_filter.new
176
+ concat.manifest = memory_manifest.new
177
+ concat.last_manifest = memory_manifest.new
178
+ concat.output_name_generator = proc { |input| "javascripts/application.js" }
179
+
180
+ strip_asserts = strip_asserts_filter.new
181
+ strip_asserts.manifest = memory_manifest.new
182
+ strip_asserts.last_manifest = memory_manifest.new
183
+ strip_asserts.output_name_generator = proc { |input| input }
184
+
185
+ pipeline.add_filters(concat, strip_asserts)
186
+ pipeline.invoke
187
+
188
+ output_should_exist
189
+ end
190
+
191
+ end
192
+
193
+ describe "using the pipeline DSL" do
194
+ attr_reader :project
195
+
196
+ shared_examples_for "the pipeline DSL" do
197
+ it "can be configured using the pipeline DSL" do
198
+ project.invoke
199
+ output_should_exist
200
+ end
201
+
202
+ it "can be configured using the pipeline DSL with an alternate Rake application" do
203
+ project.pipelines.first.rake_application = Rake::Application.new
204
+ project.invoke
205
+ output_should_exist
206
+ end
207
+
208
+ it "can be invoked repeatedly to reflected updated changes" do
209
+ project.invoke
210
+ age_existing_files
211
+
212
+ if respond_to?(:update_jquery)
213
+ update_jquery
214
+ else
215
+ File.open(File.join(tmp, "app/javascripts/jquery.js"), "w") do |file|
216
+ file.write "var jQuery = {};\njQuery.trim = function() {};\n"
217
+ end
218
+ end
219
+
220
+ expected = <<-HERE.gsub(/^ {10}/, '')
221
+ var jQuery = {};
222
+ jQuery.trim = function() {};
223
+ var SC = {};
224
+
225
+ SC.hi = function() { console.log("hi"); };
226
+ HERE
227
+
228
+ project.invoke
229
+
230
+ output_should_exist(expected)
231
+ end
232
+
233
+ it "can be restarted to reflect new files" do
234
+ project.invoke
235
+ age_existing_files
236
+
237
+ if respond_to?(:update_history)
238
+ update_history
239
+ else
240
+ File.open(File.join(tmp, "app/javascripts/history.js"), "w") do |file|
241
+ file.write "var History = {};\n"
242
+ end
243
+ end
244
+
245
+ project.invoke
246
+
247
+ expected = <<-HERE.gsub(/^ {10}/, '')
248
+ var History = {};
249
+ var jQuery = {};
250
+ var SC = {};
251
+
252
+ SC.hi = function() { console.log("hi"); };
253
+ HERE
254
+
255
+ output_should_exist(expected)
256
+ end
257
+
258
+ it "does not generate new files when things haven't changed" do
259
+ output_file = File.join(tmp, "public/javascripts/application.js")
260
+
261
+ project.invoke
262
+ previous_mtime = File.mtime(output_file)
263
+
264
+ sleep 1
265
+
266
+ project.invoke
267
+ File.mtime(output_file).should == previous_mtime
268
+ end
269
+
270
+ it "handles deleted files" do
271
+ output_file = File.join(tmp, "public/javascripts/application.js")
272
+
273
+ project.invoke
274
+ content = File.read output_file
275
+
276
+ delete_files
277
+ project.invoke
278
+
279
+ content.should_not == File.read(output_file)
280
+ end
281
+ end
282
+
283
+ describe "the raw pipeline DSL (with block strip_asserts_filter)" do
284
+ it_behaves_like "the pipeline DSL"
285
+
286
+ before do
287
+ @project = Rake::Pipeline::Project.build do
288
+ tmpdir "temporary"
289
+ output "public"
290
+
291
+ input tmp, "app/javascripts/*.js" do
292
+ concat "javascripts/application.js"
293
+ filter(strip_asserts_filter) { |input| input }
294
+ end
295
+ end
296
+ end
297
+ end
298
+
299
+ describe "the raw pipeline DSL (with before_filter)" do
300
+ it_behaves_like "the pipeline DSL"
301
+
302
+ before do
303
+ @project = Rake::Pipeline::Project.build do
304
+ tmpdir "temporary"
305
+ output "public"
306
+
307
+ before_filter Rake::Pipeline::ConcatFilter, "javascripts/application.js"
308
+
309
+ input tmp, "app/javascripts/*.js" do
310
+ filter strip_asserts_filter
311
+ end
312
+ end
313
+ end
314
+ end
315
+
316
+ describe "the raw pipeline DSL (with simple strip_asserts_filter)" do
317
+ it_behaves_like "the pipeline DSL"
318
+
319
+ before do
320
+ @project = Rake::Pipeline::Project.build do
321
+ tmpdir "temporary"
322
+ output "public"
323
+
324
+ input tmp, "app/javascripts/*.js" do
325
+ concat "javascripts/application.js"
326
+ filter strip_asserts_filter
327
+ end
328
+ end
329
+ end
330
+ end
331
+
332
+ describe "using the matcher spec" do
333
+ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
334
+ super
335
+
336
+ css = File.join(tmp, "public/stylesheets/application.css")
337
+
338
+ File.exists?(css).should be_true
339
+ File.read(css).should == EXPECTED_CSS_OUTPUT
340
+
341
+ html = File.join(tmp, "public/index.html")
342
+ File.exists?(html).should be_true
343
+ File.read(html).should == EXPECTED_HTML_OUTPUT
344
+
345
+ junk = File.join(tmp, "public/junk.txt")
346
+ File.exists?(junk).should be_false
347
+ end
348
+
349
+ it_behaves_like "the pipeline DSL"
350
+
351
+ before do
352
+ @project = Rake::Pipeline::Project.build do
353
+ tmpdir "temporary"
354
+ output "public"
355
+
356
+ input File.join(tmp, "app") do
357
+ match "**/*.js" do
358
+ filter strip_asserts_filter
359
+ concat "javascripts/application.js"
360
+ end
361
+
362
+ match "**/*.css" do
363
+ concat "stylesheets/application.css"
364
+ end
365
+
366
+ match "**/*.html" do
367
+ concat
368
+ end
369
+ end
370
+ end
371
+ end
372
+ end
373
+
374
+ describe "using multiple pipelines (with after_filters)" do
375
+ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
376
+ super
377
+
378
+ css = File.join(tmp, "public/stylesheets/application.css")
379
+
380
+ File.exists?(css).should be_true
381
+ File.read(css).should == EXPECTED_CSS_OUTPUT
382
+
383
+ html = File.join(tmp, "public/index.html")
384
+ File.exists?(html).should be_true
385
+ File.read(html).should == EXPECTED_HTML_OUTPUT
386
+
387
+ junk = File.join(tmp, "public/junk.txt")
388
+ File.exists?(junk).should be_false
389
+ end
390
+
391
+ it_behaves_like "the pipeline DSL"
392
+
393
+ before do
394
+ @project = Rake::Pipeline::Project.build do
395
+ tmpdir "temporary"
396
+ output "public"
397
+
398
+ app_dir = File.join(tmp, "app")
399
+
400
+ after_filter Rake::Pipeline::ConcatFilter do |input|
401
+ ext = File.extname(input)
402
+
403
+ case ext
404
+ when ".js"
405
+ "javascripts/application.js"
406
+ when ".css"
407
+ "stylesheets/application.css"
408
+ when ".html"
409
+ input
410
+ end
411
+ end
412
+
413
+ input app_dir, "**/*.js" do
414
+ filter strip_asserts_filter
415
+ end
416
+
417
+ input app_dir, "**/*.css"
418
+
419
+ input app_dir, "**/*.html"
420
+ end
421
+ end
422
+ end
423
+
424
+ describe "using multiple pipelines" do
425
+ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
426
+ super
427
+
428
+ css = File.join(tmp, "public/stylesheets/application.css")
429
+
430
+ File.exists?(css).should be_true
431
+ File.read(css).should == EXPECTED_CSS_OUTPUT
432
+
433
+ html = File.join(tmp, "public/index.html")
434
+ File.exists?(html).should be_true
435
+ File.read(html).should == EXPECTED_HTML_OUTPUT
436
+
437
+ junk = File.join(tmp, "public/junk.txt")
438
+ File.exists?(junk).should be_false
439
+ end
440
+
441
+ it_behaves_like "the pipeline DSL"
442
+
443
+ before do
444
+ @project = Rake::Pipeline::Project.build do
445
+ tmpdir "temporary"
446
+ output "public"
447
+
448
+ app_dir = File.join(tmp, "app")
449
+
450
+ input app_dir, "**/*.js" do
451
+ filter strip_asserts_filter
452
+ concat "javascripts/application.js"
453
+ end
454
+
455
+ input app_dir, "**/*.css" do
456
+ concat "stylesheets/application.css"
457
+ end
458
+
459
+ input app_dir, "**/*.html" do
460
+ concat
461
+ end
462
+ end
463
+ end
464
+ end
465
+
466
+ describe "using the matcher spec (with multiple inputs to a single pipeline)" do
467
+ it_behaves_like "the pipeline DSL"
468
+
469
+ def tmp1
470
+ File.join(tmp, 'tmp1')
471
+ end
472
+
473
+ def tmp2
474
+ File.join(tmp, 'tmp2')
475
+ end
476
+
477
+ def update_jquery
478
+ File.open(File.join(tmp1, "app/javascripts/jquery.js"), "w") do |file|
479
+ file.write "var jQuery = {};\njQuery.trim = function() {};\n"
480
+ end
481
+ end
482
+
483
+ def update_history
484
+ File.open(File.join(tmp1, "app/javascripts/history.js"), "w") do |file|
485
+ file.write "var History = {};\n"
486
+ end
487
+ end
488
+
489
+ def copy_files
490
+ INPUTS.each do |name, string|
491
+ file = name =~ /\.js$/ ? File.join(tmp1, name) : File.join(tmp2, name)
492
+
493
+ mkdir_p File.dirname(file)
494
+ File.open(file, "w") { |f| f.write(string) }
495
+ end
496
+ end
497
+
498
+ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
499
+ super
500
+
501
+ css = File.join(tmp, "public/stylesheets/application.css")
502
+
503
+ File.exists?(css).should be_true
504
+ File.read(css).should == EXPECTED_CSS_OUTPUT
505
+
506
+ html = File.join(tmp, "public/index.html")
507
+ File.exists?(html).should be_true
508
+ File.read(html).should == EXPECTED_HTML_OUTPUT
509
+
510
+ junk = File.join(tmp, "public/junk.txt")
511
+ File.exists?(junk).should be_false
512
+ end
513
+
514
+ def delete_files
515
+ FileUtils.rm_rf File.join(tmp1, "app/javascripts/jquery.js")
516
+ end
517
+
518
+ before do
519
+ tmp1 = self.tmp1
520
+ tmp2 = self.tmp2
521
+
522
+ @project = Rake::Pipeline::Project.build do
523
+ tmpdir "temporary"
524
+ output "public"
525
+
526
+ inputs [File.join(tmp1, "app"), File.join(tmp2, "app")] do
527
+ match "**/*.js" do
528
+ filter strip_asserts_filter
529
+ concat "javascripts/application.js"
530
+ end
531
+
532
+ match "**/*.css" do
533
+ concat "stylesheets/application.css"
534
+ end
535
+
536
+ match "**/*.html" do
537
+ concat
538
+ end
539
+ end
540
+ end
541
+ end
542
+ end
543
+ end
544
+
545
+ describe "Dynamic dependencies" do
546
+ shared_examples_for "a pipeline with dynamic files" do
547
+ it "should handle changes in dynamic imports" do
548
+ project.invoke
549
+
550
+ content = File.read output_file
551
+
552
+ content.should == EXPECTED_DYNAMIC_OUTPUT
553
+
554
+ sleep 1
555
+
556
+ imported_file = File.join tmp, "variables.import"
557
+
558
+ File.open imported_file, "w" do |f|
559
+ f.write "true to trance"
560
+ end
561
+
562
+ project.invoke
563
+ content = File.read output_file
564
+
565
+ content.should include("true to trance")
566
+ end
567
+
568
+ it "should handle changes in dynamic source files" do
569
+ project.invoke
570
+
571
+ content = File.read output_file
572
+
573
+ content.should == EXPECTED_DYNAMIC_OUTPUT
574
+
575
+ sleep 1
576
+
577
+ imported_file = File.join tmp, "app/main.dynamic"
578
+
579
+ File.open imported_file, "w" do |f|
580
+ f.write "true to trance"
581
+ end
582
+
583
+ project.invoke
584
+ content = File.read output_file
585
+
586
+ content.should == "true to trance"
587
+ end
588
+
589
+ it "should not regenerate files when nothing changes" do
590
+ project.invoke
591
+ previous_mtime = File.mtime output_file
592
+ sleep 1 ; project.invoke
593
+
594
+ File.mtime(output_file).should == previous_mtime
595
+ end
596
+ end
597
+
598
+ describe "direct dependencies" do
599
+ let(:project) do
600
+ Rake::Pipeline::Project.build do
601
+ tmpdir "temporary"
602
+ output "public"
603
+
604
+ input tmp, "app/*.dynamic" do
605
+ filter dynamic_import_filter
606
+ end
607
+ end
608
+ end
609
+
610
+ let(:output_file) { File.join tmp, "public", "app/main.dynamic" }
611
+
612
+ it_should_behave_like "a pipeline with dynamic files"
613
+ end
614
+
615
+ describe "transitive dependencies" do
616
+ let(:project) do
617
+ Rake::Pipeline::Project.build do
618
+ tmpdir "temporary"
619
+ output "public"
620
+
621
+ input tmp, "app/*.dynamic" do
622
+ filter dynamic_import_filter
623
+ concat "application.dyn"
624
+ end
625
+ end
626
+ end
627
+
628
+ let(:output_file) { File.join tmp, "public", "application.dyn" }
629
+
630
+ it_should_behave_like "a pipeline with dynamic files"
631
+ end
632
+ end
633
+
634
+ it "should work with nested matchers" do
635
+ project = Rake::Pipeline::Project.build do
636
+ tmpdir "temporary"
637
+ output "public"
638
+
639
+ input tmp, "app/**/*.js" do
640
+ match "**/*" do
641
+ match "**/*.js" do
642
+ filter strip_asserts_filter
643
+ concat "javascripts/application.js"
644
+ end
645
+ end
646
+ end
647
+ end
648
+
649
+ project.invoke
650
+
651
+ output_should_exist
652
+ end
653
+
654
+ describe "Handling mistakes" do
655
+ it "should raise an error when the tmp dir is added directly" do
656
+ project = Rake::Pipeline::Project.build do
657
+ output "public"
658
+ tmpdir "app"
659
+
660
+ input "app", "**/*" do
661
+ concat "tmp.js"
662
+ end
663
+ end
664
+
665
+ expect {
666
+ project.invoke ; project.invoke
667
+ }.to raise_error(Rake::Pipeline::TmpInputError)
668
+ end
669
+
670
+ it "should raise an error when the tmp dir is matched" do
671
+ project = Rake::Pipeline::Project.build do
672
+ output "public"
673
+ tmpdir "app/tmp"
674
+
675
+ input "app" do
676
+ # to generate temporary files
677
+ # which can be matched in the second invocation
678
+ match "**/*.js" do
679
+ concat "app.js"
680
+ end
681
+
682
+ match "tmp/**/*" do
683
+ concat "tmp.js"
684
+ end
685
+ end
686
+ end
687
+
688
+ expect {
689
+ project.invoke ; project.invoke
690
+ }.to raise_error(Rake::Pipeline::TmpInputError)
691
+ end
692
+
693
+ it "should not raise an error for internal temporary files" do
694
+ # Create a project with multiple filters and build
695
+ # steps to create intermediate build files
696
+ project = Rake::Pipeline::Project.build do
697
+ output "public"
698
+ tmpdir "temporary"
699
+
700
+ input tmp, "app/**/*" do
701
+ match "*.js" do
702
+ concat "application.js"
703
+ end
704
+
705
+ match "*.css" do
706
+ concat "application.css"
707
+ end
708
+
709
+ match "*.{js,css}" do
710
+ concat "every_file.application"
711
+ end
712
+ end
713
+ end
714
+
715
+ expect {
716
+ project.invoke
717
+ }.to_not raise_error(Rake::Pipeline::TmpInputError)
718
+ end
719
+ end
720
+ end