handlebars_assets 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.5.0 (2012-07-10)
2
+
3
+ * #24 - Remove "templates/" from template names - @cw-moshe
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- handlebars_assets (0.4.4)
4
+ handlebars_assets (0.5.0)
5
5
  execjs (>= 1.2.9)
6
6
  sprockets (>= 2.0.3)
7
7
  tilt
data/README.md CHANGED
@@ -1,7 +1,3 @@
1
- # BREAKING CHANGE
2
-
3
- `handlebars.vm.js` was renamed to `handlebars.runtime.js`, please update your Javascript manifest.
4
-
5
1
  # Use handlebars.js templates with the asset pipeline and sprockets
6
2
 
7
3
  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?
@@ -58,9 +54,9 @@ If you need to compile your Javascript templates in the browser as well, you sho
58
54
 
59
55
  ## Templates directory
60
56
 
61
- You should locate your templates with your other assets, for example `app/assets/templates`. In your Javascript manifest file, use `require_tree` to pull in the templates
57
+ 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
62
58
 
63
- //= require_tree ../templates
59
+ //= require_tree ./templates
64
60
 
65
61
  ## The template file
66
62
 
@@ -74,7 +70,7 @@ For example, if you have new, edit, and show templates for a Contact model
74
70
  edit.hbs
75
71
  show.hbs
76
72
 
77
- 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.
73
+ Your file extensions tell the asset pipeline how to process the file. Use `.hbs` to compile the template with Handlebars.
78
74
 
79
75
  If your file is `templates/contacts/new.hbs`, the asset pipeline will generate Javascript code
80
76
 
@@ -85,15 +81,6 @@ You can then invoke the resulting template in your application's Javascript
85
81
 
86
82
  HandlebarsTemplates['contacts/new'](context);
87
83
 
88
- ## JST
89
-
90
- `sprockets` ships with a simple JavaScript template wrapper called `JST` for
91
- use with the `ejs` and other gems.
92
-
93
- `handlebars_assets` is compatible with `JST`. If you name your template files
94
- `name.jst.hbs`, you will have access to your templates through the `JST` global
95
- just like your `ejs` templates.
96
-
97
84
  ## Partials
98
85
 
99
86
  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:
