handlebars_assets 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- handlebars_assets (0.3.1)
4
+ handlebars_assets (0.4.0)
5
5
  execjs (>= 1.2.9)
6
6
  sprockets (>= 2.0.3)
7
7
  tilt
@@ -9,28 +9,19 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- activesupport (3.1.1)
13
- multi_json (~> 1.0)
14
12
  execjs (1.2.9)
15
13
  multi_json (~> 1.0)
16
14
  hike (1.2.1)
17
- libv8 (3.3.10.2)
18
15
  multi_json (1.0.3)
19
16
  rack (1.3.5)
20
- rake (0.9.2.2)
21
17
  sprockets (2.1.2)
22
18
  hike (~> 1.2)
23
19
  rack (~> 1.0)
24
20
  tilt (~> 1.1, != 1.3.0)
25
- therubyracer (0.9.8)
26
- libv8 (~> 3.3.10)
27
21
  tilt (1.3.3)
28
22
 
29
23
  PLATFORMS
30
24
  ruby
31
25
 
32
26
  DEPENDENCIES
33
- activesupport (~> 3.1.0)
34
27
  handlebars_assets!
35
- rake
36
- therubyracer
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # Use handlebars.js templates with the asset pipeline and sprockets
1
+ # BREAKING CHANGE
2
+
3
+ `handlebars.vm.js` was renamed to `handlebars.runtime.js`, please update your Javascript manifest.
2
4
 
3
- **ALPHA**
5
+ # Use handlebars.js templates with the asset pipeline and sprockets
4
6
 
5
7
  Are your `handlebars.js` templates littering your Rails views with `script` tags? Wondering why the nifty Rails 3.1 asset pipeline streamlines all your Javascript except for your Handlebars templates? Wouldn't it be nice to have your Handlebars templates compiled, compressed, and cached like your other Javascript?
6
8
 
@@ -8,7 +10,11 @@ Yea, I think so too. That is why I wrote **handlebars_assets**. Give your Handle
8
10
 
9
11
  Using `sprockets` with Sinatra or another framework? **handlebars_assets** works outside of Rails too (as of v0.2.0)
10
12
 
11
- ## Installation
13
+ ## handlebars.js
14
+
15
+ `handlebars_assets` is packaged with `v1.0.beta.5` of `handlebars.js`.
16
+
17
+ ## Installation with Rails 3.1+
12
18
 
13
19
  Load `handlebars_assets` in your `Gemfile` as part of the `assets` group
14
20
 
@@ -16,11 +22,18 @@ Load `handlebars_assets` in your `Gemfile` as part of the `assets` group
16
22
  gem 'handlebars_assets'
17
23
  end
18
24
 
25
+ ## Installation without Rails 3.1+
26
+
27
+ Load `handlebars_assets` in your `Gemfile`
28
+
29
+ gem 'handlebars_assets'
30
+
31
+
19
32
  # Compiling your Javascript templates in the Rails asset pipeline
20
33
 
21
- Require `handlebars.vm.js` in your Javascript manifest (i.e. `application.js`)
34
+ Require `handlebars.runtime.js` in your Javascript manifest (i.e. `application.js`)
22
35
 
23
- //= require handlebars.vm
36
+ //= require handlebars.runtime
24
37
 
25
38
  If you need to compile your Javascript templates in the browser as well, you should instead require `handlebars.js` (which is significantly larger)
26
39
 
@@ -46,20 +59,29 @@ For example, if you have new, edit, and show templates for a Contact model
46
59
 
47
60
  templates/
48
61
  contacts/
49
- new.jst.hbs
50
- edit.jst.hbs
51
- show.jst.hbs
62
+ new.hbs
63
+ edit.hbs
64
+ show.hbs
52
65
 
53
66
  Your file extensions tell the asset pipeline how to process the file. Use `.hbs` to compile the template with Handlebars. Combine it with `.jst` to add the compiled template to the `JST` global variable.
54
67
 
55
- If your file is `templates/contacts/new.jst.hbs`, the asset pipeline will generate Javascript code
68
+ If your file is `templates/contacts/new.hbs`, the asset pipeline will generate Javascript code
56
69
 
