slinky 0.7.3 → 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.
data/spec/slinky_spec.rb CHANGED
@@ -16,426 +16,6 @@ describe "Slinky" do
16
16
  end
17
17
  end
18
18
 
19
- context "Manifest" do
20
- before :each do
21
- @mprod = Slinky::Manifest.new("/src", @config, :devel => false, :build_to => "/build")
22
- @mdevel = Slinky::Manifest.new("/src", @config)
23
- @md_prod = @mprod.manifest_dir
24
- @md_devel = @mdevel.manifest_dir
25
- end
26
-
27
- it "should build manifest dir with all files in current dir" do
28
- @md_prod.files.collect{|f| f.source}.should == ["/src/test.haml"]
29
- @md_devel.files.collect{|f| f.source}.should == ["/src/test.haml"]
30
- end
31
-
32
- it "should build manifest with all files in fs" do
33
- @mprod.files.collect{|f|
34
- f.source
35
- }.sort.should == @files.collect{|x| "/src/" + x}.sort
36
- @mdevel.files.collect{|f|
37
- f.source
38
- }.sort.should == @files.collect{|x| "/src/" + x}.sort
39
- end
40
-
41
- it "should not include dot files" do
42
- File.open("/src/.index.haml.swp", "w+"){|f| f.write("x")}
43
- manifest = Slinky::Manifest.new("/src", @config)
44
- manifest.files.map{|x| x.source}.include?("/src/.index.haml.swp").should == false
45
- end
46
-
47
- it "should be able to compute a hash for the entire manifest" do
48
- m = @mdevel
49
- hash1 = m.md5
50
- File.open("/src/hello.html", "w+") {|f| f.write("Hell!") }
51
- $stdout.should_receive(:puts).with("Compiled /src/test.haml".foreground(:green)).exactly(2).times
52
- m.add_all_by_path(["/src/hello.html"])
53
- m.md5.should_not == hash1
54
- end
55
-
56
- it "should find files in the manifest by path" do
57
- @mdevel.find_by_path("test.haml").first.source.should == "/src/test.haml"
58
- @mdevel.find_by_path("asdf.haml").first.should == nil
59
- @mdevel.find_by_path("l1/l2/test.txt").first.source.should == "/src/l1/l2/test.txt"
60
- @mdevel.find_by_path("l1/test.css").first.source.should == "/src/l1/test.sass"
61
- l1 = @mdevel.manifest_dir.children.find{|c| c.dir == "/src/l1"}
62
- l1.find_by_path("../test.haml").first.source.should == "/src/test.haml"
63
- end
64
-
65
- it "should produce the correct scripts string for production" do
66
- @mprod.scripts_string.should match \
67
- %r!<script type="text/javascript" src="/scripts.js\?\d+"></script>!
68
- end
69
-
70
- it "should produce the correct scripts string for devel" do
71
- @mdevel.scripts_string.should == [
72
- '<script type="text/javascript" src="/l1/test5.js"></script>',
73
- '<script type="text/javascript" src="/l1/l2/test6.js"></script>',
74
- '<script type="text/javascript" src="/l1/test2.js"></script>',
75
- '<script type="text/javascript" src="/l1/l2/test3.js"></script>',
76
- '<script type="text/javascript" src="/l1/test.js"></script>'].join("\n")
77
- end
78
-
79
- it "should produce the correct styles string for production" do
80
- @mprod.styles_string.should match \
81
- %r!<link rel="stylesheet" href="/styles.css\?\d+" />!
82
- end
83
-
84
- it "should produce the correct styles string for development" do
85
- File.open("/src/l1/l2/bad.sass", "w+"){|f|
86
- f.write "require('../test.sass')\ncolor: red;"
87
- }
88
- manifest = Slinky::Manifest.new("/src", @config)
89
- @mdevel.styles_string.should == [
90
- '<link rel="stylesheet" href="/l1/test.css" />',
91
- '<link rel="stylesheet" href="/l1/l2/test2.css" />'].join("\n")
92
- end
93
-
94
- it "should allow the creation of ManifestFiles" do
95
- mf = Slinky::ManifestFile.new("/src/test.haml", "", @mprod)
96
- end
97
-
98
- it "should correctly determine output_path" do
99
- mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
100
- mf.output_path.to_s.should == "/src/test.html"
101
- mf = Slinky::ManifestFile.new("/src/l1/test.js", "/src/build", @mprod)
102
- mf.output_path.to_s.should == "/src/l1/test.js"
103
- end
104
-
105
- it "should correctly determine relative_output_path" do
106
- mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
107
- mf.relative_output_path.to_s.should == "test.html"
108
- mf = Slinky::ManifestFile.new("/src/l1/test.js", "/src/build", @mprod)
109
- mf.relative_output_path.to_s.should == "l1/test.js"
110
- end
111
-
112
- it "should build tmp file without directives" do
113
- original = "/src/test.haml"
114
- mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
115
- path = mf.handle_directives mf.source
116
- File.read(original).match(/slinky_scripts|slinky_styles/).should_not == nil
117
- File.read(path).match(/slinky_scripts|slinky_styles/).should == nil
118
- end
119
-
120
- it "should build tmp file without directives for .js" do
121
- original = "/src/l1/test.js"
122
- mf = Slinky::ManifestFile.new("/src/l1/test.js", "/src/build", @mprod)
123
- path = mf.handle_directives mf.source
124
- File.read(original).match(/slinky_require/).should_not == nil
125
- File.read(path).match(/slinky_require/).should == nil
126
- end
127
-
128
- it "should compile files that need it" do
129
- $stdout.should_receive(:puts).with("Compiled /src/test.haml".foreground(:green))
130
- mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
131
- FileUtils.mkdir("/src/build")
132
- build_path = mf.process mf.build_to
133
- build_path.to_s.split(".")[-1].should == "html"
134
- File.read("/src/test.haml").match("<head>").should == nil
135
- File.read(build_path).match("<head>").should_not == nil
136
-
137
- $stdout.should_receive(:puts).with("Compiled /src/test.haml".foreground(:green))
138
- mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
139
- build_path = mf.process "/src/build/test.html"
140
- File.read("/src/build/test.html").match("<head>").should_not == nil
141
- FileUtils.rm_rf("/src/build") rescue nil
142
- end
143
-
144
- it "should give the proper error message for compilers with unmet dependencies" do
145
- File.open("/src/test.fake", "w+"){|f| f.write("hello, fake data")}
146
- $stderr.should_receive(:puts).with(/Missing dependency/)
147
- mf = Slinky::ManifestFile.new("/src/test.fake", "/src/build", @mprod)
148
- build_path = mf.process
149
- end
150
-
151
- it "should report errors for bad files" do
152
- File.open("/src/l1/l2/bad.sass", "w+"){|f|
153
- f.write "color: red;"
154
- }
155
- $stderr.should_receive(:puts).with(/Failed on/)
156
- mf = Slinky::ManifestFile.new("/src/l1/l2/bad.sass", "/src/build", @mprod)
157
- build_path = mf.process
158
- build_path.should == nil
159
- end
160
-
161
- it "shouldn't crash on syntax errors" do
162
- File.open("/src/l1/asdf.haml", "w+"){|f|
163
- f.write("%h1{:width => 50px}")
164
- }
165
- $stderr.should_receive(:puts).with(/Failed on/)
166
- mf = Slinky::ManifestFile.new("/src/l1/asdf.haml", "/src/build", @mprod)
167
- build_path = mf.process
168
- build_path.should == nil
169
- end
170
-
171
- it "should properly determine build directives" do
172
- mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
173
- mf.find_directives.should == {:slinky_scripts => [], :slinky_styles => []}
174
- mf = Slinky::ManifestFile.new("/src/l1/test.js", "/src/build", @mprod)
175
- mf.find_directives.should == {:slinky_require => ["test2.js", "l2/test3.js"]}
176
- end
177
-
178
- it "should properly determine build_to path" do
179
- mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
180
- mf.build_to.should == Pathname.new("/src/build/test.html")
181
- mf = Slinky::ManifestFile.new("/src/l1/test.js", "/src/build", @mprod)
182
- mf.build_to.should == Pathname.new("/src/build/test.js")
183
- end
184
-
185
- it "should build both compiled files and non-compiled files" do
186
- $stdout.should_receive(:puts).with("Compiled /src/test.haml".foreground(:green))
187
- mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
188
- path = mf.build
189
- path.to_s.should == "/src/build/test.html"
190
- File.read("/src/test.haml").match("<head>").should == nil
191
- File.read(path).match("<head>").should_not == nil
192
-
193
- $stdout.should_not_receive(:puts)
194
- mf = Slinky::ManifestFile.new("/src/l1/l2/test.txt", "/src/build/l1/l2", @mprod)
195
- path = mf.build
196
- path.to_s.should == "/src/build/l1/l2/test.txt"
197
- File.read("/src/build/l1/l2/test.txt").should == "hello\n"
198
- end
199
-
200
- it "should match files" do
201
- mf = Slinky::ManifestFile.new("/src/l1/l2/test.txt", "/src/build/l1/l2", @mprod)
202
- mf.matches?("test.txt").should == true
203
- mf = Slinky::ManifestFile.new("/src/l1/test.sass", "", @prod)
204
- mf.matches?("test.css").should == true
205
- mf.matches?("test.sass").should == true
206
- end
207
-
208
- it "should should properly determine if in tree" do
209
- mf = Slinky::ManifestFile.new("/src/l1/l2/test.txt", "/src/build/l1/l2", @mprod)
210
- mf.in_tree?("/l1").should == true
211
- mf.in_tree?("/l1/l2").should == true
212
- mf.in_tree?("/l1/l2/test.txt").should == true
213
- mf.in_tree?("/l1/l3").should == false
214
- mf.in_tree?("test.txt").should == false
215
- end
216
-
217
- it "should correctly build the dependency graph" do
218
- @mprod.build_dependency_graph.collect{|x| x.collect{|y| y.source}}.sort.should ==
219
- [["/src/l1/test2.js", "/src/l1/test.js"],
220
- ["/src/l1/l2/test3.coffee", "/src/l1/test.js"],
221
- ["/src/l1/test5.js", "/src/l1/test2.js"],
222
- ["/src/l1/l2/test6.js", "/src/l1/l2/test3.coffee"]].sort
223
- end
224
-
225
- it "should fail if a required file isn't in the manifest" do
226
- FileUtils.rm("/src/l1/test2.js")
227
- manifest = Slinky::Manifest.new("/src", @config, :devel => false, :build_to => "/build")
228
- $stderr.should_receive(:puts).with("Could not find file test2.js required by /src/l1/test.js".foreground(:red))
229
- proc {
230
- manifest.build_dependency_graph
231
- }.should raise_error Slinky::FileNotFoundError
232
- end
233
-
234
- it "should build a correct dependency list" do
235
- @mprod.dependency_list.collect{|x| x.source}.should == ["/src/test.haml", "/src/l1/test.sass", "/src/l1/test5.js", "/src/l1/l2/test.txt", "/src/l1/l2/test2.css", "/src/l1/l2/test6.js", "/src/l1/l2/l3/test2.txt", "/src/l1/test2.js", "/src/l1/l2/test3.coffee", "/src/l1/test.js"]
236
- end
237
-
238
- it "should fail if there is a cycle in the dependency graph" do
239
- File.open("/src/l1/test5.js", "w+"){|f| f.write("slinky_require('test.js')")}
240
- manifest = Slinky::Manifest.new("/src", @config, :devel => false, :build_to => "/build")
241
- $stderr.should_receive(:puts).with("Dependencies /src/l1/test2.js -> /src/l1/test.js, /src/l1/test5.js -> /src/l1/test2.js, /src/l1/test.js -> /src/l1/test5.js could not be satisfied".foreground(:red))
242
- proc { manifest.dependency_list }.should raise_error Slinky::DependencyError
243
- end
244
-
245
- it "should handle depends directives" do
246
- File.open("/src/l1/test5.coffee", "w+"){|f| f.write("slinky_depends('test.sass')")}
247
- manifest = Slinky::Manifest.new("/src", @config, :devel => true)
248
- f = manifest.find_by_path("l1/test5.js").first
249
- f.should_not == nil
250
- $stdout.should_receive(:puts).with(/Compiled \/src\/l1\/test.sass/)
251
- $stdout.should_receive(:puts).with(/Compiled \/src\/l1\/test5.coffee/)
252
- f.process
253
- end
254
-
255
- it "should handle depends directives with glob patterns" do
256
- File.open("/src/l1/test5.coffee", "w+"){|f| f.write("slinky_depends('*.sass')")}
257
- File.open("/src/l1/test2.sass", "w+"){|f| f.write("body\n\tcolor: red")}
258
- manifest = Slinky::Manifest.new("/src", @config, :devel => true)
259
- f = manifest.find_by_path("l1/test5.js").first
260
- f.should_not == nil
261
- $stdout.should_receive(:puts).with(/Compiled \/src\/l1\/test.sass/)
262
- $stdout.should_receive(:puts).with(/Compiled \/src\/l1\/test2.sass/)
263
- $stdout.should_receive(:puts).with(/Compiled \/src\/l1\/test5.coffee/)
264
- f.process
265
- end
266
-
267
- it "should handle depends directives with infinite loops" do
268
- File.open("/src/l1/test5.coffee", "w+"){|f| f.write("slinky_depends('*.sass')")}
269
- File.open("/src/l1/test2.sass", "w+"){|f| f.write("/* slinky_depends('*.coffee')")}
270
- manifest = Slinky::Manifest.new("/src", @config, :devel => true)
271
- f = manifest.find_by_path("l1/test5.js").first
272
- f.should_not == nil
273
- $stdout.should_receive(:puts).with(/Compiled \/src\/l1\/test.sass/)
274
- $stdout.should_receive(:puts).with(/Compiled \/src\/l1\/test2.sass/)
275
- $stdout.should_receive(:puts).with(/Compiled \/src\/l1\/test5.coffee/)
276
- f.process
277
- end
278
-
279
- it "should cache files" do
280
- File.open("/src/l1/cache.coffee", "w+"){|f| f.write("() -> 'hello, world!'\n")}
281
- manifest = Slinky::Manifest.new("/src", @config, :devel => true)
282
- f = manifest.find_by_path("l1/cache.js").first
283
- $stdout.should_receive(:puts).with(/Compiled \/src\/l1\/cache.coffee/)
284
- f.process
285
- f.process
286
- File.open("/src/l1/cache.coffee", "a"){|f| f.write("() -> 'goodbye, world!'\n")}
287
- $stdout.should_receive(:puts).with(/Compiled \/src\/l1\/cache.coffee/)
288
- f.process
289
- end
290
-
291
- it "should handle new directives" do
292
- manifest = Slinky::Manifest.new("/src", @config, :devel => true)
293
- f = manifest.find_by_path("l1/test.js").first
294
- f.process
295
- f.directives.should == {:slinky_require=>["test2.js", "l2/test3.js"]}
296
- File.open("/src/l1/test.js", "a"){|f| f.write("slinky_require('test5.js')\n")}
297
- f.process
298
- f.directives.should == {:slinky_require=>["test2.js", "l2/test3.js", "test5.js"]}
299
- end
300
-
301
- it "should detect new files" do
302
- $stdout.should_receive(:puts).with(/Compiled \/src\/test.haml/)
303
- manifest = Slinky::Manifest.new("/src", @config, :devel => true)
304
- File.open("/src/l1/cache.coffee", "w+"){|f| f.write("console.log 'hello'")}
305
- manifest.add_all_by_path(["/src/l1/cache.coffee"])
306
- f = manifest.find_by_path("l1/cache.js").first
307
- f.should_not == nil
308
- manifest.scripts_string.match("cache.js").should_not == nil
309
- FileUtils.mkdir("/src/l1/hello")
310
- File.open("/src/l1/hello/asdf.sass", "w+"){|f| f.write("hello")}
311
- f = manifest.find_by_path("l1/hello/asdf.sass")
312
- f.should_not == nil
313
- end
314
-
315
- it "should handle deletion of files" do
316
- File.open("/src/l1/cache.coffee", "w+"){|f| f.write("console.log 'hello'")}
317
- $stdout.should_receive(:puts).with(/Compiled \/src\/test.haml/)
318
- manifest = Slinky::Manifest.new("/src", @config, :devel => true)
319
- f = manifest.find_by_path("l1/cache.coffee").first
320
- f.should_not == nil
321
- manifest.scripts_string.match("l1/cache.js").should_not == nil
322
-
323
- FileUtils.rm("/src/l1/cache.coffee")
324
- File.exists?("/src/l1/cache.coffee").should == false
325
- manifest.remove_all_by_path(["/src/l1/cache.coffee"])
326
- f = manifest.find_by_path("l1/cache.coffee").first
327
- f.should == nil
328
- manifest.scripts_string.match("l1/cache.js").should == nil
329
- end
330
-
331
- it "should ignore the build directory" do
332
- $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(6).times
333
- options = {:src_dir => "/src", :build_dir => "/src/build"}
334
- Slinky::Builder.build(options, @config)
335
- File.exists?("/src/build/build").should_not == true
336
- File.exists?("/src/build/test.html").should == true
337
- Slinky::Builder.build(options, @config)
338
- File.exists?("/src/build/build").should == false
339
- end
340
-
341
- it "should combine and compress javascript" do
342
- FileUtils.rm_rf("/build") rescue nil
343
- $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(3).times
344
- @mprod.build
345
- File.exists?("/build/scripts.js").should == true
346
- File.size("/build/scripts.js").should > 90
347
- File.read("/build/scripts.js").match('"Hello, world"').should_not == nil
348
- File.exists?("/build/l1/test.js").should == false
349
- end
350
-
351
- it "should combine and compress css" do
352
- $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(3).times
353
- @mprod.build
354
- File.exists?("/build/styles.css").should == true
355
- File.size("/build/styles.css").should > 25
356
- File.read("/build/styles.css").match(/color:\s*red/).should_not == nil
357
- File.exists?("/build/l1/test.css").should == false
358
- end
359
-
360
- it "should modify css urls to point to correct paths when compiled" do
361
- $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(3).times
362
- @mprod.build
363
- css = File.read("/build/styles.css")
364
- css.include?("url('/l1/asdf.png')").should == true
365
- css.include?("url('/l1/bg.png')").should == true
366
- css.include?("url('/l1/l2/l3/hello.png')").should == true
367
- end
368
-
369
- it "should properly filter out ignores in files list" do
370
- config = Slinky::ConfigReader.new("ignore:\n - /l1/test2.js")
371
- config.ignore.should == ["/l1/test2.js"]
372
- mdevel = Slinky::Manifest.new("/src", config)
373
- mfiles = mdevel.files(false).map{|x| x.source}.sort
374
- files = (@files - ["l1/test2.js"]).map{|x| "/src/" + x}.sort
375
- mfiles.should == files
376
- # double check
377
- mfiles.include?("/src/l1/test2.js").should == false
378
- end
379
-
380
- it "should properly filter out relative ignores in files list" do
381
- config = Slinky::ConfigReader.new("ignore:\n - l1/test2.js")
382
- config.ignore.should == ["l1/test2.js"]
383
- mdevel = Slinky::Manifest.new("/src", config)
384
- mfiles = mdevel.files(false).map{|x| x.source}.sort
385
- files = (@files - ["l1/test2.js"]).map{|x| "/src/" + x}.sort
386
- mfiles.should == files
387
- # double check
388
- mfiles.include?("/src/l1/test2.js").should == false
389
- end
390
-
391
- it "should properly filter out directory ignores in files list" do
392
- config = Slinky::ConfigReader.new("ignore:\n - /l1/l2")
393
- config.ignore.should == ["/l1/l2"]
394
- mdevel = Slinky::Manifest.new("/src", config)
395
- mfiles = mdevel.files(false).map{|x| x.source}.sort
396
- files = (@files.reject{|x| x.start_with?("l1/l2")}).map{|x| "/src/" + x}.sort
397
- mfiles.should == files
398
- end
399
-
400
- it "should properly handle ignores for scripts" do
401
- File.open("/src/l1/l2/ignore.js", "w+"){|f| f.write("IGNORE!!!")}
402
- config = Slinky::ConfigReader.new("ignore:\n - /l1/l2/ignore.js")
403
- config.ignore.should == ["/l1/l2/ignore.js"]
404
-
405
- mdevel = Slinky::Manifest.new("/src", config)
406
- mdevel.scripts_string.scan(/src=\"(.+?)\"/).flatten.
407
- include?("/l1/l2/ignore.js").should == false
408
-
409
- mprod = Slinky::Manifest.new("/src", config, :devel => false,
410
- :build_to => "/build")
411
-
412
- $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(3).times
413
- mprod.build
414
-
415
- File.read("/build/scripts.js").include?("IGNORE!!!").should == false
416
- File.exists?("/build/l1/l2/ignore.js").should == true
417
- end
418
-
419
- it "should properly handle ignores for styles" do
420
- File.open("/src/l1/l2/ignore.css", "w+"){|f| f.write("IGNORE!!!")}
421
- config = Slinky::ConfigReader.new("ignore:\n - /l1/l2/ignore.css")
422
- config.ignore.should == ["/l1/l2/ignore.css"]
423
-
424
- mdevel = Slinky::Manifest.new("/src", config)
425
- mdevel.styles_string.scan(/href=\"(.+?)\"/).flatten.
426
- include?("/l1/l2/ignore.css").should == false
427
-
428
- mprod = Slinky::Manifest.new("/src", config, :devel => false,
429
- :build_to => "/build")
430
-
431
- $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(3).times
432
- mprod.build
433
-
434
- File.read("/build/styles.css").include?("IGNORE!!!").should == false
435
- File.exists?("/build/l1/l2/ignore.css").should == true
436
- end
437
- end
438
-
439
19
  context "Server" do
440
20
  before :each do
441
21
  @resp = double("EventMachine::DelegatedHttpResponse")
@@ -549,7 +129,7 @@ eos
549
129
  it "should not crash for syntax errors" do
550
130
  File.open("/src/bad_file.haml", "w+"){|f| f.write("%head{") }
551
131
  mf = Slinky::ManifestFile.new("/src/bad_file.haml", nil, @mdevel)
552
- $stderr.should_receive(:puts).with(/Failed on/)
132
+ $stderr.should_receive(:puts).with(/Compilation failed/)
553
133
  @resp.should_receive(:status=).with(500)
554
134
  Slinky::Server.handle_file @resp, mf
555
135
  end
@@ -593,6 +173,7 @@ eos
593
173
  before :each do
594
174
  @compilation_subs = {".sass" => ".css", ".coffee" => ".js", ".haml" => ".html"}
595
175
  end
176
+
596
177
  it "should build manifest to build directory" do
597
178
  $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(3).times
598
179
  options = {:src_dir => "/src", :build_dir => "/build"}
@@ -622,6 +203,13 @@ dont_minify: true
622
203
  pushstate:
623
204
  "/app1": "/index.html"
624
205
  "/app2": "/index2.html"
206
+ produce:
207
+ "/scripts.js":
208
+ include:
209
+ - "**/src/*.js"
210
+ "/tests.js":
211
+ include:
212
+ - "**/test/*.js "
625
213
  eos
626
214
  File.open("/src/slinky.yaml", "w+"){|f| f.write @config}
627
215
  @proxies = {