@@ -116,19 +103,12 @@ Thank you Yehuda Katz (@wycats) for [handlebars.js](https://github.com/wycats/ha
116
103
 
117
104
  Thank you Charles Lowell (@cowboyd) for [therubyracer](https://github.com/cowboyd/therubyracer) and [handlebars.rb](https://github.com/cowboyd/handlebars.rb).
118
105
 
119
- # Contributing
106
+ # Author
120
107
 
121
- Once you've made your great commits
108
+ Hi, I'm Les Hill and I make things go.
122
109
 
123
- 1. Fork
124
- 1. Create a topic branch - git checkout -b my_branch
125
- 1. Push to your branch - git push origin my_branch
126
- 1. Create a Pull Request from your branch
127
- 1. That's it!
110
+ Follow me on [Github](https://github.com/leshill) and [Twitter](https://twitter.com/leshill).
128
111
 
129
- # Author
130
-
131
- * Les Hill (@leshill)
132
112
 
133
113
  # Contributors
134
114
 
@@ -139,3 +119,14 @@ Once you've made your great commits
139
119
  * Brendan Loudermilk (@bloudermilk) : HandlebarsAssets.path
140
120
  * Dan Evans (@danevans) : Rails 2 support
141
121
  * Ben Woosley (@empact) : Update to handlebars.js 1.0.0.beta.6
122
+ * (@cw-moshe) : Remove 'templates/' from names
123
+
124
+ # Contributing
125
+
126
+ Once you've made your great commits
127
+
128
+ 1. Fork
129
+ 1. Create a topic branch - git checkout -b my_branch
130
+ 1. Push to your branch - git push origin my_branch
131
+ 1. Create a Pull Request from your branch
132
+ 1. That's it!
@@ -8,17 +8,18 @@ module HandlebarsAssets
8
8
 
9
9
  def evaluate(scope, locals, &block)
10
10
  name = basename(scope.logical_path)
11
+ relative_path = scope.logical_path.gsub(/^templates\/(.*)$/i, "\\1")
11
12
  compiled_hbs = Handlebars.precompile(data)
12
13
 
13
14
  if name.start_with?('_')
14
- partial_name = name[1..-1].inspect
15
+ partial_name = relative_path.gsub(/\//, '_').gsub(/__/, '_').dump
15
16
  <<-PARTIAL
16
17
  (function() {
17
18
  Handlebars.registerPartial(#{partial_name}, Handlebars.template(#{compiled_hbs}));
18
19
  }).call(this);
19
20
  PARTIAL
20
21
  else
21
- template_name = scope.logical_path.inspect
22
+ template_name = relative_path.dump
22
23
  <<-TEMPLATE
23
24
  (function() {
24
25
  this.HandlebarsTemplates || (this.HandlebarsTemplates = {});
@@ -1,3 +1,3 @@
1
1
  module HandlebarsAssets
2
- VERSION = "0.4.4"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -2,23 +2,29 @@ require 'test_helper'
2
2
 
3
3
  module HandlebarsAssets
4
4
  class TiltHandlebarsTest < Test::Unit::TestCase
5
- def test_render
6
- # Try to act like sprockets.
7
- scope = Object.new
8
- class << scope
9
- def logical_path ; 'x11' ; end
10
- end
11
- template = HandlebarsAssets::TiltHandlebars.new('/myapp/app/assets/templates/x11.jst.hbs') { "This is {{handlebars}}" }
12
- assert_equal <<END_EXPECTED, template.render(scope, {})
5
+ # Try to act like sprockets.
6
+ def make_scope(root, file)
7
+ Class.new do
8
+ define_method(:logical_path) { pathname.to_s.gsub(root + '/', '').gsub(/\..*/, '') }
9
+
10
+ define_method(:pathname) { Pathname.new(root) + file }
11
+
12
+ define_method(:root_path) { root }
13
+ end.new
14
+ end
15
+
16
+ def hbs_compiled
17
+ <<END_EXPECTED
13
18
  (function() {
14
19
  this.HandlebarsTemplates || (this.HandlebarsTemplates = {});
15
20
  this.HandlebarsTemplates["x11"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
16
21
  helpers = helpers || Handlebars.helpers;
17
- var buffer = "", stack1, self=this, functionType="function", helperMissing=helpers.helperMissing, undef=void 0, escapeExpression=this.escapeExpression;
22
+ var buffer = "", stack1, foundHelper, self=this, functionType="function", helperMissing=helpers.helperMissing, undef=void 0, escapeExpression=this.escapeExpression;
18
23
 
19
24
 
20
25
  buffer += "This is ";
21
- stack1 = helpers.handlebars || depth0.handlebars;
26
+ foundHelper = helpers.handlebars;
27
+ stack1 = foundHelper || depth0.handlebars;
22
28
  if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
23
29
  else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "handlebars", { hash: {} }); }
24
30
  buffer += escapeExpression(stack1);
@@ -27,5 +33,27 @@ module HandlebarsAssets
27
33
  }).call(this);
28
34
  END_EXPECTED
29
35
  end
36
+
37
+ def test_render
38
+ root = '/myapp/app/assets/templates'
39
+ file = 'x11.hbs'
40
+ scope = make_scope root, file
41
+
42
+ template = HandlebarsAssets::TiltHandlebars.new(scope.pathname.to_s) { "This is {{handlebars}}" }
43
+
44
+ assert_equal hbs_compiled, template.render(scope, {})
45
+ end
46
+
47
+ # Sprockets does not add nested root paths (i.e.
48
+ # app/assets/javascripts/templates is rooted at app/assets/javascripts)
49
+ def test_template_misnaming
50
+ root = '/myapp/app/assets/javascripts'
51
+ file = 'templates/x11.hbs'
52
+ scope = make_scope root, file
53
+
54
+ template = HandlebarsAssets::TiltHandlebars.new(scope.pathname.to_s) { "This is {{handlebars}}" }
55
+
56
+ assert_equal hbs_compiled, template.render(scope, {})
57
+ end
30
58
  end
31
59
  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.4.4
4
+ version: 0.5.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: 2012-04-03 00:00:00.000000000 Z
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: execjs
16
- requirement: &70241519231440 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 1.2.9
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70241519231440
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.9
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: tilt
27
- requirement: &70241519230900 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70241519230900
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: sprockets
38
- requirement: &70241519230320 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 2.0.3
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70241519230320
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.3
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rake
49
- requirement: &70241519229840 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70241519229840
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  description: Compile Handlebars templates in the Rails asset pipeline.
59
79
  email:
60
80
  - leshill@gmail.com
@@ -64,6 +84,7 @@ extra_rdoc_files: []
64
84
  files:
65
85
  - .gitignore
66
86
  - .rvmrc
87
+ - CHANGELOG.md
67
88
  - Gemfile
68
89
  - Gemfile.lock
69
90
  - HISTORY.md
@@ -100,11 +121,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
121
  version: '0'
101
122
  requirements: []
102
123
  rubyforge_project: handlebars_assets
103
- rubygems_version: 1.8.17
124
+ rubygems_version: 1.8.24
104
125
  signing_key:
105
126
  specification_version: 3
106
127
  summary: Compile Handlebars templates in the Rails asset pipeline.
107
128
  test_files:
108
129
  - test/handlebars_assets/tilt_handlebars_test.rb
109
130
  - test/test_helper.rb
110
- has_rdoc: