stache 1.0.0.rc → 1.0.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.
- data/CHANGELOG.md +10 -0
- data/README.md +13 -1
- data/Rakefile +2 -2
- data/lib/stache/config.rb +5 -2
- data/lib/stache/handlebars/handler.rb +2 -0
- data/lib/stache/mustache/handler.rb +2 -1
- data/lib/stache/version.rb +1 -1
- data/spec/controllers/handlebars_controller_spec.rb +14 -0
- data/spec/controllers/stache_controller_spec.rb +14 -0
- data/spec/dummy/app/controllers/handlebars_controller.rb +4 -0
- data/spec/dummy/app/controllers/stache_controller.rb +4 -0
- data/spec/dummy/app/views/handlebars/with_wrapper.html.hbs +3 -0
- data/spec/dummy/app/views/stache/with_wrapper.html.mustache +3 -0
- data/spec/dummy/config/application.rb +2 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/lib/wrapper/handlebars/with_wrapper.rb +9 -0
- data/spec/dummy/lib/wrapper/stache/with_wrapper.rb +9 -0
- data/spec/stache/config_spec.rb +15 -2
- data/spec/stache/handlebars/handlebars_spec.rb +22 -0
- data/spec/stache/mustache/handler_spec.rb +22 -0
- metadata +11 -6
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 1.0.0
|
2
|
+
|
3
|
+
* Overhauled Mustache template engine. If you wish to have Mustache drive your entire template stack, you can invert control to it.
|
4
|
+
* Fixed a bunch of problems with Handlebars access to the view namespace for helpers, etc.
|
5
|
+
* New configuration option: you can now specify a wrapper namespace that Stache will look for your view classes in.
|
6
|
+
|
7
|
+
Backwards compatibility should be fine; any regressions are bugs and should be reported.
|
8
|
+
|
9
|
+
Huge thanks to all contributors!
|
10
|
+
|
1
11
|
# 0.9.1
|
2
12
|
|
3
13
|
* soften our hardcore stance on missing properties.
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ A Rails 3.x compatible Mustache/Handlebars Template Handler, with support for pa
|
|
4
4
|
|
5
5
|
[](http://travis-ci.org/agoragames/stache)
|
6
6
|
|
7
|
-
## 1.0.0
|
7
|
+
## 1.0.0
|
8
8
|
|
9
9
|
Major overhaul to the mustache side of things. Backwards compatibility *should* be intact. If not, file a bug and it will get taken care of.
|
10
10
|
|
@@ -26,6 +26,10 @@ Stache.configure do |c|
|
|
26
26
|
c.template_base_path = "..." # this is probably the one you'll want to change
|
27
27
|
# it defaults to app/templates
|
28
28
|
|
29
|
+
c.wrapper_module_name = "..." # this lets you indicate the name of a module that
|
30
|
+
# namespaces all your view classes, useful, if you
|
31
|
+
# have a naming conflict, such as with a mailer
|
32
|
+
|
29
33
|
# N.B. YOU MUST TELL STACHE WHICH TO USE:
|
30
34
|
c.use :mustache
|
31
35
|
# and / or
|
@@ -74,6 +78,10 @@ end
|
|
74
78
|
<p>Here's a helper_method call: {{ my_view_helper_method }}</p>
|
75
79
|
```
|
76
80
|
|
81
|
+
With the wrapper_module_name configuration set to "Wrapper":
|
82
|
+
|
83
|
+
With a template `app/templates/profiles/index`, Stache will look for a view named `Wrapper::Profiles::Index`, and, if not found, will just use the base `Stache::Mustache::View`.
|
84
|
+
|
77
85
|
### Handlebars?
|
78
86
|
|
79
87
|
Handlebars will have full access to your rails view helpers.
|
@@ -113,6 +121,10 @@ So: thanks a ton to those guys.
|
|
113
121
|
* [ajacksified](https://github.com/ajacksified) cleaned up template extension handling.
|
114
122
|
* [ayamomiji](https://github.com/ayamomiji) extended the `#template_include_tag` to pass through the full range of `#content_tag` options.
|
115
123
|
* [awestendorf](https://github.com/awestendorf) requested that `View#partial` not be so particular about leading underscores. Though I didn't use his code, his prompt lead me to investigate how to properly use Rails' internal template lookup code.
|
124
|
+
* [zombor](https://github.com/zombor) contributed an overhaul to the Mustache renderer that puts Mustache classes themselves in control of the render chain, not Rails.
|
125
|
+
* [kategengler](https://github.com/kategengler) contributed a patch to allow folks to specify a namespace for their view objects.
|
126
|
+
|
127
|
+
Thanks a ton to all of the contributors as well. This would never have grown beyond a mediocre tool that rendered partials without their help!
|
116
128
|
|
117
129
|
## Note on Patches/Pull Requests
|
118
130
|
|
data/Rakefile
CHANGED
data/lib/stache/config.rb
CHANGED
@@ -11,13 +11,12 @@ module Stache
|
|
11
11
|
# use :mustache # or :handlebars
|
12
12
|
# end
|
13
13
|
module Config
|
14
|
-
attr_accessor :template_base_path, :shared_path
|
14
|
+
attr_accessor :template_base_path, :shared_path, :wrapper_module_name
|
15
15
|
|
16
16
|
def configure
|
17
17
|
yield self
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
20
|
def template_base_path
|
22
21
|
@template_base_path ||= ::Rails.root.join('app', 'templates')
|
23
22
|
end
|
@@ -30,6 +29,10 @@ module Stache
|
|
30
29
|
@shared_path ||= ::Rails.root.join('app', 'templates', 'shared')
|
31
30
|
end
|
32
31
|
|
32
|
+
def wrapper_module_name
|
33
|
+
@wrapper_module_name ||= nil
|
34
|
+
end
|
35
|
+
|
33
36
|
def use template_engine
|
34
37
|
require "stache/#{template_engine}"
|
35
38
|
end
|
@@ -70,6 +70,8 @@ module Stache
|
|
70
70
|
# suss out a constant name for the given template
|
71
71
|
def handlebars_class_from_template(template)
|
72
72
|
const_name = ActiveSupport::Inflector.camelize(template.virtual_path.to_s)
|
73
|
+
const_name = "#{Stache.wrapper_module_name}::#{const_name}" if Stache.wrapper_module_name
|
74
|
+
|
73
75
|
begin
|
74
76
|
const_name.constantize
|
75
77
|
rescue NameError, LoadError => e
|
@@ -25,7 +25,7 @@ module Stache
|
|
25
25
|
if #{mustache_class} == Stache::Mustache::View
|
26
26
|
template_source = '#{template.source.gsub(/'/, "\\\\'")}'
|
27
27
|
else
|
28
|
-
template_name =
|
28
|
+
template_name = "#{template.virtual_path.to_s}.#{template.formats.first.to_s}."+mustache.template_extension
|
29
29
|
template_source = File.read(File.join(::Stache.template_base_path, template_name))
|
30
30
|
end
|
31
31
|
|
@@ -68,6 +68,7 @@ module Stache
|
|
68
68
|
end
|
69
69
|
|
70
70
|
const_name = ActiveSupport::Inflector.camelize(template.virtual_path.to_s)
|
71
|
+
const_name = "#{Stache.wrapper_module_name}::#{const_name}" if Stache.wrapper_module_name
|
71
72
|
begin
|
72
73
|
const_name.constantize
|
73
74
|
rescue NameError, LoadError => e
|
data/lib/stache/version.rb
CHANGED
@@ -15,6 +15,20 @@ describe HandlebarsController do
|
|
15
15
|
response.body.should =~ /Hello, Matt!/
|
16
16
|
end
|
17
17
|
|
18
|
+
it "can render using a module wrapper" do
|
19
|
+
begin
|
20
|
+
Stache.wrapper_module_name = "Wrapper"
|
21
|
+
|
22
|
+
get :with_wrapper
|
23
|
+
assert_response 200
|
24
|
+
|
25
|
+
response.should render_template 'with_wrapper'
|
26
|
+
response.body.should =~ /Yes/
|
27
|
+
ensure
|
28
|
+
Stache.wrapper_module_name = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
18
32
|
it "correctly renders partials" do
|
19
33
|
get :with_partials
|
20
34
|
assert_response 200
|
@@ -15,6 +15,20 @@ describe StacheController do
|
|
15
15
|
response.body.should =~ /Hello, Matt!/
|
16
16
|
end
|
17
17
|
|
18
|
+
it "can render using a module wrapper" do
|
19
|
+
begin
|
20
|
+
Stache.wrapper_module_name = "Wrapper"
|
21
|
+
|
22
|
+
get :with_wrapper
|
23
|
+
assert_response 200
|
24
|
+
|
25
|
+
response.should render_template 'with_wrapper'
|
26
|
+
response.body.should =~ /Yes/
|
27
|
+
ensure
|
28
|
+
Stache.wrapper_module_name = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
18
32
|
it "correctly renders partials" do
|
19
33
|
get :with_partials
|
20
34
|
assert_response 200
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -9,6 +9,8 @@ Dummy::Application.routes.draw do
|
|
9
9
|
|
10
10
|
get 'stache/with_asset_helpers', :to => 'stache#with_asset_helpers'
|
11
11
|
|
12
|
+
get 'stache/with_wrapper', :to => 'stache#with_wrapper'
|
13
|
+
|
12
14
|
get 'handlebars', :to => 'handlebars#index', :as => 'handlebars'
|
13
15
|
|
14
16
|
get 'handlebars/with_partials', :to => 'handlebars#with_partials'
|
@@ -16,4 +18,6 @@ Dummy::Application.routes.draw do
|
|
16
18
|
get 'handlebars/with_helpers', :to => 'handlebars#with_helpers'
|
17
19
|
|
18
20
|
get 'handlebars/with_missing_data', :to => 'handlebars#with_missing_data'
|
21
|
+
|
22
|
+
get 'handlebars/with_wrapper', :to => 'handlebars#with_wrapper'
|
19
23
|
end
|
data/spec/stache/config_spec.rb
CHANGED
@@ -7,8 +7,7 @@ describe "Stache::Config" do
|
|
7
7
|
end
|
8
8
|
[:template_base_path, :shared_path].each do |attr|
|
9
9
|
it "sets up an attribute named #{attr.to_s}" do
|
10
|
-
|
11
|
-
Stache.should respond_to("#{attr}=")
|
10
|
+
should_set_up_attr_accessor_for(attr)
|
12
11
|
end
|
13
12
|
|
14
13
|
it "sets up a default value for #{attr}" do
|
@@ -20,6 +19,15 @@ describe "Stache::Config" do
|
|
20
19
|
end
|
21
20
|
end
|
22
21
|
end
|
22
|
+
|
23
|
+
it "sets up an attribute named wrapper_module_name" do
|
24
|
+
attr = :wrapper_module_name
|
25
|
+
should_set_up_attr_accessor_for(attr)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sets a default value for wrapper_module_name" do
|
29
|
+
Stache.send(:wrapper_module_name).should be_nil
|
30
|
+
end
|
23
31
|
end
|
24
32
|
|
25
33
|
describe ".configure" do
|
@@ -34,4 +42,9 @@ describe "Stache::Config" do
|
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
45
|
+
def should_set_up_attr_accessor_for(attr)
|
46
|
+
Stache.should respond_to(attr)
|
47
|
+
Stache.should respond_to("#{attr}=")
|
48
|
+
end
|
49
|
+
|
37
50
|
end
|
@@ -34,4 +34,26 @@ describe Stache::Handlebars::Handler do
|
|
34
34
|
Object.send(:remove_const, :Profiles)
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
describe "#handlebars_class_from_template with config module wrapper set" do
|
39
|
+
before do
|
40
|
+
Stache.wrapper_module_name = "Wrapper"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns the appropriate handlebars class" do
|
44
|
+
module Wrapper; class HelloWorld < ::Stache::Handlebars::View; end; end
|
45
|
+
@handler.handlebars_class_from_template(@template).should == Wrapper::HelloWorld
|
46
|
+
Object.send(:remove_const, :Wrapper)
|
47
|
+
end
|
48
|
+
it "is clever about folders and such" do
|
49
|
+
@template.stub!(:virtual_path).and_return("profiles/index")
|
50
|
+
module Wrapper; module Profiles; class Index < ::Stache::Handlebars::View; end; end; end
|
51
|
+
@handler.handlebars_class_from_template(@template).should == Wrapper::Profiles::Index
|
52
|
+
Object.send(:remove_const, :Wrapper)
|
53
|
+
end
|
54
|
+
|
55
|
+
after do
|
56
|
+
Stache.wrapper_module_name = nil
|
57
|
+
end
|
58
|
+
end
|
37
59
|
end
|
@@ -38,4 +38,26 @@ describe Stache::Mustache::Handler do
|
|
38
38
|
Object.send(:remove_const, :Profiles)
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
describe "#mustache_class_from_template with config module wrapper set" do
|
43
|
+
before do
|
44
|
+
Stache.wrapper_module_name = "Wrapper"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns the appropriate mustache class" do
|
48
|
+
module Wrapper; class HelloWorld < ::Stache::Mustache::View; end; end
|
49
|
+
@handler.mustache_class_from_template(@template).should == Wrapper::HelloWorld
|
50
|
+
Object.send(:remove_const, :Wrapper)
|
51
|
+
end
|
52
|
+
it "is clever about folders and such" do
|
53
|
+
@template.stub!(:virtual_path).and_return("profiles/index")
|
54
|
+
module Wrapper; module Profiles; class Index < ::Stache::Mustache::View; end; end; end
|
55
|
+
@handler.mustache_class_from_template(@template).should == Wrapper::Profiles::Index
|
56
|
+
Object.send(:remove_const, :Wrapper)
|
57
|
+
end
|
58
|
+
|
59
|
+
after do
|
60
|
+
Stache.wrapper_module_name = nil
|
61
|
+
end
|
62
|
+
end
|
41
63
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Matt Wilson
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mustache
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- spec/dummy/app/views/handlebars/with_helpers.html.hbs
|
170
170
|
- spec/dummy/app/views/handlebars/with_missing_data.html.hbs
|
171
171
|
- spec/dummy/app/views/handlebars/with_partials.html.hbs
|
172
|
+
- spec/dummy/app/views/handlebars/with_wrapper.html.hbs
|
172
173
|
- spec/dummy/app/views/layouts/application.html.erb
|
173
174
|
- spec/dummy/app/views/stache/_eaten_by_a.html.mustache
|
174
175
|
- spec/dummy/app/views/stache/helper.html.mustache
|
@@ -181,6 +182,7 @@ files:
|
|
181
182
|
- spec/dummy/app/views/stache/with_layout.rb
|
182
183
|
- spec/dummy/app/views/stache/with_partials.html.mustache
|
183
184
|
- spec/dummy/app/views/stache/with_partials.rb
|
185
|
+
- spec/dummy/app/views/stache/with_wrapper.html.mustache
|
184
186
|
- spec/dummy/config.ru
|
185
187
|
- spec/dummy/config/application.rb
|
186
188
|
- spec/dummy/config/boot.rb
|
@@ -198,6 +200,8 @@ files:
|
|
198
200
|
- spec/dummy/config/locales/en.yml
|
199
201
|
- spec/dummy/config/routes.rb
|
200
202
|
- spec/dummy/lib/with_asset_helpers.rb
|
203
|
+
- spec/dummy/lib/wrapper/handlebars/with_wrapper.rb
|
204
|
+
- spec/dummy/lib/wrapper/stache/with_wrapper.rb
|
201
205
|
- spec/dummy/public/404.html
|
202
206
|
- spec/dummy/public/422.html
|
203
207
|
- spec/dummy/public/500.html
|
@@ -234,9 +238,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
234
238
|
- - ! '>='
|
235
239
|
- !ruby/object:Gem::Version
|
236
240
|
version: '0'
|
237
|
-
segments:
|
238
|
-
- 0
|
239
|
-
hash: 2542393094037451014
|
240
241
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
242
|
none: false
|
242
243
|
requirements:
|
@@ -263,6 +264,7 @@ test_files:
|
|
263
264
|
- spec/dummy/app/views/handlebars/with_helpers.html.hbs
|
264
265
|
- spec/dummy/app/views/handlebars/with_missing_data.html.hbs
|
265
266
|
- spec/dummy/app/views/handlebars/with_partials.html.hbs
|
267
|
+
- spec/dummy/app/views/handlebars/with_wrapper.html.hbs
|
266
268
|
- spec/dummy/app/views/layouts/application.html.erb
|
267
269
|
- spec/dummy/app/views/stache/_eaten_by_a.html.mustache
|
268
270
|
- spec/dummy/app/views/stache/helper.html.mustache
|
@@ -275,6 +277,7 @@ test_files:
|
|
275
277
|
- spec/dummy/app/views/stache/with_layout.rb
|
276
278
|
- spec/dummy/app/views/stache/with_partials.html.mustache
|
277
279
|
- spec/dummy/app/views/stache/with_partials.rb
|
280
|
+
- spec/dummy/app/views/stache/with_wrapper.html.mustache
|
278
281
|
- spec/dummy/config.ru
|
279
282
|
- spec/dummy/config/application.rb
|
280
283
|
- spec/dummy/config/boot.rb
|
@@ -292,6 +295,8 @@ test_files:
|
|
292
295
|
- spec/dummy/config/locales/en.yml
|
293
296
|
- spec/dummy/config/routes.rb
|
294
297
|
- spec/dummy/lib/with_asset_helpers.rb
|
298
|
+
- spec/dummy/lib/wrapper/handlebars/with_wrapper.rb
|
299
|
+
- spec/dummy/lib/wrapper/stache/with_wrapper.rb
|
295
300
|
- spec/dummy/public/404.html
|
296
301
|
- spec/dummy/public/422.html
|
297
302
|
- spec/dummy/public/500.html
|