handlebars_assets 0.22.0 → 0.23.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Appraisals +15 -0
- data/Rakefile +3 -1
- data/gemfiles/rails_4_1.gemfile +8 -0
- data/gemfiles/rails_4_2.gemfile +8 -0
- data/gemfiles/rails_5.gemfile +8 -0
- data/gemfiles/sprockets_2.gemfile +7 -0
- data/gemfiles/sprockets_3.gemfile +7 -0
- data/gemfiles/tilt_1.gemfile +7 -0
- data/gemfiles/tilt_2.gemfile +7 -0
- data/handlebars_assets.gemspec +5 -4
- data/lib/handlebars_assets.rb +13 -2
- data/lib/handlebars_assets/engine.rb +6 -2
- data/lib/handlebars_assets/handlebars_template.rb +79 -20
- data/lib/handlebars_assets/version.rb +1 -1
- data/test/handlebars_assets/handlebars_processor_test.rb +17 -0
- data/test/handlebars_assets/shared/adapter_tests.rb +199 -0
- data/test/handlebars_assets/tilt_handlebars_test.rb +4 -224
- metadata +33 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 889627ed5b4b89f37958d5d20a0b7e851839ecd3
|
4
|
+
data.tar.gz: 3863d8bb5d37a1ee791d4bd7a5385d6c9a94c9aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11e90da756a16a8196c511ec8c823d69230fc2c1885a740b6087ac4103b9c66922a6cde90d8cd1d3a229e84742618e80320dd90c53af040c9b5e8bb9dd1353da
|
7
|
+
data.tar.gz: e5856bd91e60f25dd84ad23fbc938f8e136bbf8292fee9ec6e43a27afb36b3609dda6438639a6816cf4ead01055fd527b3f0f02da3b8c4480effffff9cece33c
|
data/.gitignore
CHANGED
data/Appraisals
ADDED
data/Rakefile
CHANGED
data/handlebars_assets.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["leshill@gmail.com"]
|
11
11
|
s.homepage = "https://github.com/leshill/handlebars_assets"
|
12
12
|
s.summary = "Compile Handlebars templates in the Rails asset pipeline."
|
13
|
-
s.description = "A
|
13
|
+
s.description = "A Railties Gem to compile hbs assets"
|
14
14
|
|
15
15
|
s.rubyforge_project = "handlebars_assets"
|
16
16
|
|
@@ -20,15 +20,16 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
22
|
s.add_runtime_dependency "execjs", "~> 2.0"
|
23
|
-
s.add_runtime_dependency "tilt", "
|
23
|
+
s.add_runtime_dependency "tilt", ">= 1.2"
|
24
24
|
s.add_runtime_dependency "multi_json", "~> 1.0"
|
25
|
-
s.add_runtime_dependency "sprockets", ">= 2.0.0"
|
25
|
+
s.add_runtime_dependency "sprockets", ">= 2.0.0"
|
26
26
|
|
27
27
|
s.add_development_dependency "minitest", '~> 5.5'
|
28
28
|
s.add_development_dependency "haml", '~> 4.0'
|
29
29
|
s.add_development_dependency "rake", '~> 10.0'
|
30
30
|
s.add_development_dependency "slim", '~> 3.0'
|
31
|
-
s.add_development_dependency
|
31
|
+
s.add_development_dependency "json", '~> 1.7'
|
32
|
+
s.add_development_dependency "appraisal"
|
32
33
|
|
33
34
|
s.post_install_message = "Remember to rake assets:clean or rake assets:purge on update! this is required because of handlebars updates"
|
34
35
|
end
|
data/lib/handlebars_assets.rb
CHANGED
@@ -4,6 +4,7 @@ module HandlebarsAssets
|
|
4
4
|
autoload(:Config, 'handlebars_assets/config')
|
5
5
|
autoload(:Handlebars, 'handlebars_assets/handlebars')
|
6
6
|
autoload(:HandlebarsTemplate, 'handlebars_assets/handlebars_template')
|
7
|
+
autoload(:HandlebarsProcessor, 'handlebars_assets/handlebars_template')
|
7
8
|
|
8
9
|
PATH = File.expand_path('../../vendor/assets/javascripts', __FILE__)
|
9
10
|
|
@@ -16,6 +17,7 @@ module HandlebarsAssets
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.register_extensions(sprockets_environment)
|
20
|
+
if Gem::Version.new(Sprockets::VERSION) < Gem::Version.new('3')
|
19
21
|
Config.handlebars_extensions.each do |ext|
|
20
22
|
sprockets_environment.register_engine(ext, HandlebarsTemplate)
|
21
23
|
end
|
@@ -29,12 +31,21 @@ module HandlebarsAssets
|
|
29
31
|
sprockets_environment.register_engine(ext, HandlebarsTemplate)
|
30
32
|
end
|
31
33
|
end
|
34
|
+
else
|
35
|
+
sprockets_environment.register_mime_type 'text/x-handlebars-template', extensions: Config.handlebars_extensions
|
36
|
+
if Config.slim_enabled? && Config.slim_available?
|
37
|
+
sprockets_environment.register_mime_type 'text/x-handlebars-template', extensions: Config.slimbars_extensions
|
38
|
+
end
|
39
|
+
if Config.haml_enabled? && Config.haml_available?
|
40
|
+
sprockets_environment.register_mime_type 'text/x-handlebars-template', extensions: Config.hamlbars_extensions
|
41
|
+
end
|
42
|
+
sprockets_environment.register_transformer 'text/x-handlebars-template', 'application/javascript', HandlebarsProcessor
|
43
|
+
end
|
32
44
|
end
|
33
45
|
|
34
46
|
def self.add_to_asset_versioning(sprockets_environment)
|
35
|
-
sprockets_environment.
|
47
|
+
sprockets_environment.version += "-#{HandlebarsAssets::VERSION}"
|
36
48
|
end
|
37
|
-
|
38
49
|
end
|
39
50
|
|
40
51
|
# Register the engine (which will register extension in the app)
|
@@ -2,8 +2,12 @@ module HandlebarsAssets
|
|
2
2
|
# NOTE: must be an engine because we are including assets in the gem
|
3
3
|
class Engine < ::Rails::Engine
|
4
4
|
initializer "handlebars_assets.assets.register", :group => :all do |app|
|
5
|
-
|
6
|
-
|
5
|
+
config.assets.configure do |sprockets_env|
|
6
|
+
::HandlebarsAssets::register_extensions(sprockets_env)
|
7
|
+
if Gem::Version.new(Sprockets::VERSION) < Gem::Version.new('3')
|
8
|
+
::HandlebarsAssets::add_to_asset_versioning(sprockets_env)
|
9
|
+
end
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
13
|
end
|
@@ -12,15 +12,76 @@ module HandlebarsAssets
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
# Sprockets <= 3
|
15
16
|
class HandlebarsTemplate < Tilt::Template
|
16
|
-
|
17
|
-
include Unindent
|
18
|
-
|
19
17
|
def self.default_mime_type
|
20
18
|
'application/javascript'
|
21
19
|
end
|
22
20
|
|
23
21
|
def initialize_engine
|
22
|
+
HandlebarsRenderer.initialize_engine
|
23
|
+
end
|
24
|
+
|
25
|
+
def prepare
|
26
|
+
@engine = renderer.choose_engine(data)
|
27
|
+
end
|
28
|
+
|
29
|
+
def evaluate(scope, locals, &block)
|
30
|
+
source = @engine.render(scope, locals, &block)
|
31
|
+
renderer.compile(source)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def renderer
|
37
|
+
@renderer ||= HandlebarsRenderer.new(path: @file)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Sprockets 4
|
42
|
+
class HandlebarsProcessor
|
43
|
+
|
44
|
+
def self.instance
|
45
|
+
@instance ||= new
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.call(input)
|
49
|
+
instance.call(input)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.cache_key
|
53
|
+
instance.cache_key
|
54
|
+
end
|
55
|
+
|
56
|
+
attr_reader :cache_key
|
57
|
+
|
58
|
+
def initialize(options = {})
|
59
|
+
@cache_key = [self.class.name, ::HandlebarsAssets::VERSION, options].freeze
|
60
|
+
end
|
61
|
+
|
62
|
+
def call(input)
|
63
|
+
renderer = HandlebarsRenderer.new(path: input[:filename])
|
64
|
+
engine = renderer.choose_engine(input[:data])
|
65
|
+
renderer.compile(engine.render)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class NoOpEngine
|
70
|
+
def initialize(data)
|
71
|
+
@data = data
|
72
|
+
end
|
73
|
+
|
74
|
+
def render(*args)
|
75
|
+
@data
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class HandlebarsRenderer
|
80
|
+
include Unindent
|
81
|
+
|
82
|
+
def self.initialize_engine
|
83
|
+
return if @initialized
|
84
|
+
|
24
85
|
begin
|
25
86
|
require 'haml'
|
26
87
|
rescue LoadError
|
@@ -31,28 +92,26 @@ module HandlebarsAssets
|
|
31
92
|
rescue LoadError
|
32
93
|
# slim not available
|
33
94
|
end
|
95
|
+
|
96
|
+
@initialized = true
|
34
97
|
end
|
35
98
|
|
36
|
-
def
|
37
|
-
|
38
|
-
@
|
39
|
-
if @template_path.is_haml?
|
40
|
-
Haml::Engine.new(data, HandlebarsAssets::Config.haml_options)
|
41
|
-
elsif @template_path.is_slim?
|
42
|
-
Slim::Template.new(HandlebarsAssets::Config.slim_options) { data }
|
43
|
-
else
|
44
|
-
nil
|
45
|
-
end
|
99
|
+
def initialize(options)
|
100
|
+
self.class.initialize_engine
|
101
|
+
@template_path = TemplatePath.new(options[:path])
|
46
102
|
end
|
47
103
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
104
|
+
def choose_engine(data)
|
105
|
+
if @template_path.is_haml?
|
106
|
+
Haml::Engine.new(data, HandlebarsAssets::Config.haml_options)
|
107
|
+
elsif @template_path.is_slim?
|
108
|
+
Slim::Template.new(HandlebarsAssets::Config.slim_options) { data }
|
109
|
+
else
|
110
|
+
NoOpEngine.new(data)
|
111
|
+
end
|
112
|
+
end
|
55
113
|
|
114
|
+
def compile(source)
|
56
115
|
# remove trailing \n on file, for some reason the directives pipeline adds this
|
57
116
|
source.chomp!($/)
|
58
117
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require_relative 'shared/adapter_tests'
|
3
|
+
|
4
|
+
module HandlebarsAssets
|
5
|
+
class HandlebarsProcessorTest < Minitest::Test
|
6
|
+
include AdapterTests
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
HandlebarsAssets::Config.reset!
|
10
|
+
HandlebarsAssets::Handlebars.reset!
|
11
|
+
end
|
12
|
+
|
13
|
+
def render_it(scope, source)
|
14
|
+
HandlebarsAssets::HandlebarsProcessor.call(filename: scope.pathname.to_s, data: source)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'haml'
|
3
|
+
require 'slim'
|
4
|
+
|
5
|
+
module AdapterTests
|
6
|
+
include CompilerSupport
|
7
|
+
include SprocketsScope
|
8
|
+
|
9
|
+
def compile_haml(source)
|
10
|
+
::Haml::Engine.new(source, HandlebarsAssets::Config.haml_options).render
|
11
|
+
end
|
12
|
+
|
13
|
+
def compile_slim(source)
|
14
|
+
::Slim::Template.new(HandlebarsAssets::Config.slim_options) { source }.render
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_render
|
18
|
+
root = '/myapp/app/assets/templates'
|
19
|
+
file = 'test_render.hbs'
|
20
|
+
scope = make_scope root, file
|
21
|
+
source = "This is {{handlebars}}"
|
22
|
+
|
23
|
+
assert_equal hbs_compiled('test_render', source), render_it(scope, source)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Sprockets does not add nested root paths (i.e.
|
27
|
+
# app/assets/javascripts/templates is rooted at app/assets/javascripts)
|
28
|
+
def test_template_misnaming
|
29
|
+
root = '/myapp/app/assets/javascripts'
|
30
|
+
file = 'templates/test_template_misnaming.hbs'
|
31
|
+
scope = make_scope root, file
|
32
|
+
source = "This is {{handlebars}}"
|
33
|
+
|
34
|
+
assert_equal hbs_compiled('test_template_misnaming', source), render_it(scope, source)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_path_prefix
|
38
|
+
root = '/myapp/app/assets/javascripts'
|
39
|
+
file = 'app/templates/test_path_prefix.hbs'
|
40
|
+
scope = make_scope root, file
|
41
|
+
source = "This is {{handlebars}}"
|
42
|
+
|
43
|
+
HandlebarsAssets::Config.path_prefix = 'app/templates'
|
44
|
+
|
45
|
+
assert_equal hbs_compiled('test_path_prefix', source), render_it(scope, source)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_underscore_partials
|
49
|
+
root = '/myapp/app/assets/javascripts'
|
50
|
+
file1 = 'app/templates/_test_underscore.hbs'
|
51
|
+
scope1 = make_scope root, file1
|
52
|
+
file2 = 'app/templates/some/thing/_test_underscore.hbs'
|
53
|
+
scope2 = make_scope root, file2
|
54
|
+
source = "This is {{handlebars}}"
|
55
|
+
|
56
|
+
HandlebarsAssets::Config.path_prefix = 'app/templates'
|
57
|
+
|
58
|
+
assert_equal hbs_compiled_partial('_test_underscore', source), render_it(scope1, source)
|
59
|
+
|
60
|
+
assert_equal hbs_compiled_partial('some/thing/_test_underscore', source), render_it(scope2, source)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_chomped_underscore_partials
|
64
|
+
assert_equal HandlebarsAssets::Config.chomp_underscore_for_partials?, false
|
65
|
+
|
66
|
+
HandlebarsAssets::Config.chomp_underscore_for_partials = true
|
67
|
+
assert_equal HandlebarsAssets::Config.chomp_underscore_for_partials?, true
|
68
|
+
|
69
|
+
root = '/myapp/app/assets/javascripts'
|
70
|
+
file1 = 'app/templates/_test_underscore.hbs'
|
71
|
+
scope1 = make_scope root, file1
|
72
|
+
file2 = 'app/templates/some/thing/_test_underscore.hbs'
|
73
|
+
scope2 = make_scope root, file2
|
74
|
+
source = "This is {{handlebars}}"
|
75
|
+
|
76
|
+
HandlebarsAssets::Config.path_prefix = 'app/templates'
|
77
|
+
|
78
|
+
assert_equal hbs_compiled_partial('test_underscore', source), render_it(scope1, source)
|
79
|
+
|
80
|
+
assert_equal hbs_compiled_partial('some/thing/test_underscore', source), render_it(scope2, source)
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_without_known_helpers_opt
|
85
|
+
root = '/myapp/app/assets/templates'
|
86
|
+
file = 'test_without_known.hbs'
|
87
|
+
scope = make_scope root, file
|
88
|
+
source = "{{#with author}}By {{first_name}} {{last_name}}{{/with}}"
|
89
|
+
|
90
|
+
assert_equal hbs_compiled('test_without_known', source), render_it(scope, source)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_known_helpers_opt
|
94
|
+
root = '/myapp/app/assets/templates'
|
95
|
+
file = 'test_known.hbs'
|
96
|
+
scope = make_scope root, file
|
97
|
+
source = "{{#with author}}By {{first_name}} {{last_name}}{{/with}}"
|
98
|
+
|
99
|
+
HandlebarsAssets::Config.known_helpers_only = true
|
100
|
+
|
101
|
+
assert_equal hbs_compiled('test_known', source), render_it(scope, source)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_with_custom_helpers
|
105
|
+
root = '/myapp/app/assets/templates'
|
106
|
+
file = 'test_custom_helper.hbs'
|
107
|
+
scope = make_scope root, file
|
108
|
+
source = "{{#custom author}}By {{first_name}} {{last_name}}{{/custom}}"
|
109
|
+
|
110
|
+
assert_equal hbs_compiled('test_custom_helper', source), render_it(scope, source)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_with_custom_known_helpers
|
114
|
+
root = '/myapp/app/assets/templates'
|
115
|
+
file = 'test_custom_known_helper.hbs'
|
116
|
+
scope = make_scope root, file
|
117
|
+
source = "{{#custom author}}By {{first_name}} {{last_name}}{{/custom}}"
|
118
|
+
|
119
|
+
HandlebarsAssets::Config.known_helpers_only = true
|
120
|
+
HandlebarsAssets::Config.known_helpers = %w(custom)
|
121
|
+
|
122
|
+
assert_equal hbs_compiled('test_custom_known_helper', source), render_it(scope, source)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_template_namespace
|
126
|
+
root = '/myapp/app/assets/javascripts/templates'
|
127
|
+
file = 'test_template_namespace.hbs'
|
128
|
+
scope = make_scope root, file
|
129
|
+
source = "This is {{handlebars}}"
|
130
|
+
|
131
|
+
HandlebarsAssets::Config.template_namespace = 'JST'
|
132
|
+
|
133
|
+
assert_equal hbs_compiled('test_template_namespace', source), render_it(scope, source)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_ember_render
|
137
|
+
root = '/myapp/app/assets/templates'
|
138
|
+
file = 'test_render.hbs'
|
139
|
+
scope = make_scope root, file
|
140
|
+
source = "This is {{handlebars}}"
|
141
|
+
|
142
|
+
HandlebarsAssets::Config.ember = true
|
143
|
+
HandlebarsAssets::Config.multiple_frameworks = false
|
144
|
+
|
145
|
+
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("This is {{handlebars}}");};
|
146
|
+
assert_equal expected_compiled, render_it(scope, source)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_multiple_frameworks_with_ember_render
|
150
|
+
root = '/myapp/app/assets/templates'
|
151
|
+
non_ember = 'test_render.hbs'
|
152
|
+
non_ember_but_with_ember = 'test_member.hbs'
|
153
|
+
ember_ext_no_hbs = 'test_render.ember'
|
154
|
+
ember_ext = 'test_render.ember.hbs'
|
155
|
+
ember_with_haml = 'test_render.ember.hamlbars'
|
156
|
+
ember_with_slim = 'test_render.ember.slimbars'
|
157
|
+
ember_ext_with_erb = 'test_render.ember.hbs.erb'
|
158
|
+
|
159
|
+
HandlebarsAssets::Config.ember = true
|
160
|
+
HandlebarsAssets::Config.multiple_frameworks = true
|
161
|
+
|
162
|
+
# File without ember extension should compile to default namespace
|
163
|
+
scope = make_scope root, non_ember
|
164
|
+
source = "This is {{handlebars}}"
|
165
|
+
assert_equal hbs_compiled('test_render', source), render_it(scope, source)
|
166
|
+
|
167
|
+
# File without ember extension but with ember in it should compile to default namespace
|
168
|
+
scope = make_scope root, non_ember_but_with_ember
|
169
|
+
source = "This is {{handlebars}}"
|
170
|
+
assert_equal hbs_compiled('test_member', source), render_it(scope, source)
|
171
|
+
|
172
|
+
# File with ember extension should compile to ember specific namespace
|
173
|
+
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("This is {{handlebars}}");};
|
174
|
+
scope = make_scope root, ember_ext_no_hbs
|
175
|
+
assert_equal expected_compiled, render_it(scope, source)
|
176
|
+
|
177
|
+
# File with ember and erb extension should compile to ember specific namespace
|
178
|
+
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("This is {{handlebars}}");};
|
179
|
+
scope = make_scope root, ember_ext_with_erb
|
180
|
+
assert_equal expected_compiled, render_it(scope, source)
|
181
|
+
|
182
|
+
# File with ember.hbs extension should compile to ember specific namespace
|
183
|
+
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("This is {{handlebars}}");};
|
184
|
+
scope = make_scope root, ember_ext
|
185
|
+
assert_equal expected_compiled, render_it(scope, source)
|
186
|
+
|
187
|
+
# File with ember.hamlbars extension should compile to ember specific namespace
|
188
|
+
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("<p>This is {{handlebars}}</p>");};
|
189
|
+
scope = make_scope root, ember_with_haml
|
190
|
+
source = "%p This is {{handlebars}}"
|
191
|
+
assert_equal expected_compiled, render_it(scope, source)
|
192
|
+
|
193
|
+
# File with ember.slimbars extension should compile to ember specific namespace
|
194
|
+
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("<p>This is {{handlebars}}</p>");};
|
195
|
+
source = "p This is {{handlebars}}"
|
196
|
+
scope = make_scope root, ember_with_slim
|
197
|
+
assert_equal expected_compiled, render_it(scope, source)
|
198
|
+
end
|
199
|
+
end
|
@@ -1,238 +1,18 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
|
3
|
-
require 'slim'
|
2
|
+
require_relative 'shared/adapter_tests'
|
4
3
|
|
5
4
|
module HandlebarsAssets
|
6
5
|
class HandlebarsTemplateTest < Minitest::Test
|
7
|
-
include
|
8
|
-
include SprocketsScope
|
6
|
+
include AdapterTests
|
9
7
|
|
10
8
|
def teardown
|
11
9
|
HandlebarsAssets::Config.reset!
|
12
10
|
HandlebarsAssets::Handlebars.reset!
|
13
11
|
end
|
14
12
|
|
15
|
-
def
|
16
|
-
::Haml::Engine.new(source, HandlebarsAssets::Config.haml_options).render
|
17
|
-
end
|
18
|
-
|
19
|
-
def compile_slim(source)
|
20
|
-
::Slim::Template.new(HandlebarsAssets::Config.slim_options) { source }.render
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_render
|
24
|
-
root = '/myapp/app/assets/templates'
|
25
|
-
file = 'test_render.hbs'
|
26
|
-
scope = make_scope root, file
|
27
|
-
source = "This is {{handlebars}}"
|
28
|
-
|
29
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
30
|
-
|
31
|
-
assert_equal hbs_compiled('test_render', source), template.render(scope, {})
|
32
|
-
end
|
33
|
-
|
34
|
-
# Sprockets does not add nested root paths (i.e.
|
35
|
-
# app/assets/javascripts/templates is rooted at app/assets/javascripts)
|
36
|
-
def test_template_misnaming
|
37
|
-
root = '/myapp/app/assets/javascripts'
|
38
|
-
file = 'templates/test_template_misnaming.hbs'
|
39
|
-
scope = make_scope root, file
|
40
|
-
source = "This is {{handlebars}}"
|
41
|
-
|
42
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
43
|
-
|
44
|
-
assert_equal hbs_compiled('test_template_misnaming', source), template.render(scope, {})
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_path_prefix
|
48
|
-
root = '/myapp/app/assets/javascripts'
|
49
|
-
file = 'app/templates/test_path_prefix.hbs'
|
50
|
-
scope = make_scope root, file
|
51
|
-
source = "This is {{handlebars}}"
|
52
|
-
|
53
|
-
HandlebarsAssets::Config.path_prefix = 'app/templates'
|
54
|
-
|
55
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
56
|
-
|
57
|
-
assert_equal hbs_compiled('test_path_prefix', source), template.render(scope, {})
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_underscore_partials
|
61
|
-
root = '/myapp/app/assets/javascripts'
|
62
|
-
file1 = 'app/templates/_test_underscore.hbs'
|
63
|
-
scope1 = make_scope root, file1
|
64
|
-
file2 = 'app/templates/some/thing/_test_underscore.hbs'
|
65
|
-
scope2 = make_scope root, file2
|
66
|
-
source = "This is {{handlebars}}"
|
67
|
-
|
68
|
-
HandlebarsAssets::Config.path_prefix = 'app/templates'
|
69
|
-
|
70
|
-
template1 = HandlebarsAssets::HandlebarsTemplate.new(scope1.pathname.to_s) { source }
|
71
|
-
|
72
|
-
assert_equal hbs_compiled_partial('_test_underscore', source), template1.render(scope1, {})
|
73
|
-
|
74
|
-
template2 = HandlebarsAssets::HandlebarsTemplate.new(scope2.pathname.to_s) { source }
|
75
|
-
|
76
|
-
assert_equal hbs_compiled_partial('some/thing/_test_underscore', source), template2.render(scope2, {})
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_chomped_underscore_partials
|
80
|
-
assert_equal HandlebarsAssets::Config.chomp_underscore_for_partials?, false
|
81
|
-
|
82
|
-
HandlebarsAssets::Config.chomp_underscore_for_partials = true
|
83
|
-
assert_equal HandlebarsAssets::Config.chomp_underscore_for_partials?, true
|
84
|
-
|
85
|
-
root = '/myapp/app/assets/javascripts'
|
86
|
-
file1 = 'app/templates/_test_underscore.hbs'
|
87
|
-
scope1 = make_scope root, file1
|
88
|
-
file2 = 'app/templates/some/thing/_test_underscore.hbs'
|
89
|
-
scope2 = make_scope root, file2
|
90
|
-
source = "This is {{handlebars}}"
|
91
|
-
|
92
|
-
HandlebarsAssets::Config.path_prefix = 'app/templates'
|
93
|
-
|
94
|
-
template1 = HandlebarsAssets::HandlebarsTemplate.new(scope1.pathname.to_s) { source }
|
95
|
-
|
96
|
-
assert_equal hbs_compiled_partial('test_underscore', source), template1.render(scope1, {})
|
97
|
-
|
98
|
-
template2 = HandlebarsAssets::HandlebarsTemplate.new(scope2.pathname.to_s) { source }
|
99
|
-
|
100
|
-
assert_equal hbs_compiled_partial('some/thing/test_underscore', source), template2.render(scope2, {})
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_without_known_helpers_opt
|
105
|
-
root = '/myapp/app/assets/templates'
|
106
|
-
file = 'test_without_known.hbs'
|
107
|
-
scope = make_scope root, file
|
108
|
-
source = "{{#with author}}By {{first_name}} {{last_name}}{{/with}}"
|
109
|
-
|
110
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
111
|
-
|
112
|
-
assert_equal hbs_compiled('test_without_known', source), template.render(scope, {})
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_known_helpers_opt
|
116
|
-
root = '/myapp/app/assets/templates'
|
117
|
-
file = 'test_known.hbs'
|
118
|
-
scope = make_scope root, file
|
119
|
-
source = "{{#with author}}By {{first_name}} {{last_name}}{{/with}}"
|
120
|
-
|
121
|
-
HandlebarsAssets::Config.known_helpers_only = true
|
122
|
-
|
13
|
+
def render_it(scope, source)
|
123
14
|
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
124
|
-
|
125
|
-
assert_equal hbs_compiled('test_known', source), template.render(scope, {})
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_with_custom_helpers
|
129
|
-
root = '/myapp/app/assets/templates'
|
130
|
-
file = 'test_custom_helper.hbs'
|
131
|
-
scope = make_scope root, file
|
132
|
-
source = "{{#custom author}}By {{first_name}} {{last_name}}{{/custom}}"
|
133
|
-
|
134
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
135
|
-
|
136
|
-
assert_equal hbs_compiled('test_custom_helper', source), template.render(scope, {})
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_with_custom_known_helpers
|
140
|
-
root = '/myapp/app/assets/templates'
|
141
|
-
file = 'test_custom_known_helper.hbs'
|
142
|
-
scope = make_scope root, file
|
143
|
-
source = "{{#custom author}}By {{first_name}} {{last_name}}{{/custom}}"
|
144
|
-
|
145
|
-
HandlebarsAssets::Config.known_helpers_only = true
|
146
|
-
HandlebarsAssets::Config.known_helpers = %w(custom)
|
147
|
-
|
148
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
149
|
-
|
150
|
-
assert_equal hbs_compiled('test_custom_known_helper', source), template.render(scope, {})
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_template_namespace
|
154
|
-
root = '/myapp/app/assets/javascripts/templates'
|
155
|
-
file = 'test_template_namespace.hbs'
|
156
|
-
scope = make_scope root, file
|
157
|
-
source = "This is {{handlebars}}"
|
158
|
-
|
159
|
-
HandlebarsAssets::Config.template_namespace = 'JST'
|
160
|
-
|
161
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
162
|
-
|
163
|
-
assert_equal hbs_compiled('test_template_namespace', source), template.render(scope, {})
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_ember_render
|
167
|
-
root = '/myapp/app/assets/templates'
|
168
|
-
file = 'test_render.hbs'
|
169
|
-
scope = make_scope root, file
|
170
|
-
source = "This is {{handlebars}}"
|
171
|
-
|
172
|
-
HandlebarsAssets::Config.ember = true
|
173
|
-
HandlebarsAssets::Config.multiple_frameworks = false
|
174
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
175
|
-
|
176
|
-
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("This is {{handlebars}}");};
|
177
|
-
assert_equal expected_compiled, template.render(scope, {})
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_multiple_frameworks_with_ember_render
|
181
|
-
root = '/myapp/app/assets/templates'
|
182
|
-
non_ember = 'test_render.hbs'
|
183
|
-
non_ember_but_with_ember = 'test_member.hbs'
|
184
|
-
ember_ext_no_hbs = 'test_render.ember'
|
185
|
-
ember_ext = 'test_render.ember.hbs'
|
186
|
-
ember_with_haml = 'test_render.ember.hamlbars'
|
187
|
-
ember_with_slim = 'test_render.ember.slimbars'
|
188
|
-
ember_ext_with_erb = 'test_render.ember.hbs.erb'
|
189
|
-
|
190
|
-
HandlebarsAssets::Config.ember = true
|
191
|
-
HandlebarsAssets::Config.multiple_frameworks = true
|
192
|
-
|
193
|
-
# File without ember extension should compile to default namespace
|
194
|
-
scope = make_scope root, non_ember
|
195
|
-
source = "This is {{handlebars}}"
|
196
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
197
|
-
assert_equal hbs_compiled('test_render', source), template.render(scope, {})
|
198
|
-
|
199
|
-
# File without ember extension but with ember in it should compile to default namespace
|
200
|
-
scope = make_scope root, non_ember_but_with_ember
|
201
|
-
source = "This is {{handlebars}}"
|
202
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
203
|
-
assert_equal hbs_compiled('test_member', source), template.render(scope, {})
|
204
|
-
|
205
|
-
# File with ember extension should compile to ember specific namespace
|
206
|
-
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("This is {{handlebars}}");};
|
207
|
-
scope = make_scope root, ember_ext_no_hbs
|
208
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
209
|
-
assert_equal expected_compiled, template.render(scope, {})
|
210
|
-
|
211
|
-
# File with ember and erb extension should compile to ember specific namespace
|
212
|
-
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("This is {{handlebars}}");};
|
213
|
-
scope = make_scope root, ember_ext_with_erb
|
214
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
215
|
-
assert_equal expected_compiled, template.render(scope, {})
|
216
|
-
|
217
|
-
# File with ember.hbs extension should compile to ember specific namespace
|
218
|
-
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("This is {{handlebars}}");};
|
219
|
-
scope = make_scope root, ember_ext
|
220
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { source }
|
221
|
-
assert_equal expected_compiled, template.render(scope, {})
|
222
|
-
|
223
|
-
# File with ember.hamlbars extension should compile to ember specific namespace
|
224
|
-
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("<p>This is {{handlebars}}</p>");};
|
225
|
-
scope = make_scope root, ember_with_haml
|
226
|
-
source = "%p This is {{handlebars}}"
|
227
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { compile_haml(source) }
|
228
|
-
assert_equal expected_compiled, template.render(scope, {})
|
229
|
-
|
230
|
-
# File with ember.slimbars extension should compile to ember specific namespace
|
231
|
-
expected_compiled = %{window.Ember.TEMPLATES["test_render"] = Ember.Handlebars.compile("<p>This is {{handlebars}}</p>");};
|
232
|
-
source = "p This is {{handlebars}}"
|
233
|
-
scope = make_scope root, ember_with_slim
|
234
|
-
template = HandlebarsAssets::HandlebarsTemplate.new(scope.pathname.to_s) { compile_slim(source) }
|
235
|
-
assert_equal expected_compiled, template.render(scope, {})
|
15
|
+
template.render(scope, {})
|
236
16
|
end
|
237
17
|
end
|
238
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handlebars_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Les Hill
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: tilt
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -59,9 +59,6 @@ dependencies:
|
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 2.0.0
|
62
|
-
- - "<"
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: '4.0'
|
65
62
|
type: :runtime
|
66
63
|
prerelease: false
|
67
64
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -69,9 +66,6 @@ dependencies:
|
|
69
66
|
- - ">="
|
70
67
|
- !ruby/object:Gem::Version
|
71
68
|
version: 2.0.0
|
72
|
-
- - "<"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '4.0'
|
75
69
|
- !ruby/object:Gem::Dependency
|
76
70
|
name: minitest
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,7 +136,21 @@ dependencies:
|
|
142
136
|
- - "~>"
|
143
137
|
- !ruby/object:Gem::Version
|
144
138
|
version: '1.7'
|
145
|
-
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: appraisal
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: A Railties Gem to compile hbs assets
|
146
154
|
email:
|
147
155
|
- leshill@gmail.com
|
148
156
|
executables: []
|
@@ -151,11 +159,19 @@ extra_rdoc_files: []
|
|
151
159
|
files:
|
152
160
|
- ".gitignore"
|
153
161
|
- ".ruby-gemset"
|
162
|
+
- Appraisals
|
154
163
|
- CHANGELOG.md
|
155
164
|
- Gemfile
|
156
165
|
- MIT-LICENSE
|
157
166
|
- README.md
|
158
167
|
- Rakefile
|
168
|
+
- gemfiles/rails_4_1.gemfile
|
169
|
+
- gemfiles/rails_4_2.gemfile
|
170
|
+
- gemfiles/rails_5.gemfile
|
171
|
+
- gemfiles/sprockets_2.gemfile
|
172
|
+
- gemfiles/sprockets_3.gemfile
|
173
|
+
- gemfiles/tilt_1.gemfile
|
174
|
+
- gemfiles/tilt_2.gemfile
|
159
175
|
- handlebars_assets.gemspec
|
160
176
|
- lib/handlebars_assets.rb
|
161
177
|
- lib/handlebars_assets/config.rb
|
@@ -166,6 +182,8 @@ files:
|
|
166
182
|
- test/edge/handlebars.js
|
167
183
|
- test/handlebars_assets/compiling_test.rb
|
168
184
|
- test/handlebars_assets/hamlbars_test.rb
|
185
|
+
- test/handlebars_assets/handlebars_processor_test.rb
|
186
|
+
- test/handlebars_assets/shared/adapter_tests.rb
|
169
187
|
- test/handlebars_assets/slimbars_test.rb
|
170
188
|
- test/handlebars_assets/tilt_handlebars_test.rb
|
171
189
|
- test/patch/patch.js
|
@@ -193,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
211
|
version: '0'
|
194
212
|
requirements: []
|
195
213
|
rubyforge_project: handlebars_assets
|
196
|
-
rubygems_version: 2.
|
214
|
+
rubygems_version: 2.4.5.1
|
197
215
|
signing_key:
|
198
216
|
specification_version: 4
|
199
217
|
summary: Compile Handlebars templates in the Rails asset pipeline.
|
@@ -201,7 +219,10 @@ test_files:
|
|
201
219
|
- test/edge/handlebars.js
|
202
220
|
- test/handlebars_assets/compiling_test.rb
|
203
221
|
- test/handlebars_assets/hamlbars_test.rb
|
222
|
+
- test/handlebars_assets/handlebars_processor_test.rb
|
223
|
+
- test/handlebars_assets/shared/adapter_tests.rb
|
204
224
|
- test/handlebars_assets/slimbars_test.rb
|
205
225
|
- test/handlebars_assets/tilt_handlebars_test.rb
|
206
226
|
- test/patch/patch.js
|
207
227
|
- test/test_helper.rb
|
228
|
+
has_rdoc:
|