bunch 0.2.2 → 1.0.0pre1
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.
- checksums.yaml +7 -0
- data/.gitignore +15 -6
- data/Gemfile +3 -1
- data/Guardfile +5 -0
- data/LICENSE.txt +22 -0
- data/Rakefile +7 -12
- data/bin/bunch +2 -5
- data/bunch.gemspec +30 -23
- data/lib/bunch.rb +37 -81
- data/lib/bunch/cli.rb +40 -74
- data/lib/bunch/combiner.rb +121 -0
- data/lib/bunch/compiler.rb +52 -0
- data/lib/bunch/compilers/coffee_script.rb +23 -0
- data/lib/bunch/compilers/ejs.rb +28 -0
- data/lib/bunch/compilers/jade.rb +28 -0
- data/lib/bunch/compilers/jst.rb +38 -0
- data/lib/bunch/compilers/null.rb +19 -0
- data/lib/bunch/compilers/sass.rb +55 -0
- data/lib/bunch/content_hash.rb +37 -0
- data/lib/bunch/css_minifier.rb +121 -0
- data/lib/bunch/file.rb +18 -0
- data/lib/bunch/file_cache.rb +159 -0
- data/lib/bunch/file_tree.rb +153 -0
- data/lib/bunch/ignorer.rb +38 -0
- data/lib/bunch/js_minifier.rb +38 -0
- data/lib/bunch/middleware.rb +16 -67
- data/lib/bunch/pipeline.rb +30 -0
- data/lib/bunch/server.rb +56 -0
- data/lib/bunch/simple_cache.rb +36 -0
- data/lib/bunch/tree_merge.rb +29 -0
- data/lib/bunch/version.rb +3 -1
- data/spec/bunch/cli_spec.rb +85 -0
- data/spec/bunch/combiner_spec.rb +107 -0
- data/spec/bunch/compiler_spec.rb +73 -0
- data/spec/bunch/compilers/coffee_script_spec.rb +23 -0
- data/spec/bunch/compilers/ejs_spec.rb +27 -0
- data/spec/bunch/compilers/jade_spec.rb +28 -0
- data/spec/bunch/compilers/sass_spec.rb +120 -0
- data/spec/bunch/css_minifier_spec.rb +31 -0
- data/spec/bunch/file_cache_spec.rb +151 -0
- data/spec/bunch/file_tree_spec.rb +127 -0
- data/spec/bunch/ignorer_spec.rb +26 -0
- data/spec/bunch/js_minifier_spec.rb +35 -0
- data/spec/bunch/middleware_spec.rb +41 -0
- data/spec/bunch/pipeline_spec.rb +31 -0
- data/spec/bunch/server_spec.rb +90 -0
- data/spec/bunch/simple_cache_spec.rb +55 -0
- data/spec/bunch/tree_merge_spec.rb +30 -0
- data/spec/bunch_spec.rb +6 -0
- data/spec/example_tree/directory/_combine +2 -0
- data/{example/js/test1.js → spec/example_tree/directory/file1} +0 -0
- data/{example/js/test2/test2a.js → spec/example_tree/directory/file2} +0 -0
- data/{example/js/test2/test2c.js → spec/example_tree/file3} +0 -0
- data/spec/spec_helper.rb +38 -0
- metadata +224 -102
- data/.yardopts +0 -1
- data/README.md +0 -4
- data/config.ru +0 -6
- data/example/config.ru +0 -6
- data/example/css/test1.css +0 -1
- data/example/css/test2/test2a.scss +0 -1
- data/example/css/test2/test2b.css +0 -1
- data/example/js/.bunchignore +0 -1
- data/example/js/test2/_.yml +0 -2
- data/example/js/test2/foo.js +0 -1
- data/example/js/test2/test2b.js +0 -1
- data/example/js/test3/test3a.js +0 -1
- data/example/js/test3/test3b/_.yml +0 -1
- data/example/js/test3/test3b/test3bi.js +0 -1
- data/example/js/test3/test3b/test3bii.js +0 -1
- data/example/js/test4/_.yml +0 -1
- data/example/js/test4/test4a.js +0 -1
- data/example/js/test4/test4b.coffee +0 -1
- data/example/js/test4/test4c.coffee +0 -1
- data/example/js/test5/test5a.jst.ejs +0 -1
- data/lib/bunch/abstract_node.rb +0 -25
- data/lib/bunch/cache.rb +0 -40
- data/lib/bunch/coffee_node.rb +0 -39
- data/lib/bunch/directory_node.rb +0 -82
- data/lib/bunch/ejs_node.rb +0 -50
- data/lib/bunch/file_node.rb +0 -25
- data/lib/bunch/jade_node.rb +0 -50
- data/lib/bunch/null_node.rb +0 -11
- data/lib/bunch/rack.rb +0 -38
- data/lib/bunch/sass_node.rb +0 -39
- data/test/middleware_test.rb +0 -26
- data/test/rack_test.rb +0 -93
- data/test/test_helper.rb +0 -21
data/lib/bunch/sass_node.rb
DELETED
@@ -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
|
data/test/middleware_test.rb
DELETED
@@ -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
|
data/test/rack_test.rb
DELETED
@@ -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
|
data/test/test_helper.rb
DELETED
@@ -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
|