bunch 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/bunch.gemspec +4 -2
- data/example/js/test5/test5a.jst.ejs +1 -0
- data/lib/bunch.rb +5 -2
- data/lib/bunch/cache.rb +2 -2
- data/lib/bunch/cli.rb +1 -1
- data/lib/bunch/ejs_node.rb +50 -0
- data/lib/bunch/rack.rb +1 -1
- data/lib/bunch/version.rb +1 -1
- data/test/rack_test.rb +12 -2
- metadata +26 -8
data/.gitignore
CHANGED
data/bunch.gemspec
CHANGED
@@ -20,10 +20,12 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.add_runtime_dependency 'mime-types'
|
22
22
|
|
23
|
-
s.add_development_dependency 'coffee-script'
|
24
|
-
s.add_development_dependency 'sass'
|
25
23
|
s.add_development_dependency 'yard'
|
26
24
|
s.add_development_dependency 'rdiscount'
|
27
25
|
s.add_development_dependency 'shoulda-context'
|
28
26
|
s.add_development_dependency 'mocha'
|
27
|
+
|
28
|
+
s.add_development_dependency 'coffee-script'
|
29
|
+
s.add_development_dependency 'sass'
|
30
|
+
s.add_development_dependency 'ejs'
|
29
31
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
11
|
data/lib/bunch.rb
CHANGED
@@ -22,6 +22,7 @@ require 'bunch/file_node'
|
|
22
22
|
require 'bunch/coffee_node'
|
23
23
|
require 'bunch/sass_node'
|
24
24
|
require 'bunch/null_node'
|
25
|
+
require 'bunch/ejs_node'
|
25
26
|
|
26
27
|
module Bunch
|
27
28
|
class CompileError < StandardError
|
@@ -47,8 +48,8 @@ class << Bunch
|
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
def content_for(path)
|
51
|
-
tree_for(normalized_path(path),
|
51
|
+
def content_for(path, options = {})
|
52
|
+
tree_for(normalized_path(path), options).content
|
52
53
|
end
|
53
54
|
|
54
55
|
def tree_for(path, options)
|
@@ -61,6 +62,8 @@ class << Bunch
|
|
61
62
|
Bunch::CoffeeNode.new(path)
|
62
63
|
when path =~ /\.s(a|c)ss$/
|
63
64
|
Bunch::SassNode.new(path)
|
65
|
+
when path =~ /\.ejs$/
|
66
|
+
Bunch::EJSNode.new(path)
|
64
67
|
else
|
65
68
|
Bunch::FileNode.new(path)
|
66
69
|
end
|
data/lib/bunch/cache.rb
CHANGED
data/lib/bunch/cli.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Bunch
|
2
|
+
class EJSNode < FileNode
|
3
|
+
def initialize(fn)
|
4
|
+
EJSNode.require_ejs
|
5
|
+
@filename = fn
|
6
|
+
end
|
7
|
+
|
8
|
+
def content
|
9
|
+
@content ||= fetch(@filename) {
|
10
|
+
<<-JAVASCRIPT
|
11
|
+
(function() {
|
12
|
+
this.JST || (this.JST = {});
|
13
|
+
this.JST['#{template_name}'] = #{EJS.compile(File.read(@filename))};
|
14
|
+
})();
|
15
|
+
JAVASCRIPT
|
16
|
+
}
|
17
|
+
rescue => e
|
18
|
+
raise CompileError.new(e, @filename)
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
File.basename(@filename, '.ejs')
|
23
|
+
end
|
24
|
+
|
25
|
+
def template_name
|
26
|
+
name = @filename.sub(/\.jst\.ejs$/, '')
|
27
|
+
|
28
|
+
if @options[:root]
|
29
|
+
name.sub(/^#{Regexp.escape(@options[:root].to_s)}\//, '')
|
30
|
+
else
|
31
|
+
name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def target_extension
|
36
|
+
'.js'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class << EJSNode
|
41
|
+
def require_ejs
|
42
|
+
unless @required
|
43
|
+
require 'ejs'
|
44
|
+
@required = true
|
45
|
+
end
|
46
|
+
rescue LoadError
|
47
|
+
raise "'gem install ejs' to compile .ejs files."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/bunch/rack.rb
CHANGED
data/lib/bunch/version.rb
CHANGED
data/test/rack_test.rb
CHANGED
@@ -13,7 +13,7 @@ class RackTest < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
should 'combine everything' do
|
16
|
-
|
16
|
+
assert squeeze(@body).start_with? "1 2 3 4 5 6 7 8 9 10 (f"
|
17
17
|
end
|
18
18
|
|
19
19
|
should 'have text/plain content type' do
|
@@ -27,7 +27,7 @@ class RackTest < Test::Unit::TestCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
should 'combine everything in the correct order' do
|
30
|
-
|
30
|
+
assert squeeze(@body).start_with? "1 2 3 4 5 6 7 8 9 10 (f"
|
31
31
|
end
|
32
32
|
|
33
33
|
should 'have application/javascript content type' do
|
@@ -67,6 +67,16 @@ class RackTest < Test::Unit::TestCase
|
|
67
67
|
end
|
68
68
|
end
|
69
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
|
70
80
|
end
|
71
81
|
|
72
82
|
context 'given a tree of scss files' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mime-types
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: yard
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: rdiscount
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: shoulda-context
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: mocha
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
@@ -92,7 +92,7 @@ dependencies:
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
95
|
+
name: coffee-script
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
@@ -108,7 +108,23 @@ dependencies:
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
111
|
+
name: sass
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: ejs
|
112
128
|
requirement: !ruby/object:Gem::Requirement
|
113
129
|
none: false
|
114
130
|
requirements:
|
@@ -158,12 +174,14 @@ files:
|
|
158
174
|
- example/js/test4/test4a.js
|
159
175
|
- example/js/test4/test4b.coffee
|
160
176
|
- example/js/test4/test4c.coffee
|
177
|
+
- example/js/test5/test5a.jst.ejs
|
161
178
|
- lib/bunch.rb
|
162
179
|
- lib/bunch/abstract_node.rb
|
163
180
|
- lib/bunch/cache.rb
|
164
181
|
- lib/bunch/cli.rb
|
165
182
|
- lib/bunch/coffee_node.rb
|
166
183
|
- lib/bunch/directory_node.rb
|
184
|
+
- lib/bunch/ejs_node.rb
|
167
185
|
- lib/bunch/file_node.rb
|
168
186
|
- lib/bunch/middleware.rb
|
169
187
|
- lib/bunch/null_node.rb
|