handlebars_assets 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +2 -2
- data/README.md +5 -0
- data/lib/handlebars_assets/tilt_handlebars.rb +14 -2
- data/lib/handlebars_assets/version.rb +1 -1
- data/test/handlebars_assets/hamlbars_test.rb +4 -22
- data/test/handlebars_assets/tilt_edge_test.rb +5 -23
- data/test/handlebars_assets/tilt_handlebars_test.rb +1 -28
- data/test/test_helper.rb +32 -0
- metadata +19 -19
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## On master
|
2
|
+
|
3
|
+
## 0.7.2 (2012-12-25)
|
4
|
+
|
5
|
+
* Note use of `rake assets:precompile` in README
|
6
|
+
* Strip leading whitespace from compiled templates - @trkoch
|
7
|
+
|
1
8
|
## 0.7.1 (2012-12-4)
|
2
9
|
|
3
10
|
* Use edge version of `handlebars.js` ([this commit](https://github.com/wycats/handlebars.js/commit/bd0490145438e8f9df05abd2f4c25687bac81326)) to fix regression with context functions
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
handlebars_assets (0.7.
|
4
|
+
handlebars_assets (0.7.2)
|
5
5
|
execjs (>= 1.2.9)
|
6
6
|
sprockets (>= 2.0.3)
|
7
7
|
tilt
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
hike (1.2.1)
|
16
16
|
multi_json (1.4.0)
|
17
17
|
rack (1.4.1)
|
18
|
-
rake (0.
|
18
|
+
rake (10.0.3)
|
19
19
|
sprockets (2.8.1)
|
20
20
|
hike (~> 1.2)
|
21
21
|
multi_json (~> 1.0)
|
data/README.md
CHANGED
@@ -52,6 +52,10 @@ If you need to compile your JavaScript templates in the browser as well, you sho
|
|
52
52
|
|
53
53
|
`handlebars_assets` also works when you are precompiling your assets.
|
54
54
|
|
55
|
+
### `rake assets:precompile`
|
56
|
+
|
57
|
+
If you are using `rake assets:precompile`, you have to re-run the `rake` command to rebuild any changed templates. See the [Rails guide](http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets) for more details.
|
58
|
+
|
55
59
|
### Heroku
|
56
60
|
|
57
61
|
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:
|
@@ -170,6 +174,7 @@ Follow me on [Github](https://github.com/leshill) and [Twitter](https://twitter.
|
|
170
174
|
* Ken Mayer (@kmayer) : Quick fix for template\_namespace option
|
171
175
|
* Brad Murray (@wyaeld) : Generic options support
|
172
176
|
* Blake Williams (@BlakeWilliams) : .handlebars extension
|
177
|
+
* Tristan Koch (@trkoch) : Strip leading whitespace from compiled templates
|
173
178
|
|
174
179
|
# Contributing
|
175
180
|
|
@@ -1,8 +1,20 @@
|
|
1
1
|
require 'tilt'
|
2
2
|
|
3
3
|
module HandlebarsAssets
|
4
|
+
module Unindent
|
5
|
+
# http://bit.ly/aze9FV
|
6
|
+
# Strip leading whitespace from each line that is the same as the
|
7
|
+
# amount of whitespace on the first line of the string.
|
8
|
+
# Leaves _additional_ indentation on later lines intact.
|
9
|
+
def unindent(heredoc)
|
10
|
+
heredoc.gsub /^#{heredoc[/\A\s*/]}/, ''
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
class TiltHandlebars < Tilt::Template
|
5
15
|
|
16
|
+
include Unindent
|
17
|
+
|
6
18
|
def self.default_mime_type
|
7
19
|
'application/javascript'
|
8
20
|
end
|
@@ -21,13 +33,13 @@ module HandlebarsAssets
|
|
21
33
|
template_namespace = HandlebarsAssets::Config.template_namespace
|
22
34
|
|
23
35
|
if template_path.is_partial?
|
24
|
-
<<-PARTIAL
|
36
|
+
unindent <<-PARTIAL
|
25
37
|
(function() {
|
26
38
|
Handlebars.registerPartial(#{template_path.name}, Handlebars.template(#{compiled_hbs}));
|
27
39
|
}).call(this);
|
28
40
|
PARTIAL
|
29
41
|
else
|
30
|
-
<<-TEMPLATE
|
42
|
+
unindent <<-TEMPLATE
|
31
43
|
(function() {
|
32
44
|
this.#{template_namespace} || (this.#{template_namespace} = {});
|
33
45
|
this.#{template_namespace}[#{template_path.name}] = Handlebars.template(#{compiled_hbs});
|
@@ -1,32 +1,14 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
module HandlebarsAssets
|
4
|
-
class
|
4
|
+
class HamlbarsTest < Test::Unit::TestCase
|
5
5
|
include SprocketsScope
|
6
|
+
include CompilerSupport
|
6
7
|
|
7
|
-
def
|
8
|
+
def compile_haml(source)
|
8
9
|
Haml::Engine.new(source, HandlebarsAssets::Config.haml_options).render
|
9
10
|
end
|
10
11
|
|
11
|
-
def expected_hbs_compiled(source)
|
12
|
-
compiler_src = Pathname(HandlebarsAssets::Config.compiler_path).join(HandlebarsAssets::Config.compiler).read
|
13
|
-
ExecJS.compile(compiler_src).call('Handlebars.precompile', source, HandlebarsAssets::Config.options)
|
14
|
-
end
|
15
|
-
|
16
|
-
def haml_compiled(template_name, source)
|
17
|
-
compiled_haml = expected_haml_compiled(source)
|
18
|
-
compiled_hbs = expected_hbs_compiled(compiled_haml)
|
19
|
-
template_namespace = HandlebarsAssets::Config.template_namespace
|
20
|
-
|
21
|
-
<<END_EXPECTED
|
22
|
-
(function() {
|
23
|
-
this.#{template_namespace} || (this.#{template_namespace} = {});
|
24
|
-
this.#{template_namespace}[#{template_name.dump}] = Handlebars.template(#{compiled_hbs});
|
25
|
-
return this.#{template_namespace}[#{template_name.dump}];
|
26
|
-
}).call(this);
|
27
|
-
END_EXPECTED
|
28
|
-
end
|
29
|
-
|
30
12
|
def teardown
|
31
13
|
HandlebarsAssets::Config.reset!
|
32
14
|
HandlebarsAssets::Handlebars.reset!
|
@@ -40,7 +22,7 @@ END_EXPECTED
|
|
40
22
|
|
41
23
|
template = HandlebarsAssets::TiltHandlebars.new(scope.pathname.to_s) { source }
|
42
24
|
|
43
|
-
assert_equal
|
25
|
+
assert_equal hbs_compiled('test_render', compile_haml(source)), template.render(scope, {})
|
44
26
|
end
|
45
27
|
end
|
46
28
|
end
|
@@ -1,28 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
module HandlebarsAssets
|
4
|
-
class
|
4
|
+
class TiltEdgeTest < Test::Unit::TestCase
|
5
5
|
include SprocketsScope
|
6
|
-
|
7
|
-
def hbs_edge_compiled(template_name)
|
8
|
-
<<END_EXPECTED
|
9
|
-
(function() {
|
10
|
-
this.HandlebarsTemplates || (this.HandlebarsTemplates = {});
|
11
|
-
this.HandlebarsTemplates[\"#{template_name}\"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
|
12
|
-
helpers = helpers || Handlebars.helpers;
|
13
|
-
var buffer = \"\", stack1, foundHelper, functionType=\"function\", escapeExpression=this.escapeExpression;
|
14
|
-
|
15
|
-
|
16
|
-
buffer += \"This is \";
|
17
|
-
foundHelper = helpers.handlebars;
|
18
|
-
if (foundHelper) { stack1 = foundHelper.call(depth0, {hash:{}}); }
|
19
|
-
else { stack1 = depth0.handlebars; stack1 = typeof stack1 === functionType ? stack1() : stack1; }
|
20
|
-
buffer += escapeExpression(stack1);
|
21
|
-
return buffer;});
|
22
|
-
return this.HandlebarsTemplates[\"#{template_name}\"];
|
23
|
-
}).call(this);
|
24
|
-
END_EXPECTED
|
25
|
-
end
|
6
|
+
include CompilerSupport
|
26
7
|
|
27
8
|
def teardown
|
28
9
|
HandlebarsAssets::Config.reset!
|
@@ -33,12 +14,13 @@ END_EXPECTED
|
|
33
14
|
root = '/myapp/app/assets/templates'
|
34
15
|
file = 'test_render.hbs'
|
35
16
|
scope = make_scope root, file
|
17
|
+
source = "This is {{handlebars}}"
|
36
18
|
|
37
19
|
HandlebarsAssets::Config.compiler_path = File.expand_path '../../edge', __FILE__
|
38
20
|
|
39
|
-
template = HandlebarsAssets::TiltHandlebars.new(scope.pathname.to_s) {
|
21
|
+
template = HandlebarsAssets::TiltHandlebars.new(scope.pathname.to_s) { source }
|
40
22
|
|
41
|
-
assert_equal
|
23
|
+
assert_equal hbs_compiled('test_render', source), template.render(scope, {})
|
42
24
|
end
|
43
25
|
end
|
44
26
|
end
|
@@ -2,36 +2,9 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module HandlebarsAssets
|
4
4
|
class TiltHandlebarsTest < Test::Unit::TestCase
|
5
|
+
include CompilerSupport
|
5
6
|
include SprocketsScope
|
6
7
|
|
7
|
-
def expected_compiled(source)
|
8
|
-
compiler_src = Pathname(HandlebarsAssets::Config.compiler_path).join(HandlebarsAssets::Config.compiler).read
|
9
|
-
ExecJS.compile(compiler_src).call('Handlebars.precompile', source, HandlebarsAssets::Config.options)
|
10
|
-
end
|
11
|
-
|
12
|
-
def hbs_compiled(template_name, source)
|
13
|
-
compiled_hbs = expected_compiled(source)
|
14
|
-
template_namespace = HandlebarsAssets::Config.template_namespace
|
15
|
-
|
16
|
-
<<END_EXPECTED
|
17
|
-
(function() {
|
18
|
-
this.#{template_namespace} || (this.#{template_namespace} = {});
|
19
|
-
this.#{template_namespace}[#{template_name.dump}] = Handlebars.template(#{compiled_hbs});
|
20
|
-
return this.#{template_namespace}[#{template_name.dump}];
|
21
|
-
}).call(this);
|
22
|
-
END_EXPECTED
|
23
|
-
end
|
24
|
-
|
25
|
-
def hbs_compiled_partial(partial_name, source)
|
26
|
-
compiled_hbs = expected_compiled(source)
|
27
|
-
|
28
|
-
<<END_EXPECTED
|
29
|
-
(function() {
|
30
|
-
Handlebars.registerPartial(#{partial_name.dump}, Handlebars.template(#{compiled_hbs}));
|
31
|
-
}).call(this);
|
32
|
-
END_EXPECTED
|
33
|
-
end
|
34
|
-
|
35
8
|
def teardown
|
36
9
|
HandlebarsAssets::Config.reset!
|
37
10
|
HandlebarsAssets::Handlebars.reset!
|
data/test/test_helper.rb
CHANGED
@@ -18,6 +18,38 @@ module SprocketsScope
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
module CompilerSupport
|
22
|
+
include HandlebarsAssets::Unindent
|
23
|
+
|
24
|
+
def compile_hbs(source)
|
25
|
+
compiler_src = Pathname(HandlebarsAssets::Config.compiler_path).join(HandlebarsAssets::Config.compiler).read
|
26
|
+
ExecJS.compile(compiler_src).call('Handlebars.precompile', source, HandlebarsAssets::Config.options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def hbs_compiled(template_name, source)
|
30
|
+
compiled_hbs = compile_hbs(source)
|
31
|
+
template_namespace = HandlebarsAssets::Config.template_namespace
|
32
|
+
|
33
|
+
unindent <<-END_EXPECTED
|
34
|
+
(function() {
|
35
|
+
this.#{template_namespace} || (this.#{template_namespace} = {});
|
36
|
+
this.#{template_namespace}[#{template_name.dump}] = Handlebars.template(#{compiled_hbs});
|
37
|
+
return this.#{template_namespace}[#{template_name.dump}];
|
38
|
+
}).call(this);
|
39
|
+
END_EXPECTED
|
40
|
+
end
|
41
|
+
|
42
|
+
def hbs_compiled_partial(partial_name, source)
|
43
|
+
compiled_hbs = compile_hbs(source)
|
44
|
+
|
45
|
+
unindent <<-END_EXPECTED
|
46
|
+
(function() {
|
47
|
+
Handlebars.registerPartial(#{partial_name.dump}, Handlebars.template(#{compiled_hbs}));
|
48
|
+
}).call(this);
|
49
|
+
END_EXPECTED
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
21
53
|
module HandlebarsAssets
|
22
54
|
module Config
|
23
55
|
extend self
|
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.
|
4
|
+
version: 0.7.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,88 +9,88 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-25 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
|
18
17
|
requirements:
|
19
18
|
- - ! '>='
|
20
19
|
- !ruby/object:Gem::Version
|
21
20
|
version: 1.2.9
|
22
|
-
|
21
|
+
none: false
|
23
22
|
prerelease: false
|
23
|
+
type: :runtime
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
25
|
requirements:
|
27
26
|
- - ! '>='
|
28
27
|
- !ruby/object:Gem::Version
|
29
28
|
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
|
34
33
|
requirements:
|
35
34
|
- - ! '>='
|
36
35
|
- !ruby/object:Gem::Version
|
37
36
|
version: '0'
|
38
|
-
|
37
|
+
none: false
|
39
38
|
prerelease: false
|
39
|
+
type: :runtime
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
41
|
requirements:
|
43
42
|
- - ! '>='
|
44
43
|
- !ruby/object:Gem::Version
|
45
44
|
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
|
50
49
|
requirements:
|
51
50
|
- - ! '>='
|
52
51
|
- !ruby/object:Gem::Version
|
53
52
|
version: 2.0.3
|
54
|
-
|
53
|
+
none: false
|
55
54
|
prerelease: false
|
55
|
+
type: :runtime
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
57
|
requirements:
|
59
58
|
- - ! '>='
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
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
|
66
65
|
requirements:
|
67
66
|
- - ! '>='
|
68
67
|
- !ruby/object:Gem::Version
|
69
68
|
version: '0'
|
70
|
-
|
69
|
+
none: false
|
71
70
|
prerelease: false
|
71
|
+
type: :development
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
73
|
requirements:
|
75
74
|
- - ! '>='
|
76
75
|
- !ruby/object:Gem::Version
|
77
76
|
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
|
82
81
|
requirements:
|
83
82
|
- - ! '>='
|
84
83
|
- !ruby/object:Gem::Version
|
85
84
|
version: '0'
|
86
|
-
|
85
|
+
none: false
|
87
86
|
prerelease: false
|
87
|
+
type: :development
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
89
|
requirements:
|
91
90
|
- - ! '>='
|
92
91
|
- !ruby/object:Gem::Version
|
93
92
|
version: '0'
|
93
|
+
none: false
|
94
94
|
description: Compile Handlebars templates in the Rails asset pipeline.
|
95
95
|
email:
|
96
96
|
- leshill@gmail.com
|
@@ -127,17 +127,17 @@ rdoc_options: []
|
|
127
127
|
require_paths:
|
128
128
|
- lib
|
129
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
130
|
requirements:
|
132
131
|
- - ! '>='
|
133
132
|
- !ruby/object:Gem::Version
|
134
133
|
version: '0'
|
135
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
134
|
none: false
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
136
|
requirements:
|
138
137
|
- - ! '>='
|
139
138
|
- !ruby/object:Gem::Version
|
140
139
|
version: '0'
|
140
|
+
none: false
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project: handlebars_assets
|
143
143
|
rubygems_version: 1.8.24
|