bunch 0.2.2 → 1.0.0pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -6
  3. data/Gemfile +3 -1
  4. data/Guardfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/Rakefile +7 -12
  7. data/bin/bunch +2 -5
  8. data/bunch.gemspec +30 -23
  9. data/lib/bunch.rb +37 -81
  10. data/lib/bunch/cli.rb +40 -74
  11. data/lib/bunch/combiner.rb +121 -0
  12. data/lib/bunch/compiler.rb +52 -0
  13. data/lib/bunch/compilers/coffee_script.rb +23 -0
  14. data/lib/bunch/compilers/ejs.rb +28 -0
  15. data/lib/bunch/compilers/jade.rb +28 -0
  16. data/lib/bunch/compilers/jst.rb +38 -0
  17. data/lib/bunch/compilers/null.rb +19 -0
  18. data/lib/bunch/compilers/sass.rb +55 -0
  19. data/lib/bunch/content_hash.rb +37 -0
  20. data/lib/bunch/css_minifier.rb +121 -0
  21. data/lib/bunch/file.rb +18 -0
  22. data/lib/bunch/file_cache.rb +159 -0
  23. data/lib/bunch/file_tree.rb +153 -0
  24. data/lib/bunch/ignorer.rb +38 -0
  25. data/lib/bunch/js_minifier.rb +38 -0
  26. data/lib/bunch/middleware.rb +16 -67
  27. data/lib/bunch/pipeline.rb +30 -0
  28. data/lib/bunch/server.rb +56 -0
  29. data/lib/bunch/simple_cache.rb +36 -0
  30. data/lib/bunch/tree_merge.rb +29 -0
  31. data/lib/bunch/version.rb +3 -1
  32. data/spec/bunch/cli_spec.rb +85 -0
  33. data/spec/bunch/combiner_spec.rb +107 -0
  34. data/spec/bunch/compiler_spec.rb +73 -0
  35. data/spec/bunch/compilers/coffee_script_spec.rb +23 -0
  36. data/spec/bunch/compilers/ejs_spec.rb +27 -0
  37. data/spec/bunch/compilers/jade_spec.rb +28 -0
  38. data/spec/bunch/compilers/sass_spec.rb +120 -0
  39. data/spec/bunch/css_minifier_spec.rb +31 -0
  40. data/spec/bunch/file_cache_spec.rb +151 -0
  41. data/spec/bunch/file_tree_spec.rb +127 -0
  42. data/spec/bunch/ignorer_spec.rb +26 -0
  43. data/spec/bunch/js_minifier_spec.rb +35 -0
  44. data/spec/bunch/middleware_spec.rb +41 -0
  45. data/spec/bunch/pipeline_spec.rb +31 -0
  46. data/spec/bunch/server_spec.rb +90 -0
  47. data/spec/bunch/simple_cache_spec.rb +55 -0
  48. data/spec/bunch/tree_merge_spec.rb +30 -0
  49. data/spec/bunch_spec.rb +6 -0
  50. data/spec/example_tree/directory/_combine +2 -0
  51. data/{example/js/test1.js → spec/example_tree/directory/file1} +0 -0
  52. data/{example/js/test2/test2a.js → spec/example_tree/directory/file2} +0 -0
  53. data/{example/js/test2/test2c.js → spec/example_tree/file3} +0 -0
  54. data/spec/spec_helper.rb +38 -0
  55. metadata +224 -102
  56. data/.yardopts +0 -1
  57. data/README.md +0 -4
  58. data/config.ru +0 -6
  59. data/example/config.ru +0 -6
  60. data/example/css/test1.css +0 -1
  61. data/example/css/test2/test2a.scss +0 -1
  62. data/example/css/test2/test2b.css +0 -1
  63. data/example/js/.bunchignore +0 -1
  64. data/example/js/test2/_.yml +0 -2
  65. data/example/js/test2/foo.js +0 -1
  66. data/example/js/test2/test2b.js +0 -1
  67. data/example/js/test3/test3a.js +0 -1
  68. data/example/js/test3/test3b/_.yml +0 -1
  69. data/example/js/test3/test3b/test3bi.js +0 -1
  70. data/example/js/test3/test3b/test3bii.js +0 -1
  71. data/example/js/test4/_.yml +0 -1
  72. data/example/js/test4/test4a.js +0 -1
  73. data/example/js/test4/test4b.coffee +0 -1
  74. data/example/js/test4/test4c.coffee +0 -1
  75. data/example/js/test5/test5a.jst.ejs +0 -1
  76. data/lib/bunch/abstract_node.rb +0 -25
  77. data/lib/bunch/cache.rb +0 -40
  78. data/lib/bunch/coffee_node.rb +0 -39
  79. data/lib/bunch/directory_node.rb +0 -82
  80. data/lib/bunch/ejs_node.rb +0 -50
  81. data/lib/bunch/file_node.rb +0 -25
  82. data/lib/bunch/jade_node.rb +0 -50
  83. data/lib/bunch/null_node.rb +0 -11
  84. data/lib/bunch/rack.rb +0 -38
  85. data/lib/bunch/sass_node.rb +0 -39
  86. data/test/middleware_test.rb +0 -26
  87. data/test/rack_test.rb +0 -93
  88. data/test/test_helper.rb +0 -21