57
70
  1. Compile the Handlebars template to Javascript code
58
- 1. Add the template code to the `JST` global under the name `contacts/new`
71
+ 1. Add the template code to the `HandlebarsTemplates` global under the name `contacts/new`
59
72
 
60
73
  You can then invoke the resulting template in your application's Javascript
61
74
 
62
- JST['contacts/new'](context);
75
+ HandlebarsTemplates['contacts/new'](context);
76
+
77
+ ## JST
78
+
79
+ `sprockets` ships with a simple JavaScript template wrapper called `JST` for
80
+ use with the `ejs` and other gems.
81
+
82
+ `handlebars_assets` is compatible with `JST`. If you name your template files
83
+ `name.jst.hbs`, you will have access to your templates through the `JST` global
84
+ just like your `ejs` templates.
63
85
 
64
86
  ## Partials
65
87
 
@@ -21,8 +21,4 @@ Gem::Specification.new do |s|
21
21
  s.add_runtime_dependency "execjs", ">= 1.2.9"
22
22
  s.add_runtime_dependency "tilt"
23
23
  s.add_runtime_dependency "sprockets", ">= 2.0.3"
24
-
25
- s.add_development_dependency "activesupport", "~> 3.1.0"
26
- s.add_development_dependency "therubyracer"
27
- s.add_development_dependency "rake"
28
24
  end
@@ -1,3 +1,3 @@
1
1
  module HandlebarsAssets
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/string/starts_ends_with'
2
-
3
1
  require 'handlebars_assets/tilt_handlebars'
4
2
  require 'handlebars_assets/handlebars'
5
3
 
@@ -1,7 +1,7 @@
1
1
  // lib/handlebars/base.js
2
2
  var Handlebars = {};
3
3
 
4
- Handlebars.VERSION = "1.0.beta.4";
4
+ Handlebars.VERSION = "1.0.beta.5";
5
5
 
6
6
  Handlebars.helpers = {};
7
7
  Handlebars.partials = {};
@@ -23,16 +23,16 @@ Handlebars.registerHelper('helperMissing', function(arg) {
23
23
  }
24
24
  });
25
25
 
