handlebars_assets 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,10 @@
1
1
  ## On master
2
2
 
3
+ ## 0.11.0 (2013-02-15)
4
+
5
+ * Update to handlebars.js 1.0.0-rc.3 - @akshayrawat
6
+ * Add github markdown to README - @phlipper
7
+
3
8
  ## 0.10.0 (2013-01-29)
4
9
 
5
10
  * Support `.slimbars` extension for Slim templates - @davidlee
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- handlebars_assets (0.10.0)
4
+ handlebars_assets (0.11.0)
5
5
  execjs (>= 1.2.9)
6
6
  sprockets (>= 2.0.3)
7
7
  tilt
data/README.md CHANGED
@@ -6,23 +6,23 @@ Yea, I think so too. That is why I wrote **handlebars_assets**. Give your Handle
6
6
 
7
7
  Using `sprockets` with Sinatra or another framework? **handlebars_assets** works outside of Rails too (as of v0.2.0)
8
8
 
9
- # BREAKING CHANGE IN v0.9.0
9
+ # BREAKING CHANGE AS OF v0.9.0
10
10
 
11
- My pull request to allow `/` in partials was pulled into Handlebars. The hack that converted partial names to underscored paths (`shared/_time` -> `_shared_time`) is no longer necessary and has been removed. You should change all the partial references in your app when going to v0.9.x.
11
+ My pull request to allow `/` in partials was pulled into Handlebars. The hack that converted partial names to underscored paths (`shared/_time` -> `_shared_time`) is no longer necessary and has been removed. You should change all the partial references in your app when upgrading from a version prior to v0.9.0.
12
12
 
13
- ## Edge version of handlebars.js
13
+ ## Version of handlebars.js
14
14
 