@@ -1,39 +0,0 @@
1
- module Bunch
2
- class SassNode < FileNode
3
- def initialize(fn)
4
- SassNode.require_sass
5
- @filename = fn
6
- end
7
-
8
- def content
9
- @content ||= fetch(@filename) { Sass::Engine.for_file(@filename, :style => SassNode.style).render }
10
- rescue => e
11
- raise CompileError.new(e, @filename)
12
- end
13
-
14
- def name
15
- File.basename(@filename).sub(/\.s(c|a)ss$/, '')
16
- end
17
-
18
- def target_extension
19
- '.css'
20
- end
21
- end
22
-
23
- class << SassNode
24
- attr_writer :style
25
-
26
- def require_sass
27
- unless @required
28
- require 'sass'
29
- @required = true
30
- end
31
- rescue LoadError
32
- raise "'gem install sass' to compile .sass and .scss files."
33
- end
34
-
35
- def style
36
- @style ||= (env = ENV['SASS_STYLE']) ? env.to_sym : :nested
37
- end
38
- end
39
- end
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- class MiddlewareTest < Test::Unit::TestCase
4
- context 'the Middleware class' do
5
- setup do
6
- @app = Bunch::Middleware.new(nil,
7
- :root_url => '/javascripts',
8
- :path => '/example/js'
9
- )
10
- @mock = mock
11
- @mock.expects(:call).returns([200, {}, ['hello']])
12
- end
13
-
14
- should 'ignore requests without the correct url' do
15
- @app.app = @mock
16
- perform_request('/not_javascripts/hello.html')
17
- assert_equal @body, 'hello'
18
- end
19
-
20
- should 'pass on requests with the correct url' do
21
- @app.endpoint = @mock
22
- perform_request('/javascripts/hello.js')
23
- assert_equal @body, 'hello'
24
- end
25
- end
26
- end
@@ -1,93 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RackTest < Test::Unit::TestCase
4
- context 'given a tree of js and coffee files' do
5
- setup do
6
- @app = Bunch::Rack.new('example/js')
7
- Bunch::CoffeeNode.bare = true
8
- end
9
-
10
- context 'when / is requested' do
11
- setup do
12
- perform_request
13
- end
14
-
15
- should 'combine everything' do
16
- assert squeeze(@body).start_with? "1 2 3 4 5 6 7 8 9 10 (f"
17
- end
18
-
19
- should 'have text/plain content type' do
20
- assert_equal 'text/plain', @headers['Content-Type']
21
- end
22
- end
23
-
24
- context 'when /all.js is requested' do
25
- setup do
26
- perform_request('/.js')
27
- end
28
-
29
- should 'combine everything in the correct order' do
30
- assert squeeze(@body).start_with? "1 2 3 4 5 6 7 8 9 10 (f"
31
- end
32
-
33
- should 'have application/javascript content type' do
34
- assert_equal "application/javascript", @headers['Content-Type']
35
- end
36
- end
37
-
38
- context 'with a subfolder of js files' do
39
- setup do
40
- perform_request('/test2.js')
41
- end
42
-
43
- should 'combine everything in that folder and nothing else' do
44
- assert_equal "2 3 4", squeeze(@body)
45
- assert %w(1 5 6 7 8 9 10).all? { |n| !@body.include?(n) }
46
- end
47
- end
48
-
49
- context 'with a subfolder containing another folder' do
50
- context 'when the outer folder is requested' do
51
- setup do
52
- perform_request('/test3.js')
53
- end
54
-
55
- should 'combine the contents of both folders in the correct order' do
56
- assert_equal "5 6 7", squeeze(@body)
57
- end
58
- end
59
-
60
- context 'when the inner folder is requested' do
61
- setup do
62
- perform_request('/test3/test3b.js')
63
- end
64
-
65
- should 'only render the inner folder' do
66
- assert_equal "6 7", squeeze(@body)
67
- end
68
- end
69
- end
70
-
71
- context 'when an EJS template is requested' do
72
- setup do
73
- perform_request('/test5/test5a.js')
74
- end
75
-
76
- should 'have the correct template name' do
77
- assert_match @body, %r(this\.JST\[.test5/test5a.\])
78
- end
79
- end
80
- end
81
-
82
- context 'given a tree of scss files' do
83
- setup do
84
- @app = Bunch::Rack.new('example/css')
85
- perform_request('/all.css')
86
- end
87
-
88
- should 'work' do
89
- assert_equal "body { a: 1 } body { b: 2 } body { c: 3 }", squeeze(@body)
90
- assert_equal "text/css", @headers['Content-Type']
91
- end
92
- end
93
- end
@@ -1,21 +0,0 @@
1
- $:.unshift File.expand_path('../../lib', __FILE__)
2
-
3
- require 'bunch'
4
- require 'test/unit'
5
- require 'mocha'
6
- require 'shoulda-context'
7
-
8
- # collapse whitespace and remove semicolons
9
- def squeeze(js)
10
- js.tr("\n;", ' ').split.join(' ')
11
- end
12
-
13
- # perform a request for the given path and set @status, @headers, and @body.
14
- def perform_request(path='/')
15
- env = {
16
- 'REQUEST_METHOD' => 'GET',
17
- 'PATH_INFO' => path
18
- }
19
- out = @app.call(env)
20
- @status, @headers, @body = out[0], out[1], out[2].join
21
- end