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.
@@ -1,5 +1,9 @@
1
1
  ## On master
2
2
 
3
+ ## 0.8.0
4
+
5
+ * Support Ember.js templates
6
+
3
7
  ## 0.7.2 (2012-12-25)
4
8
 
5
9
  * Note use of `rake assets:precompile` in README
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- handlebars_assets (0.7.2)
4
+ handlebars_assets (0.8.0)
5
5
  execjs (>= 1.2.9)
6
6
  sprockets (>= 2.0.3)
7
7
  tilt
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
- compiled_hbs = Handlebars.precompile(source, HandlebarsAssets::Config.options)
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
- unindent <<-TEMPLATE
43
- (function() {
44
- this.#{template_namespace} || (this.#{template_namespace} = {});
45
- this.#{template_namespace}[#{template_path.name}] = Handlebars.template(#{compiled_hbs});
46
- return this.#{template_namespace}[#{template_path.name}];
47
- }).call(this);
48
- TEMPLATE
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
 
@@ -1,3 +1,3 @@
1
1
  module HandlebarsAssets
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -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
@@ -63,6 +63,7 @@ module HandlebarsAssets
63
63
  @options = nil
64
64
  @path_prefix = nil
65
65
  @template_namespace = nil
66
+ @ember = nil
66
67
  end
67
68
 
68
69
  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.7.2
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: 2012-12-25 00:00:00.000000000 Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: execjs