26
+ var toString = Object.prototype.toString, functionType = "[object Function]";
27
+
26
28
  Handlebars.registerHelper('blockHelperMissing', function(context, options) {
27
29
  var inverse = options.inverse || function() {}, fn = options.fn;
28
30
 
29
31
 
30
32
  var ret = "";
31
- var type = Object.prototype.toString.call(context);
33
+ var type = toString.call(context);
32
34
 
33
- if(type === "[object Function]") {
34
- context = context();
35
- }
35
+ if(type === functionType) { context = context.call(this); }
36
36
 
37
37
  if(context === true) {
38
38
  return fn(this);
@@ -67,6 +67,9 @@ Handlebars.registerHelper('each', function(context, options) {
67
67
  });
68
68
 
69
69
  Handlebars.registerHelper('if', function(context, options) {
70
+ var type = toString.call(context);
71
+ if(type === functionType) { context = context.call(this); }
72
+
70
73
  if(!context || Handlebars.Utils.isEmpty(context)) {
71
74
  return options.inverse(this);
72
75
  } else {
@@ -491,62 +494,68 @@ lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_STA
491
494
 
492
495
  var YYSTATE=YY_START
493
496
  switch($avoiding_name_collisions) {
494
- case 0: this.begin("mu"); if (yy_.yytext) return 14;
497
+ case 0:
498
+ if(yy_.yytext.slice(-1) !== "\\") this.begin("mu");
499
+ if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1), this.begin("emu");
500
+ if(yy_.yytext) return 14;
501
+
495
502
  break;
496
503
  case 1: return 14;
497
504
  break;
498
- case 2: return 24;
505
+ case 2: this.popState(); return 14;
499
506
  break;
500
- case 3: return 16;
507
+ case 3: return 24;
501
508
  break;
502
- case 4: return 20;
509
+ case 4: return 16;
503
510
  break;
504
- case 5: return 19;
511
+ case 5: return 20;
505
512
  break;
506
513
  case 6: return 19;
507
514
  break;
508
- case 7: return 23;
515
+ case 7: return 19;
509
516
  break;
510
517
  case 8: return 23;
511
518
  break;
512
- case 9: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.begin("INITIAL"); return 15;
519
+ case 9: return 23;
513
520
  break;
514
- case 10: return 22;
521
+ case 10: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15;
515
522
  break;
516
- case 11: return 34;
523
+ case 11: return 22;
517
524
  break;
518
- case 12: return 33;
525
+ case 12: return 34;
519
526
  break;
520
527
  case 13: return 33;
521
528
  break;
522
- case 14: return 36;
529
+ case 14: return 33;
523
530
  break;
524
- case 15: /*ignore whitespace*/
531
+ case 15: return 36;
525
532
  break;
526
- case 16: this.begin("INITIAL"); return 18;
533
+ case 16: /*ignore whitespace*/
527
534
  break;
528
- case 17: this.begin("INITIAL"); return 18;
535
+ case 17: this.popState(); return 18;
529
536
  break;
530
- case 18: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 28;
537
+ case 18: this.popState(); return 18;
531
538
  break;
532
- case 19: return 30;
539
+ case 19: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 28;
533
540
  break;
534
541
  case 20: return 30;
535
542
  break;
536
- case 21: return 29;
543
+ case 21: return 30;
537
544
  break;
538
- case 22: return 33;
545
+ case 22: return 29;
539
546
  break;
540
- case 23: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 33;
547
+ case 23: return 33;
541
548
  break;
542
- case 24: return 'INVALID';
549
+ case 24: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 33;
543
550
  break;
544
- case 25: return 5;
551
+ case 25: return 'INVALID';
552
+ break;
553
+ case 26: return 5;
545
554
  break;
546
555
  }
547
556
  };
548
- lexer.rules = [/^[^\x00]*?(?=(\{\{))/,/^[^\x00]+/,/^\{\{>/,/^\{\{#/,/^\{\{\//,/^\{\{\^/,/^\{\{\s*else\b/,/^\{\{\{/,/^\{\{&/,/^\{\{![\s\S]*?\}\}/,/^\{\{/,/^=/,/^\.(?=[} ])/,/^\.\./,/^[/.]/,/^\s+/,/^\}\}\}/,/^\}\}/,/^"(\\["]|[^"])*"/,/^true(?=[}\s])/,/^false(?=[}\s])/,/^[0-9]+(?=[}\s])/,/^[a-zA-Z0-9_$-]+(?=[=}\s\/.])/,/^\[.*\]/,/^./,/^$/];
549
- lexer.conditions = {"mu":{"rules":[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25],"inclusive":false},"INITIAL":{"rules":[0,1,25],"inclusive":true}};return lexer;})()
557
+ lexer.rules = [/^[^\x00]*?(?=(\{\{))/,/^[^\x00]+/,/^[^\x00]{2,}?(?=(\{\{))/,/^\{\{>/,/^\{\{#/,/^\{\{\//,/^\{\{\^/,/^\{\{\s*else\b/,/^\{\{\{/,/^\{\{&/,/^\{\{![\s\S]*?\}\}/,/^\{\{/,/^=/,/^\.(?=[} ])/,/^\.\./,/^[\/.]/,/^\s+/,/^\}\}\}/,/^\}\}/,/^"(\\["]|[^"])*"/,/^true(?=[}\s])/,/^false(?=[}\s])/,/^[0-9]+(?=[}\s])/,/^[a-zA-Z0-9_$-]+(?=[=}\s\/.])/,/^\[[^\]]*\]/,/^./,/^$/];
558
+ lexer.conditions = {"mu":{"rules":[3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"INITIAL":{"rules":[0,1,26],"inclusive":true}};return lexer;})()
550
559
  parser.lexer = lexer;
551
560
  return parser;
552
561
  })();
@@ -696,6 +705,8 @@ Handlebars.Exception = function(message) {
696
705
  for (var p in tmp) {
697
706
  if (tmp.hasOwnProperty(p)) { this[p] = tmp[p]; }
698
707
  }
708
+
709
+ this.message = tmp.message;
699
710
  };
700
711
  Handlebars.Exception.prototype = new Error;
701
712
 
@@ -932,6 +943,7 @@ Handlebars.JavaScriptCompiler = function() {};
932
943
  this.declare('inverse', programGuid);
933
944
 
934
945
  this.opcode('invokeProgram', null, params.length, !!block.mustache.hash);
946
+ this.declare('inverse', null);
935
947
  this.opcode('append');
936
948
  },
937
949
 
@@ -972,7 +984,7 @@ Handlebars.JavaScriptCompiler = function() {};
972
984
 
973
985
  this.opcode('invokeMustache', params.length, mustache.id.original, !!mustache.hash);
974
986
 
975
- if(mustache.escaped) {
987
+ if(mustache.escaped && !this.options.noEscape) {
976
988
  this.opcode('appendEscaped');
977
989
  } else {
978
990
  this.opcode('append');
@@ -1388,7 +1400,13 @@ Handlebars.JavaScriptCompiler = function() {};
1388
1400
  },
1389
1401
 
1390
1402
  invokePartial: function(context) {
1391
- this.pushStack("self.invokePartial(" + this.nameLookup('partials', context, 'partial') + ", '" + context + "', " + this.popStack() + ", helpers, partials);");
1403
+ params = [this.nameLookup('partials', context, 'partial'), "'" + context + "'", this.popStack(), "helpers", "partials"];
1404
+
1405
+ if (this.options.data) {
1406
+ params.push("data");
1407
+ }
1408
+
1409
+ this.pushStack("self.invokePartial(" + params.join(", ") + ");");
1392
1410
  },
1393
1411
 
1394
1412
  assignToHash: function(key) {
@@ -1526,7 +1544,7 @@ Handlebars.compile = function(string, options) {
1526
1544
  };
1527
1545
  };
1528
1546
  ;
1529
- // lib/handlebars/vm.js
1547
+ // lib/handlebars/runtime.js
1530
1548
  Handlebars.VM = {
1531
1549
  template: function(templateSpec) {
1532
1550
  // Just add water
@@ -1572,16 +1590,18 @@ Handlebars.VM = {
1572
1590
  };
1573
1591
  },
1574
1592
  noop: function() { return ""; },
1575
- invokePartial: function(partial, name, context, helpers, partials) {
1593
+ invokePartial: function(partial, name, context, helpers, partials, data) {
1594
+ options = { helpers: helpers, partials: partials, data: data };
1595
+
1576
1596
  if(partial === undefined) {
1577
1597
  throw new Handlebars.Exception("The partial " + name + " could not be found");
1578
1598
  } else if(partial instanceof Function) {
1579
- return partial(context, {helpers: helpers, partials: partials});
1599
+ return partial(context, options);
1580
1600
  } else if (!Handlebars.compile) {
1581
- throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in vm mode");
1601
+ throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
1582
1602
  } else {
1583
1603
  partials[name] = Handlebars.compile(partial);
1584
- return partials[name](context, {helpers: helpers, partials: partials});
1604
+ return partials[name](context, options);
1585
1605
  }
1586
1606
  }
1587
1607
  };
@@ -1,7 +1,7 @@
1
1
  // lib/handlebars/base.js
2
2
  var Handlebars = {};
3
3
 
4
- Handlebars.VERSION = "1.0.beta.4";
4
+ Handlebars.VERSION = "1.0.beta.5";
5
5
 
6
6
  Handlebars.helpers = {};
7
7
  Handlebars.partials = {};
@@ -23,16 +23,16 @@ Handlebars.registerHelper('helperMissing', function(arg) {
23
23
  }
24
24
  });
25
25
 
26
+ var toString = Object.prototype.toString, functionType = "[object Function]";
27
+
26
28
  Handlebars.registerHelper('blockHelperMissing', function(context, options) {
27
29
  var inverse = options.inverse || function() {}, fn = options.fn;
28
30
 
29
31
 
30
32
  var ret = "";
31
- var type = Object.prototype.toString.call(context);
33
+ var type = toString.call(context);
32
34
 
33
- if(type === "[object Function]") {
34
- context = context();
35
- }
35
+ if(type === functionType) { context = context.call(this); }
36
36
 
37
37
  if(context === true) {
38
38
  return fn(this);
@@ -67,6 +67,9 @@ Handlebars.registerHelper('each', function(context, options) {
67
67
  });
68
68
 
69
69
  Handlebars.registerHelper('if', function(context, options) {
70
+ var type = toString.call(context);
71
+ if(type === functionType) { context = context.call(this); }
72
+
70
73
  if(!context || Handlebars.Utils.isEmpty(context)) {
71
74
  return options.inverse(this);
72
75
  } else {
@@ -97,6 +100,8 @@ Handlebars.Exception = function(message) {
97
100
  for (var p in tmp) {
98
101
  if (tmp.hasOwnProperty(p)) { this[p] = tmp[p]; }
99
102
  }
103
+
104
+ this.message = tmp.message;
100
105
  };
101
106
  Handlebars.Exception.prototype = new Error;
102
107
 
@@ -152,7 +157,7 @@ Handlebars.SafeString.prototype.toString = function() {
152
157
  }
153
158
  };
154
159
  })();;
155
- // lib/handlebars/vm.js
160
+ // lib/handlebars/runtime.js
156
161
  Handlebars.VM = {
157
162
  template: function(templateSpec) {
158
163
  // Just add water
@@ -198,16 +203,18 @@ Handlebars.VM = {
198
203
  };
199
204
  },
200
205
  noop: function() { return ""; },
201
- invokePartial: function(partial, name, context, helpers, partials) {
206
+ invokePartial: function(partial, name, context, helpers, partials, data) {
207
+ options = { helpers: helpers, partials: partials, data: data };
208
+
202
209
  if(partial === undefined) {
203
210
  throw new Handlebars.Exception("The partial " + name + " could not be found");
204
211
  } else if(partial instanceof Function) {
205
- return partial(context, {helpers: helpers, partials: partials});
212
+ return partial(context, options);
206
213
  } else if (!Handlebars.compile) {
207
- throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in vm mode");
214
+ throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
208
215
  } else {
209
216
  partials[name] = Handlebars.compile(partial);
210
- return partials[name](context, {helpers: helpers, partials: partials});
217
+ return partials[name](context, options);
211
218
  }
212
219
  }
213
220
  };
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.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-12 00:00:00.000000000Z
12
+ date: 2011-12-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: execjs
16
- requirement: &70121416196800 !ruby/object:Gem::Requirement
16
+ requirement: &70164826032720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.2.9
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70121416196800
24
+ version_requirements: *70164826032720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tilt
27
- requirement: &70121416182660 !ruby/object:Gem::Requirement
27
+ requirement: &70164826032300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70121416182660
35
+ version_requirements: *70164826032300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sprockets
38
- requirement: &70121416181800 !ruby/object:Gem::Requirement
38
+ requirement: &70164826031760 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,40 +43,7 @@ dependencies:
43
43
  version: 2.0.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70121416181800
47
- - !ruby/object:Gem::Dependency
48
- name: activesupport
49
- requirement: &70121416181240 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 3.1.0
55
- type: :development
56
- prerelease: false
57
- version_requirements: *70121416181240
58
- - !ruby/object:Gem::Dependency
59
- name: therubyracer
60
- requirement: &70121416180860 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- type: :development
67
- prerelease: false
68
- version_requirements: *70121416180860
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: &70121416180380 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: *70121416180380
46
+ version_requirements: *70164826031760
80
47
  description: Compile Handlebars templates in the Rails asset pipeline.
81
48
  email:
82
49
  - leshill@gmail.com
@@ -101,7 +68,7 @@ files:
101
68
  - test/handlebars_assets/tilt_handlebars_test.rb
102
69
  - test/test_helper.rb
103
70
  - vendor/assets/javascripts/handlebars.js
104
- - vendor/assets/javascripts/handlebars.vm.js
71
+ - vendor/assets/javascripts/handlebars.runtime.js
105
72
  homepage: ''
106
73
  licenses: []
107
74
  post_install_message: