handlebars_assets 0.6.2 → 0.6.4
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/CHANGELOG.md +10 -0
- data/Gemfile.lock +4 -4
- data/README.md +20 -1
- data/lib/handlebars_assets/config.rb +21 -8
- data/lib/handlebars_assets/handlebars.rb +2 -2
- data/lib/handlebars_assets/tilt_handlebars.rb +5 -4
- data/lib/handlebars_assets/version.rb +1 -1
- data/test/edge/handlebars.js +1917 -0
- data/test/handlebars_assets/tilt_edge_test.rb +44 -0
- data/test/handlebars_assets/tilt_handlebars_test.rb +62 -19
- data/test/test_helper.rb +42 -0
- metadata +6 -3
- data/HISTORY.md +0 -7
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module HandlebarsAssets
|
4
|
+
class TiltHandlebarsTest < Test::Unit::TestCase
|
5
|
+
include SprocketsScope
|
6
|
+
|
7
|
+
def hbs_edge_compiled(template_name)
|
8
|
+
<<END_EXPECTED
|
9
|
+
(function() {
|
10
|
+
this.HandlebarsTemplates || (this.HandlebarsTemplates = {});
|
11
|
+
this.HandlebarsTemplates[\"#{template_name}\"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
|
12
|
+
helpers = helpers || Handlebars.helpers;
|
13
|
+
var buffer = \"\", stack1, foundHelper, functionType=\"function\", escapeExpression=this.escapeExpression;
|
14
|
+
|
15
|
+
|
16
|
+
buffer += \"This is \";
|
17
|
+
foundHelper = helpers.handlebars;
|
18
|
+
if (foundHelper) { stack1 = foundHelper.call(depth0, {hash:{}}); }
|
19
|
+
else { stack1 = depth0.handlebars; stack1 = typeof stack1 === functionType ? stack1() : stack1; }
|
20
|
+
buffer += escapeExpression(stack1);
|
21
|
+
return buffer;});
|
22
|
+
return this.HandlebarsTemplates[\"#{template_name}\"];
|
23
|
+
}).call(this);
|
24
|
+
END_EXPECTED
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
HandlebarsAssets::Config.reset!
|
29
|
+
HandlebarsAssets::Handlebars.reset!
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_edge_compile
|
33
|
+
root = '/myapp/app/assets/templates'
|
34
|
+
file = 'test_render.hbs'
|
35
|
+
scope = make_scope root, file
|
36
|
+
|
37
|
+
HandlebarsAssets::Config.compiler_path = File.expand_path '../../edge', __FILE__
|
38
|
+
|
39
|
+
template = HandlebarsAssets::TiltHandlebars.new(scope.pathname.to_s) { "This is {{handlebars}}" }
|
40
|
+
|
41
|
+
assert_equal hbs_edge_compiled('test_render'), template.render(scope, {})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,18 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'handlebars_assets/config'
|
3
2
|
|
4
3
|
module HandlebarsAssets
|
5
4
|
class TiltHandlebarsTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def make_scope(root, file)
|
8
|
-
Class.new do
|
9
|
-
define_method(:logical_path) { pathname.to_s.gsub(root + '/', '').gsub(/\..*/, '') }
|
10
|
-
|
11
|
-
define_method(:pathname) { Pathname.new(root) + file }
|
12
|
-
|
13
|
-
define_method(:root_path) { root }
|
14
|
-
end.new
|
15
|
-
end
|
5
|
+
include SprocketsScope
|
16
6
|
|
17
7
|
def hbs_compiled(template_name)
|
18
8
|
<<END_EXPECTED
|
@@ -30,7 +20,7 @@ module HandlebarsAssets
|
|
30
20
|
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "handlebars", { hash: {} }); }
|
31
21
|
buffer += escapeExpression(stack1);
|
32
22
|
return buffer;});
|
33
|
-
return HandlebarsTemplates["#{template_name}"];
|
23
|
+
return this.HandlebarsTemplates["#{template_name}"];
|
34
24
|
}).call(this);
|
35
25
|
END_EXPECTED
|
36
26
|
end
|
@@ -88,7 +78,7 @@ function program1(depth0,data) {
|
|
88
78
|
stack1 = stack2.call(depth0, stack1, tmp1);
|
89
79
|
if(stack1 || stack1 === 0) { return stack1; }
|
90
80
|
else { return ''; }});
|
91
|
-
return HandlebarsTemplates[\"#{template_name}\"];
|
81
|
+
return this.HandlebarsTemplates[\"#{template_name}\"];
|
92
82
|
}).call(this);
|
93
83
|
END_EXPECTED
|
94
84
|
end
|
@@ -124,7 +114,7 @@ function program1(depth0,data) {
|
|
124
114
|
stack1 = stack2.call(depth0, stack1, tmp1);
|
125
115
|
if(stack1 || stack1 === 0) { return stack1; }
|
126
116
|
else { return ''; }});
|
127
|
-
return HandlebarsTemplates[\"#{template_name}\"];
|
117
|
+
return this.HandlebarsTemplates[\"#{template_name}\"];
|
128
118
|
}).call(this);
|
129
119
|
END_EXPECTED
|
130
120
|
end
|
@@ -165,7 +155,7 @@ function program1(depth0,data) {
|
|
165
155
|
else { stack1 = blockHelperMissing.call(depth0, stack2, stack1, tmp1); }
|
166
156
|
if(stack1 || stack1 === 0) { return stack1; }
|
167
157
|
else { return ''; }});
|
168
|
-
return HandlebarsTemplates[\"#{template_name}\"];
|
158
|
+
return this.HandlebarsTemplates[\"#{template_name}\"];
|
169
159
|
}).call(this);
|
170
160
|
END_EXPECTED
|
171
161
|
end
|
@@ -202,15 +192,55 @@ function program1(depth0,data) {
|
|
202
192
|
else { stack1 = blockHelperMissing.call(depth0, stack2, stack1, tmp1); }
|
203
193
|
if(stack1 || stack1 === 0) { return stack1; }
|
204
194
|
else { return ''; }});
|
205
|
-
return HandlebarsTemplates[\"#{template_name}\"];
|
195
|
+
return this.HandlebarsTemplates[\"#{template_name}\"];
|
196
|
+
}).call(this);
|
197
|
+
END_EXPECTED
|
198
|
+
end
|
199
|
+
|
200
|
+
def hbs_compiled_template_namespace(template_name)
|
201
|
+
<<END_EXPECTED
|
202
|
+
(function() {
|
203
|
+
this.JST || (this.JST = {});
|
204
|
+
this.JST["#{template_name}"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
|
205
|
+
helpers = helpers || Handlebars.helpers;
|
206
|
+
var buffer = "", stack1, foundHelper, self=this, functionType="function", helperMissing=helpers.helperMissing, undef=void 0, escapeExpression=this.escapeExpression;
|
207
|
+
|
208
|
+
|
209
|
+
buffer += "This is ";
|
210
|
+
foundHelper = helpers.handlebars;
|
211
|
+
stack1 = foundHelper || depth0.handlebars;
|
212
|
+
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
|
213
|
+
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "handlebars", { hash: {} }); }
|
214
|
+
buffer += escapeExpression(stack1);
|
215
|
+
return buffer;});
|
216
|
+
return this.JST["#{template_name}"];
|
217
|
+
}).call(this);
|
218
|
+
END_EXPECTED
|
219
|
+
end
|
220
|
+
|
221
|
+
def hbs_edge_compiled(template_name)
|
222
|
+
<<END_EXPECTED
|
223
|
+
(function() {
|
224
|
+
this.HandlebarsTemplates || (this.HandlebarsTemplates = {});
|
225
|
+
this.HandlebarsTemplates[\"#{template_name}\"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
|
226
|
+
helpers = helpers || Handlebars.helpers;
|
227
|
+
var buffer = \"\", stack1, foundHelper, functionType=\"function\", escapeExpression=this.escapeExpression;
|
228
|
+
|
229
|
+
|
230
|
+
buffer += \"This is \";
|
231
|
+
foundHelper = helpers.handlebars;
|
232
|
+
if (foundHelper) { stack1 = foundHelper.call(depth0, {hash:{}}); }
|
233
|
+
else { stack1 = depth0.handlebars; stack1 = typeof stack1 === functionType ? stack1() : stack1; }
|
234
|
+
buffer += escapeExpression(stack1);
|
235
|
+
return buffer;});
|
236
|
+
return this.HandlebarsTemplates[\"#{template_name}\"];
|
206
237
|
}).call(this);
|
207
238
|
END_EXPECTED
|
208
239
|
end
|
209
240
|
|
210
241
|
def teardown
|
211
|
-
HandlebarsAssets::Config.
|
212
|
-
HandlebarsAssets::
|
213
|
-
HandlebarsAssets::Config.path_prefix = nil
|
242
|
+
HandlebarsAssets::Config.reset!
|
243
|
+
HandlebarsAssets::Handlebars.reset!
|
214
244
|
end
|
215
245
|
|
216
246
|
def test_render
|
@@ -309,5 +339,18 @@ END_EXPECTED
|
|
309
339
|
|
310
340
|
assert_equal hbs_custom_compiled_with_helper_opt('test_custom_known_helper', 'custom'), template.render(scope, {})
|
311
341
|
end
|
342
|
+
|
343
|
+
def test_template_namespace
|
344
|
+
root = '/myapp/app/assets/javascripts'
|
345
|
+
file = 'test_template_namespace.hbs'
|
346
|
+
scope = make_scope root, file
|
347
|
+
|
348
|
+
HandlebarsAssets::Config.template_namespace = 'JST'
|
349
|
+
|
350
|
+
template = HandlebarsAssets::TiltHandlebars.new(scope.pathname.to_s) { "This is {{handlebars}}" }
|
351
|
+
|
352
|
+
assert_equal hbs_compiled_template_namespace('test_template_namespace'), template.render(scope, {})
|
353
|
+
end
|
354
|
+
|
312
355
|
end
|
313
356
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,5 +1,47 @@
|
|
1
1
|
require 'handlebars_assets'
|
2
|
+
require 'handlebars_assets/config'
|
2
3
|
require 'handlebars_assets/tilt_handlebars'
|
3
4
|
require 'handlebars_assets/handlebars'
|
4
5
|
|
5
6
|
require 'test/unit'
|
7
|
+
|
8
|
+
module SprocketsScope
|
9
|
+
# Try to act like sprockets.
|
10
|
+
def make_scope(root, file)
|
11
|
+
Class.new do
|
12
|
+
define_method(:logical_path) { pathname.to_s.gsub(root + '/', '').gsub(/\..*/, '') }
|
13
|
+
|
14
|
+
define_method(:pathname) { Pathname.new(root) + file }
|
15
|
+
|
16
|
+
define_method(:root_path) { root }
|
17
|
+
end.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module HandlebarsAssets
|
22
|
+
module Config
|
23
|
+
extend self
|
24
|
+
|
25
|
+
def reset!
|
26
|
+
@compiler = nil
|
27
|
+
@compiler_path = nil
|
28
|
+
@known_helpers = nil
|
29
|
+
@known_helpers_only = nil
|
30
|
+
@options = nil
|
31
|
+
@path_prefix = nil
|
32
|
+
@template_namespace = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class Handlebars
|
38
|
+
|
39
|
+
def self.reset!
|
40
|
+
@context = nil
|
41
|
+
@source = nil
|
42
|
+
@path = nil
|
43
|
+
@assets_path = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handlebars_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
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-
|
12
|
+
date: 2012-08-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: execjs
|
@@ -87,7 +87,6 @@ files:
|
|
87
87
|
- CHANGELOG.md
|
88
88
|
- Gemfile
|
89
89
|
- Gemfile.lock
|
90
|
-
- HISTORY.md
|
91
90
|
- MIT-LICENSE
|
92
91
|
- README.md
|
93
92
|
- Rakefile
|
@@ -98,6 +97,8 @@ files:
|
|
98
97
|
- lib/handlebars_assets/handlebars.rb
|
99
98
|
- lib/handlebars_assets/tilt_handlebars.rb
|
100
99
|
- lib/handlebars_assets/version.rb
|
100
|
+
- test/edge/handlebars.js
|
101
|
+
- test/handlebars_assets/tilt_edge_test.rb
|
101
102
|
- test/handlebars_assets/tilt_handlebars_test.rb
|
102
103
|
- test/test_helper.rb
|
103
104
|
- vendor/assets/javascripts/handlebars.js
|
@@ -127,5 +128,7 @@ signing_key:
|
|
127
128
|
specification_version: 3
|
128
129
|
summary: Compile Handlebars templates in the Rails asset pipeline.
|
129
130
|
test_files:
|
131
|
+
- test/edge/handlebars.js
|
132
|
+
- test/handlebars_assets/tilt_edge_test.rb
|
130
133
|
- test/handlebars_assets/tilt_handlebars_test.rb
|
131
134
|
- test/test_helper.rb
|