15
- *Please read*
16
-
17
- `handlebars_assets` is packaged with an edge build of `handlebars.js` (this [commit](https://github.com/wycats/handlebars.js/commit/a3376e24b1a25f72cf86d1d999bd2ea93fa4dc39)). See the section on using another version if that does not work for you.
15
+ `handlebars_assets` is packaged with an 1.0.0-rc3 of `handlebars.js`. See the section on using another version if that does not work for you.
18
16
 
19
17
  ## Installation with Rails 3.1+
20
18
 
21
19
  Load `handlebars_assets` in your `Gemfile` as part of the `assets` group
22
20
 
23
- group :assets do
24
- gem 'handlebars_assets'
25
- end
21
+ ```ruby
22
+ group :assets do
23
+ gem 'handlebars_assets'
24
+ end
25
+ ```
26
26
 
27
27
  ## Installation without Rails 3.1+
28
28
 
@@ -30,27 +30,34 @@ Load `handlebars_assets` in your `Gemfile` as part of the `assets` group
30
30
 
31
31
  Load `handlebars_assets` in your `Gemfile`
32
32
 
33
- gem 'handlebars_assets'
33
+ ```ruby
34
+ gem 'handlebars_assets'
35
+ ```
34
36
 
35
37
  Add the `HandlebarsAssets.path` to your `Sprockets::Environment` instance. This
36
38
  lets Sprockets know where the Handlebars JavaScript files are and is required
37
39
  for the next steps to work.
38
40
 
39
- env = Sprockets::Environment.new
40
-
41
- require 'handlebars_assets'
42
- env.append_path HandlebarsAssets.path
41
+ ```ruby
42
+ env = Sprockets::Environment.new
43
43
 
44
+ require 'handlebars_assets'
45
+ env.append_path HandlebarsAssets.path
46
+ ```
44
47
 
45
48
  # Compiling your JavaScript templates in the Rails asset pipeline
46
49
 
47
50
  Require `handlebars.runtime.js` in your JavaScript manifest (i.e. `application.js`)
48
51
 
49
- //= require handlebars.runtime
52
+ ```javascript
53
+ //= require handlebars.runtime
54
+ ```
50
55
 
51
56
  If you need to compile your JavaScript templates in the browser as well, you should instead require `handlebars.js` (which is significantly larger)
52
57
 
53
- //= require handlebars
58
+ ```javascript
59
+ //= require handlebars
60
+ ```
54
61
 
55
62
  ## Precompiling
56
63
 
@@ -64,13 +71,17 @@ If you are using `rake assets:precompile`, you have to re-run the `rake` command
64
71
 
65
72
  If you are deploying to Heroku, be sure to read the [Rails guide](http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets) and in your `config/application.rb` set:
66
73
 
67
- config.assets.initialize_on_precompile = false
74
+ ```ruby
75
+ config.assets.initialize_on_precompile = false
76
+ ```
68
77
 
69
78
  This avoids running your initializers when compiling assets (see the [guide](http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets) for why you would want that).
70
79
 
71
80
  However, that does mean that you cannot set your configuration in an initializer. This [issue](https://github.com/leshill/handlebars_assets/issues/34) has a workaround, or you can set:
72
81
 
73
- config.assets.initialize_on_precompile = true
82
+ ```ruby
83
+ config.assets.initialize_on_precompile = true
84
+ ```
74
85
 
75
86
  This will run all your initializers before precompiling assets.
76
87
 
@@ -78,7 +89,9 @@ This will run all your initializers before precompiling assets.
78
89
 
79
90
  You should locate your templates with your other assets, for example `app/assets/javascripts/templates`. In your JavaScript manifest file, use `require_tree` to pull in the templates
80
91
 
81
- //= require_tree ./templates
92
+ ```javascripts
93
+ //= require_tree ./templates
94
+ ```
82
95
 
83
96
  ## The template file
84
97
 
@@ -86,11 +99,13 @@ Write your Handlebars templates as standalone files in your templates directory.
86
99
 
87
100
  For example, if you have new, edit, and show templates for a Contact model
88
101
 
89
- templates/
90
- contacts/
91
- new.hbs
92
- edit.hbs
93
- show.hbs
102
+ ```
103
+ templates/
104
+ contacts/
105
+ new.hbs
106
+ edit.hbs
107
+ show.hbs
108
+ ```
94
109
 
95
110
  Your file extensions tell the asset pipeline how to process the file. Use `.hbs` to compile the template with Handlebars.
96
111
 
@@ -101,7 +116,9 @@ If your file is `templates/contacts/new.hbs`, the asset pipeline will generate J
101
116
 
102
117
  You can then invoke the resulting template in your application's JavaScript
103
118
 
104
- HandlebarsTemplates['contacts/new'](context);
119
+ ```javascript
120
+ HandlebarsTemplates['contacts/new'](context);
121
+ ```
105
122
 
106
123
  ## The template namespace
107
124
 
@@ -109,14 +126,18 @@ By default, the global JavaScript object that holds the compiled templates is `H
109
126
  be easily renamed. Another common template namespace is `JST`. Just change the `template_namespace` configuration option
110
127
  when you initialize your application.
111
128
 
112
- HandlebarsAssets::Config.template_namespace = 'JST'
129
+ ```ruby
130
+ HandlebarsAssets::Config.template_namespace = 'JST'
131
+ ```
113
132
 
114
133
  ## Ember
115
134
 
116
135
  To compile your templates for use with [Ember.js](http://emberjs.com)
117
136
  simply turn on the config option
118
137
 
119
- HandlebarsAssets::Config.ember = true
138
+ ```ruby
139
+ HandlebarsAssets::Config.ember = true
140
+ ```
120
141
 
121
142
  ## `.hamlbars` and `.slimbars`
122
143
 
@@ -124,13 +145,17 @@ If you name your templates with the extension `.hamlbars`, you can use Haml synt
124
145
 
125
146
  For example, if you have a file `widget.hamlbars` that looks like this:
126
147
 
127
- %h1 {{title}}
128
- %p {{body}}
148
+ ```haml
149
+ %h1 {{title}}
150
+ %p {{body}}
151
+ ```
129
152
 
130
153
  The Haml will be pre-processed so that the Handlebars template is basically this:
131
154
 
132
- <h1> {{title}} </h1>
133
- <p> {{body}} </p>
155
+ ```html
156
+ <h1> {{title}} </h1>
157
+ <p> {{body}} </p>
158
+ ```
134
159
 
135
160
  The same applies to `.slimbars` and the Slim gem. Use `HandlebarsAssets::Config.slim_options` to pass custom options to the Slim rendering engine.
136
161
 
@@ -138,14 +163,18 @@ The same applies to `.slimbars` and the Slim gem. Use `HandlebarsAssets::Config.
138
163
 
139
164
  If you begin the name of the template with an underscore, it will be recognized as a partial. You can invoke partials inside a template using the Handlebars partial syntax:
140
165
 
141
- Invoke a {{> path/to/_partial }}
166
+ ```
167
+ Invoke a {{> path/to/_partial }}
168
+ ```
142
169
 
143
170
  ## Using another version of `handlebars.js`
144
171
 
145
172
  Occasionally you might need to use a version of `handlebars.js` other than the included version. You can set the `compiler_path` and `compiler` options to use a custom version of `handlebars.js`.
146
173
 
147
- HandlebarsAssets::Config.compiler = 'my_handlebars.js' # Change the name of the compiler file
148
- HandlebarsAssets::Config.compiler_path = Rails.root.join('app/assets/javascripts') # Change the location of the compiler file
174
+ ```ruby
175
+ HandlebarsAssets::Config.compiler = 'my_handlebars.js' # Change the name of the compiler file
176
+ HandlebarsAssets::Config.compiler_path = Rails.root.join('app/assets/javascripts') # Change the location of the compiler file
177
+ ```
149
178
 
150
179
  # Thanks
151
180
 
@@ -179,6 +208,8 @@ Follow me on [Github](https://github.com/leshill) and [Twitter](https://twitter.
179
208
  * Tristan Koch (@trkoch) : Strip leading whitespace from compiled templates
180
209
  * Brian Cardarella (@bcardarella) : Ember support
181
210
  * David Lee (@davidlee) : Slim support
211
+ * Phil Cohen (@phlipper) : README cleanup
212
+ * Akshay Rawat (@akshayrawat) : Update to handlebars.js 1.0.0-rc.3
182
213
 
183
214
  # Contributing
184
215
 
@@ -1,3 +1,3 @@
1
1
  module HandlebarsAssets
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -29,7 +29,13 @@ this.Handlebars = {};
29
29
 
30
30
  (function(Handlebars) {
31
31
 
32
- Handlebars.VERSION = "1.0.rc.2";
32
+ Handlebars.VERSION = "1.0.0-rc.3";
33
+ Handlebars.COMPILER_REVISION = 2;
34
+
35
+ Handlebars.REVISION_CHANGES = {
36
+ 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
37
+ 2: '>= 1.0.0-rc.3'
38
+ };
33
39
 
34
40
  Handlebars.helpers = {};
35
41
  Handlebars.partials = {};
@@ -642,9 +648,13 @@ return new Parser;
642
648
  // lib/handlebars/compiler/base.js
643
649
  Handlebars.Parser = handlebars;
644
650
 
645
- Handlebars.parse = function(string) {
651
+ Handlebars.parse = function(input) {
652
+
653
+ // Just return if an already-compile AST was passed in.
654
+ if(input.constructor === Handlebars.AST.ProgramNode) { return input; }
655
+
646
656
  Handlebars.Parser.yy = Handlebars.AST;
647
- return Handlebars.Parser.parse(string);
657
+ return Handlebars.Parser.parse(input);
648
658
  };
649
659
 
650
660
  Handlebars.print = function(ast) {
@@ -1380,6 +1390,12 @@ Handlebars.JavaScriptCompiler = function() {};
1380
1390
  // Perform a second pass over the output to merge content when possible
1381
1391
  var source = this.mergeSource();
1382
1392
 
1393
+ if (!this.isChild) {
1394
+ var revision = Handlebars.COMPILER_REVISION,
1395
+ versions = Handlebars.REVISION_CHANGES[revision];
1396
+ source = "this.compilerInfo = ["+revision+",'"+versions+"'];\n"+source;
1397
+ }
1398
+
1383
1399
  if (asObject) {
1384
1400
  params.push(source);
1385
1401
 
@@ -2059,23 +2075,23 @@ Handlebars.JavaScriptCompiler = function() {};
2059
2075
 
2060
2076
  })(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
2061
2077
 
2062
- Handlebars.precompile = function(string, options) {
2063
- if (typeof string !== 'string') {
2064
- throw new Handlebars.Exception("You must pass a string to Handlebars.compile. You passed " + string);
2078
+ Handlebars.precompile = function(input, options) {
2079
+ if (!input || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
2080
+ throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
2065
2081
  }
2066
2082
 
2067
2083
  options = options || {};
2068
2084
  if (!('data' in options)) {
2069
2085
  options.data = true;
2070
2086
  }
2071
- var ast = Handlebars.parse(string);
2087
+ var ast = Handlebars.parse(input);
2072
2088
  var environment = new Handlebars.Compiler().compile(ast, options);
2073
2089
  return new Handlebars.JavaScriptCompiler().compile(environment, options);
2074
2090
  };
2075
2091
 
2076
- Handlebars.compile = function(string, options) {
2077
- if (typeof string !== 'string') {
2078
- throw new Handlebars.Exception("You must pass a string to Handlebars.compile. You passed " + string);
2092
+ Handlebars.compile = function(input, options) {
2093
+ if (!input || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
2094
+ throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
2079
2095
  }
2080
2096
 
2081
2097
  options = options || {};
@@ -2084,7 +2100,7 @@ Handlebars.compile = function(string, options) {
2084
2100
  }
2085
2101
  var compiled;
2086
2102
  function compile() {
2087
- var ast = Handlebars.parse(string);
2103
+ var ast = Handlebars.parse(input);
2088
2104
  var environment = new Handlebars.Compiler().compile(ast, options);
2089
2105
  var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
2090
2106
  return Handlebars.template(templateSpec);
@@ -2119,12 +2135,32 @@ Handlebars.VM = {
2119
2135
  }
2120
2136
  },
2121
2137
  programWithDepth: Handlebars.VM.programWithDepth,
2122
- noop: Handlebars.VM.noop
2138
+ noop: Handlebars.VM.noop,
2139
+ compilerInfo: null
2123
2140
  };
2124
2141
 
2125
2142
  return function(context, options) {
2126
2143
  options = options || {};
2127
- return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
2144
+ var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
2145
+
2146
+ var compilerInfo = container.compilerInfo || [],
2147
+ compilerRevision = compilerInfo[0] || 1,
2148
+ currentRevision = Handlebars.COMPILER_REVISION;
2149
+
2150
+ if (compilerRevision !== currentRevision) {
2151
+ if (compilerRevision < currentRevision) {
2152
+ var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
2153
+ compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
2154
+ throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
2155
+ "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
2156
+ } else {
2157
+ // Use the embedded version info since the runtime doesn't know about this revision yet
2158
+ throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
2159
+ "Please update your runtime to a newer version ("+compilerInfo[1]+").";
2160
+ }
2161
+ }
2162
+
2163
+ return result;
2128
2164
  };
2129
2165
  },
2130
2166
 
@@ -29,7 +29,13 @@ this.Handlebars = {};
29
29
 
30
30
  (function(Handlebars) {
31
31
 
32
- Handlebars.VERSION = "1.0.rc.2";
32
+ Handlebars.VERSION = "1.0.0-rc.3";
33
+ Handlebars.COMPILER_REVISION = 2;
34
+
35
+ Handlebars.REVISION_CHANGES = {
36
+ 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
37
+ 2: '>= 1.0.0-rc.3'
38
+ };
33
39
 
34
40
  Handlebars.helpers = {};
35
41
  Handlebars.partials = {};
@@ -249,12 +255,32 @@ Handlebars.VM = {
249
255
  }
250
256
  },
251
257
  programWithDepth: Handlebars.VM.programWithDepth,
252
- noop: Handlebars.VM.noop
258
+ noop: Handlebars.VM.noop,
259
+ compilerInfo: null
253
260
  };
254
261
 
255
262
  return function(context, options) {
256
263
  options = options || {};
257
- return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
264
+ var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
265
+
266
+ var compilerInfo = container.compilerInfo || [],
267
+ compilerRevision = compilerInfo[0] || 1,
268
+ currentRevision = Handlebars.COMPILER_REVISION;
269
+
270
+ if (compilerRevision !== currentRevision) {
271
+ if (compilerRevision < currentRevision) {
272
+ var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
273
+ compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
274
+ throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
275
+ "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
276
+ } else {
277
+ // Use the embedded version info since the runtime doesn't know about this revision yet
278
+ throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
279
+ "Please update your runtime to a newer version ("+compilerInfo[1]+").";
280
+ }
281
+ }
282
+
283
+ return result;
258
284
  };
259
285
  },
260
286
 
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.10.0
4
+ version: 0.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,104 +9,104 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-30 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: execjs
16
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
17
18
  requirements:
18
19
  - - ! '>='
19
20
  - !ruby/object:Gem::Version
20
21
  version: 1.2.9
21
- none: false
22
- prerelease: false
23
22
  type: :runtime
23
+ prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
25
26
  requirements:
26
27
  - - ! '>='
27
28
  - !ruby/object:Gem::Version
28
29
  version: 1.2.9
29
- none: false
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: tilt
32
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
33
34
  requirements:
34
35
  - - ! '>='
35
36
  - !ruby/object:Gem::Version
36
37
  version: '0'
37
- none: false
38
- prerelease: false
39
38
  type: :runtime
39
+ prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
41
42
  requirements:
42
43
  - - ! '>='
43
44
  - !ruby/object:Gem::Version
44
45
  version: '0'
45
- none: false
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: sprockets
48
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
49
50
  requirements:
50
51
  - - ! '>='
51
52
  - !ruby/object:Gem::Version
52
53
  version: 2.0.3
53
- none: false
54
- prerelease: false
55
54
  type: :runtime
55
+ prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
57
58
  requirements:
58
59
  - - ! '>='
59
60
  - !ruby/object:Gem::Version
60
61
  version: 2.0.3
61
- none: false
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rake
64
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
65
66
  requirements:
66
67
  - - ! '>='
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0'
69
- none: false
70
- prerelease: false
71
70
  type: :development
71
+ prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
73
74
  requirements:
74
75
  - - ! '>='
75
76
  - !ruby/object:Gem::Version
76
77
  version: '0'
77
- none: false
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: haml
80
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
81
82
  requirements:
82
83
  - - ! '>='
83
84
  - !ruby/object:Gem::Version
84
85
  version: '0'
85
- none: false
86
- prerelease: false
87
86
  type: :development
87
+ prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
89
90
  requirements:
90
91
  - - ! '>='
91
92
  - !ruby/object:Gem::Version
92
93
  version: '0'
93
- none: false
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: slim
96
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
97
98
  requirements:
98
99
  - - ! '>='
99
100
  - !ruby/object:Gem::Version
100
101
  version: '0'
101
- none: false
102
- prerelease: false
103
102
  type: :development
103
+ prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
105
106
  requirements:
106
107
  - - ! '>='
107
108
  - !ruby/object:Gem::Version
108
109
  version: '0'
109
- none: false
110
110
  description: Compile Handlebars templates in the Rails asset pipeline.
111
111
  email:
112
112
  - leshill@gmail.com
@@ -144,20 +144,20 @@ rdoc_options: []
144
144
  require_paths:
145
145
  - lib
146
146
  required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
147
148
  requirements:
148
149
  - - ! '>='
149
150
  - !ruby/object:Gem::Version
150
151
  version: '0'
151
- none: false
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
153
154
  requirements:
154
155
  - - ! '>='
155
156
  - !ruby/object:Gem::Version
156
157
  version: '0'
157
- none: false
158
158
  requirements: []
159
159
  rubyforge_project: handlebars_assets
160
- rubygems_version: 1.8.24
160
+ rubygems_version: 1.8.23
161
161
  signing_key:
162
162
  specification_version: 3
163
163
  summary: Compile Handlebars templates in the Rails asset pipeline.