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 CHANGED
@@ -5,3 +5,6 @@ pkg/*
5
5
  .sass-cache
6
6
  .yardoc
7
7
  doc/*
8
+ *.sublime-workspace
9
+ *.sublime-project
10
+ *.DS_Store
@@ -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
@@ -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), {}).content
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
@@ -3,7 +3,7 @@ module Bunch
3
3
  end
4
4
 
5
5
  class << Cache
6
- def initialize
6
+ def init
7
7
  @cache = Hash.new { |h, k| h[k] = {} }
8
8
  end
9
9
 
@@ -36,5 +36,5 @@ module Bunch
36
36
  end
37
37
  end
38
38
 
39
- Cache.initialize
39
+ Cache.init
40
40
  end
@@ -22,7 +22,7 @@ module Bunch
22
22
 
23
23
  def generate_files
24
24
  Bunch.load_ignores(@input)
25
- tree = Bunch.tree_for(@input.to_s, @opts)
25
+ tree = Bunch.tree_for(@input.to_s, @opts.merge(:root => @input.to_s))
26
26
 
27
27
  if @output
28
28
  FileUtils.mkdir_p(@output.to_s)
@@ -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
@@ -24,7 +24,7 @@ module Bunch
24
24
 
25
25
  private
26
26
  def content_for(path)
27
- Bunch.content_for(path)
27
+ Bunch.content_for(path, :root => @root)
28
28
  end
29
29
 
30
30
  def headers(mime_type)
@@ -1,3 +1,3 @@
1
1
  module Bunch
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -13,7 +13,7 @@ class RackTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  should 'combine everything' do
16
- assert_equal "1 2 3 4 5 6 7 8 9 10", squeeze(@body)
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
- assert_equal "1 2 3 4 5 6 7 8 9 10", squeeze(@body)
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.1.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-13 00:00:00.000000000 Z
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: coffee-script
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: sass
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: yard
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: rdiscount
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: shoulda-context
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: mocha
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