handlebars_assets 0.7.2 → 0.8.0
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 +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +8 -0
- data/lib/handlebars_assets/config.rb +5 -1
- data/lib/handlebars_assets/tilt_handlebars.rb +21 -17
- data/lib/handlebars_assets/version.rb +1 -1
- data/test/handlebars_assets/tilt_handlebars_test.rb +13 -0
- data/test/test_helper.rb +1 -0
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -107,6 +107,13 @@ when you initialize your application.
|
|
107
107
|
|
108
108
|
HandlebarsAssets::Config.template_namespace = 'JST'
|
109
109
|
|
110
|
+
## Ember
|
111
|
+
|
112
|
+
To compile your templates for use with [Ember.js](http://emberjs.com)
|
113
|
+
simply turn on the config option
|
114
|
+
|
115
|
+
HandlebarsAssets::Config.ember = true
|
116
|
+
|
110
117
|
## `.hamlbars`
|
111
118
|
|
112
119
|
If you name your templates with the extension `.hamlbars`, you can use Haml syntax for your markup! Use `HandlebarsAssets::Config.haml_options` to pass custom options to the Haml rendering engine.
|
@@ -175,6 +182,7 @@ Follow me on [Github](https://github.com/leshill) and [Twitter](https://twitter.
|
|
175
182
|
* Brad Murray (@wyaeld) : Generic options support
|
176
183
|
* Blake Williams (@BlakeWilliams) : .handlebars extension
|
177
184
|
* Tristan Koch (@trkoch) : Strip leading whitespace from compiled templates
|
185
|
+
* Brian Cardarella (@bcardarella) : Ember support
|
178
186
|
|
179
187
|
# Contributing
|
180
188
|
|
@@ -5,7 +5,7 @@ module HandlebarsAssets
|
|
5
5
|
module Config
|
6
6
|
extend self
|
7
7
|
|
8
|
-
attr_writer :compiler, :compiler_path, :haml_options, :known_helpers, :known_helpers_only, :options, :path_prefix, :template_namespace
|
8
|
+
attr_writer :compiler, :compiler_path, :ember, :haml_options, :known_helpers, :known_helpers_only, :options, :path_prefix, :template_namespace
|
9
9
|
|
10
10
|
def compiler
|
11
11
|
@compiler || 'handlebars.js'
|
@@ -15,6 +15,10 @@ module HandlebarsAssets
|
|
15
15
|
@compiler_path || HandlebarsAssets.path
|
16
16
|
end
|
17
17
|
|
18
|
+
def ember?
|
19
|
+
@ember
|
20
|
+
end
|
21
|
+
|
18
22
|
def haml_available?
|
19
23
|
defined? ::Haml::Engine
|
20
24
|
end
|
@@ -28,24 +28,28 @@ module HandlebarsAssets
|
|
28
28
|
data
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
template_namespace = HandlebarsAssets::Config.template_namespace
|
34
|
-
|
35
|
-
if template_path.is_partial?
|
36
|
-
unindent <<-PARTIAL
|
37
|
-
(function() {
|
38
|
-
Handlebars.registerPartial(#{template_path.name}, Handlebars.template(#{compiled_hbs}));
|
39
|
-
}).call(this);
|
40
|
-
PARTIAL
|
31
|
+
if HandlebarsAssets::Config.ember?
|
32
|
+
"window.Ember.TEMPLATES[#{template_path.name}] = Ember.Handlebars.compile(#{source.to_json});"
|
41
33
|
else
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
34
|
+
compiled_hbs = Handlebars.precompile(source, HandlebarsAssets::Config.options)
|
35
|
+
|
36
|
+
template_namespace = HandlebarsAssets::Config.template_namespace
|
37
|
+
|
38
|
+
if template_path.is_partial?
|
39
|
+
unindent <<-PARTIAL
|
40
|
+
(function() {
|
41
|
+
Handlebars.registerPartial(#{template_path.name}, Handlebars.template(#{compiled_hbs}));
|
42
|
+
}).call(this);
|
43
|
+
PARTIAL
|
44
|
+
else
|
45
|
+
unindent <<-TEMPLATE
|
46
|
+
(function() {
|
47
|
+
this.#{template_namespace} || (this.#{template_namespace} = {});
|
48
|
+
this.#{template_namespace}[#{template_path.name}] = Handlebars.template(#{compiled_hbs});
|
49
|
+
return this.#{template_namespace}[#{template_path.name}];
|
50
|
+
}).call(this);
|
51
|
+
TEMPLATE
|
52
|
+
end
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
@@ -127,5 +127,18 @@ module HandlebarsAssets
|
|
127
127
|
|
128
128
|
assert_equal hbs_compiled('test_template_namespace', source), template.render(scope, {})
|
129
129
|
end
|
130
|
+
|
131
|
+
def test_ember_render
|
132
|
+
root = '/myapp/app/assets/templates'
|
133
|
+
file = 'test_render.hbs'
|
134
|
+
scope = make_scope root, file
|
135
|
+
source = "This is {{handlebars}}"
|
136
|
+
|
137
|
+
HandlebarsAssets::Config.ember = true
|
138
|
+
template = HandlebarsAssets::TiltHandlebars.new(scope.pathname.to_s) { source }
|
139
|
+
|
140
|
+
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("This is {{handlebars}}");};
|
141
|
+
assert_equal expected_compiled, template.render(scope, {})
|
142
|
+
end
|
130
143
|
end
|
131
144
|
end
|
data/test/test_helper.rb
CHANGED
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.
|
4
|
+
version: 0.8.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:
|
12
|
+
date: 2013-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: execjs
|