stache 0.2.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -0
- data/README.md +32 -7
- data/lib/stache.rb +1 -3
- data/lib/stache/asset_helper.rb +15 -22
- data/lib/stache/config.rb +11 -9
- data/lib/stache/handlebars.rb +7 -0
- data/lib/stache/handlebars/handler.rb +80 -0
- data/lib/stache/handlebars/view.rb +14 -0
- data/lib/stache/mustache.rb +7 -0
- data/lib/stache/mustache/handler.rb +70 -0
- data/lib/stache/mustache/view.rb +37 -0
- data/lib/stache/version.rb +1 -1
- data/spec/controllers/handlebars_controller_spec.rb +35 -0
- data/spec/controllers/stache_controller_spec.rb +17 -5
- data/spec/dummy/app/assets/stylesheets/test.css +3 -0
- data/spec/dummy/app/controllers/handlebars_controller.rb +18 -0
- data/spec/dummy/app/controllers/stache_controller.rb +8 -3
- data/spec/dummy/app/helpers/application_helper.rb +4 -0
- data/spec/dummy/app/views/handlebars/_eaten_by_a.html.hbs +1 -0
- data/spec/dummy/app/views/handlebars/index.html.hbs +1 -0
- data/spec/dummy/app/views/handlebars/with_helpers.html.hbs +3 -0
- data/spec/dummy/app/views/handlebars/with_partials.html.hbs +3 -0
- data/spec/dummy/app/views/stache/with_asset_helpers.html.mustache +4 -0
- data/spec/dummy/config/application.rb +3 -0
- data/spec/dummy/config/initializers/stache.rb +2 -0
- data/spec/dummy/config/routes.rb +5 -53
- data/spec/dummy/lib/with_asset_helpers.rb +11 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/stache/asset_helper_spec.rb +41 -39
- data/spec/stache/config_spec.rb +4 -6
- data/spec/stache/handlebars/handlebars_spec.rb +37 -0
- data/spec/stache/handlebars/profile_autoload.rb +6 -0
- data/spec/stache/handlebars/view_spec.rb +11 -0
- data/spec/stache/{handler_spec.rb → mustache/handler_spec.rb} +8 -8
- data/spec/stache/{profile_autoload.rb → mustache/profile_autoload.rb} +1 -1
- data/spec/stache/mustache/view_spec.rb +11 -0
- data/stache.gemspec +3 -5
- metadata +50 -22
- data/lib/stache/handler.rb +0 -68
- data/lib/stache/view.rb +0 -38
- data/spec/stache/view_spec.rb +0 -9
@@ -1,29 +1,29 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Stache::Handler do
|
3
|
+
describe Stache::Mustache::Handler do
|
4
4
|
# ERBHandler = ActionView::Template::Handlers::ERB.new
|
5
5
|
# def new_template(body = "<%= hello %>", details = {})
|
6
6
|
# ActionView::Template.new(body, "hello template", ERBHandler, {:virtual_path => "hello"}.merge!(details))
|
7
7
|
# end
|
8
8
|
before do
|
9
|
-
@template = ActionView::Template.new("{{body}}", "hello mustache", Stache::Handler, { :virtual_path => "hello_world"})
|
10
|
-
@handler = Stache::Handler.new
|
9
|
+
@template = ActionView::Template.new("{{body}}", "hello mustache", Stache::Mustache::Handler, { :virtual_path => "hello_world"})
|
10
|
+
@handler = Stache::Mustache::Handler.new
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "#mustache_class_from_template" do
|
14
14
|
it "returns the appropriate mustache class" do
|
15
|
-
class HelloWorld < Stache::View; end
|
15
|
+
class HelloWorld < Stache::Mustache::View; end
|
16
16
|
@handler.mustache_class_from_template(@template).should == HelloWorld
|
17
17
|
Object.send(:remove_const, :HelloWorld)
|
18
18
|
end
|
19
19
|
it "is clever about folders and such" do
|
20
20
|
@template.stub!(:virtual_path).and_return("profiles/index")
|
21
|
-
module Profiles; class Index < Stache::View; end; end
|
21
|
+
module Profiles; class Index < Stache::Mustache::View; end; end
|
22
22
|
@handler.mustache_class_from_template(@template).should == Profiles::Index
|
23
23
|
Object.send(:remove_const, :Profiles)
|
24
24
|
end
|
25
|
-
it "retuns Stache::View if it can't find none" do
|
26
|
-
@handler.mustache_class_from_template(@template).should == Stache::View
|
25
|
+
it "retuns Stache::Mustache::View if it can't find none" do
|
26
|
+
@handler.mustache_class_from_template(@template).should == Stache::Mustache::View
|
27
27
|
end
|
28
28
|
it "reraises error if loaded mustache_class raises a NameError" do
|
29
29
|
@template.stub!(:virtual_path).and_return("profiles/index")
|
data/stache.gemspec
CHANGED
@@ -5,7 +5,6 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = 'stache'
|
6
6
|
s.version = Stache::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.date = '2012-01-06'
|
9
8
|
s.authors = ['Matt Wilson']
|
10
9
|
s.email = 'mhw@hypomodern.com'
|
11
10
|
s.homepage = 'http://github.com/agoragames/stache'
|
@@ -25,14 +24,13 @@ Gem::Specification.new do |s|
|
|
25
24
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
25
|
s.require_paths = ['lib']
|
27
26
|
|
28
|
-
s.
|
29
|
-
|
30
|
-
s.add_development_dependency 'rails', '~>3.
|
27
|
+
s.add_development_dependency 'mustache'
|
28
|
+
s.add_development_dependency 'handlebars'
|
29
|
+
s.add_development_dependency 'rails', '~>3.2.0'
|
31
30
|
s.add_development_dependency 'rspec'
|
32
31
|
s.add_development_dependency 'rspec-rails'
|
33
32
|
s.add_development_dependency 'bundler'
|
34
33
|
s.add_development_dependency 'bueller'
|
35
34
|
s.add_development_dependency 'rake'
|
36
|
-
s.add_development_dependency 'rcov'
|
37
35
|
end
|
38
36
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: stache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.9.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Matt Wilson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-05-16 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mustache
|
@@ -21,32 +21,32 @@ dependencies:
|
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
|
-
type: :
|
24
|
+
type: :development
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
27
|
+
name: handlebars
|
28
28
|
prerelease: false
|
29
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: "0"
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id002
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: rails
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 3.2.0
|
46
46
|
type: :development
|
47
47
|
version_requirements: *id003
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name: rspec
|
49
|
+
name: rspec
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
type: :development
|
58
58
|
version_requirements: *id004
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
60
|
+
name: rspec-rails
|
61
61
|
prerelease: false
|
62
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
type: :development
|
69
69
|
version_requirements: *id005
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: bundler
|
72
72
|
prerelease: false
|
73
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
@@ -79,7 +79,7 @@ dependencies:
|
|
79
79
|
type: :development
|
80
80
|
version_requirements: *id006
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
82
|
+
name: bueller
|
83
83
|
prerelease: false
|
84
84
|
requirement: &id007 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
type: :development
|
91
91
|
version_requirements: *id007
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
|
-
name:
|
93
|
+
name: rake
|
94
94
|
prerelease: false
|
95
95
|
requirement: &id008 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
@@ -123,19 +123,31 @@ files:
|
|
123
123
|
- lib/stache.rb
|
124
124
|
- lib/stache/asset_helper.rb
|
125
125
|
- lib/stache/config.rb
|
126
|
-
- lib/stache/
|
126
|
+
- lib/stache/handlebars.rb
|
127
|
+
- lib/stache/handlebars/handler.rb
|
128
|
+
- lib/stache/handlebars/view.rb
|
129
|
+
- lib/stache/mustache.rb
|
130
|
+
- lib/stache/mustache/handler.rb
|
131
|
+
- lib/stache/mustache/view.rb
|
127
132
|
- lib/stache/railtie.rb
|
128
133
|
- lib/stache/util.rb
|
129
134
|
- lib/stache/version.rb
|
130
|
-
-
|
135
|
+
- spec/controllers/handlebars_controller_spec.rb
|
131
136
|
- spec/controllers/stache_controller_spec.rb
|
132
137
|
- spec/dummy/Rakefile
|
138
|
+
- spec/dummy/app/assets/stylesheets/test.css
|
133
139
|
- spec/dummy/app/controllers/application_controller.rb
|
140
|
+
- spec/dummy/app/controllers/handlebars_controller.rb
|
134
141
|
- spec/dummy/app/controllers/stache_controller.rb
|
135
142
|
- spec/dummy/app/helpers/application_helper.rb
|
143
|
+
- spec/dummy/app/views/handlebars/_eaten_by_a.html.hbs
|
144
|
+
- spec/dummy/app/views/handlebars/index.html.hbs
|
145
|
+
- spec/dummy/app/views/handlebars/with_helpers.html.hbs
|
146
|
+
- spec/dummy/app/views/handlebars/with_partials.html.hbs
|
136
147
|
- spec/dummy/app/views/layouts/application.html.erb
|
137
148
|
- spec/dummy/app/views/stache/_eaten_by_a.html.mustache
|
138
149
|
- spec/dummy/app/views/stache/index.html.mustache
|
150
|
+
- spec/dummy/app/views/stache/with_asset_helpers.html.mustache
|
139
151
|
- spec/dummy/app/views/stache/with_partials.html.mustache
|
140
152
|
- spec/dummy/config.ru
|
141
153
|
- spec/dummy/config/application.rb
|
@@ -153,6 +165,7 @@ files:
|
|
153
165
|
- spec/dummy/config/initializers/stache.rb
|
154
166
|
- spec/dummy/config/locales/en.yml
|
155
167
|
- spec/dummy/config/routes.rb
|
168
|
+
- spec/dummy/lib/with_asset_helpers.rb
|
156
169
|
- spec/dummy/public/404.html
|
157
170
|
- spec/dummy/public/422.html
|
158
171
|
- spec/dummy/public/500.html
|
@@ -168,10 +181,13 @@ files:
|
|
168
181
|
- spec/spec_helper.rb
|
169
182
|
- spec/stache/asset_helper_spec.rb
|
170
183
|
- spec/stache/config_spec.rb
|
171
|
-
- spec/stache/
|
172
|
-
- spec/stache/profile_autoload.rb
|
184
|
+
- spec/stache/handlebars/handlebars_spec.rb
|
185
|
+
- spec/stache/handlebars/profile_autoload.rb
|
186
|
+
- spec/stache/handlebars/view_spec.rb
|
187
|
+
- spec/stache/mustache/handler_spec.rb
|
188
|
+
- spec/stache/mustache/profile_autoload.rb
|
189
|
+
- spec/stache/mustache/view_spec.rb
|
173
190
|
- spec/stache/util_spec.rb
|
174
|
-
- spec/stache/view_spec.rb
|
175
191
|
- spec/stache_spec.rb
|
176
192
|
- stache.gemspec
|
177
193
|
homepage: http://github.com/agoragames/stache
|
@@ -202,14 +218,22 @@ signing_key:
|
|
202
218
|
specification_version: 3
|
203
219
|
summary: Configurable Mustache Handler and Helpers for Rails
|
204
220
|
test_files:
|
221
|
+
- spec/controllers/handlebars_controller_spec.rb
|
205
222
|
- spec/controllers/stache_controller_spec.rb
|
206
223
|
- spec/dummy/Rakefile
|
224
|
+
- spec/dummy/app/assets/stylesheets/test.css
|
207
225
|
- spec/dummy/app/controllers/application_controller.rb
|
226
|
+
- spec/dummy/app/controllers/handlebars_controller.rb
|
208
227
|
- spec/dummy/app/controllers/stache_controller.rb
|
209
228
|
- spec/dummy/app/helpers/application_helper.rb
|
229
|
+
- spec/dummy/app/views/handlebars/_eaten_by_a.html.hbs
|
230
|
+
- spec/dummy/app/views/handlebars/index.html.hbs
|
231
|
+
- spec/dummy/app/views/handlebars/with_helpers.html.hbs
|
232
|
+
- spec/dummy/app/views/handlebars/with_partials.html.hbs
|
210
233
|
- spec/dummy/app/views/layouts/application.html.erb
|
211
234
|
- spec/dummy/app/views/stache/_eaten_by_a.html.mustache
|
212
235
|
- spec/dummy/app/views/stache/index.html.mustache
|
236
|
+
- spec/dummy/app/views/stache/with_asset_helpers.html.mustache
|
213
237
|
- spec/dummy/app/views/stache/with_partials.html.mustache
|
214
238
|
- spec/dummy/config.ru
|
215
239
|
- spec/dummy/config/application.rb
|
@@ -227,6 +251,7 @@ test_files:
|
|
227
251
|
- spec/dummy/config/initializers/stache.rb
|
228
252
|
- spec/dummy/config/locales/en.yml
|
229
253
|
- spec/dummy/config/routes.rb
|
254
|
+
- spec/dummy/lib/with_asset_helpers.rb
|
230
255
|
- spec/dummy/public/404.html
|
231
256
|
- spec/dummy/public/422.html
|
232
257
|
- spec/dummy/public/500.html
|
@@ -242,8 +267,11 @@ test_files:
|
|
242
267
|
- spec/spec_helper.rb
|
243
268
|
- spec/stache/asset_helper_spec.rb
|
244
269
|
- spec/stache/config_spec.rb
|
245
|
-
- spec/stache/
|
246
|
-
- spec/stache/profile_autoload.rb
|
270
|
+
- spec/stache/handlebars/handlebars_spec.rb
|
271
|
+
- spec/stache/handlebars/profile_autoload.rb
|
272
|
+
- spec/stache/handlebars/view_spec.rb
|
273
|
+
- spec/stache/mustache/handler_spec.rb
|
274
|
+
- spec/stache/mustache/profile_autoload.rb
|
275
|
+
- spec/stache/mustache/view_spec.rb
|
247
276
|
- spec/stache/util_spec.rb
|
248
|
-
- spec/stache/view_spec.rb
|
249
277
|
- spec/stache_spec.rb
|
data/lib/stache/handler.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'stache/view'
|
2
|
-
|
3
|
-
module Stache
|
4
|
-
# From HAML, thanks a bunch, guys!
|
5
|
-
# In Rails 3.1+, template handlers don't inherit from anything. In <= 3.0, they do.
|
6
|
-
# To avoid messy logic figuring this out, we just inherit from whatever the ERB handler does.
|
7
|
-
class Handler < Stache::Util.av_template_class(:Handlers)::ERB.superclass
|
8
|
-
if Stache::Util.needs_compilable?
|
9
|
-
include Stache::Util.av_template_class(:Handlers)::Compilable
|
10
|
-
end
|
11
|
-
|
12
|
-
# Thanks to Mustache::Rails3 for getting us most of the way home here
|
13
|
-
def compile(template)
|
14
|
-
#
|
15
|
-
# get a custom Mustache, or the default Stache::View
|
16
|
-
mustache_class = mustache_class_from_template(template)
|
17
|
-
|
18
|
-
# Return a string that will be eval'd in the context of the ActionView, ugly, but it works.
|
19
|
-
<<-MUSTACHE
|
20
|
-
mustache = ::#{mustache_class}.new
|
21
|
-
mustache.view = self
|
22
|
-
mustache.template = '#{template.source.gsub(/'/, "\\\\'")}'
|
23
|
-
mustache.virtual_path = '#{template.virtual_path.to_s}'
|
24
|
-
mustache[:yield] = content_for(:layout)
|
25
|
-
mustache.context.update(local_assigns)
|
26
|
-
variables = controller.instance_variable_names
|
27
|
-
variables -= %w[@template]
|
28
|
-
|
29
|
-
if controller.respond_to?(:protected_instance_variables)
|
30
|
-
variables -= controller.protected_instance_variables
|
31
|
-
end
|
32
|
-
|
33
|
-
variables.each do |name|
|
34
|
-
mustache.instance_variable_set(name, controller.instance_variable_get(name))
|
35
|
-
end
|
36
|
-
|
37
|
-
# Declaring an +attr_reader+ for each instance variable in the
|
38
|
-
# Stache::View subclass makes them available to your templates.
|
39
|
-
mustache.class.class_eval do
|
40
|
-
attr_reader *variables.map { |name| name.sub(/^@/, '').to_sym }
|
41
|
-
end
|
42
|
-
|
43
|
-
mustache.render.html_safe
|
44
|
-
MUSTACHE
|
45
|
-
end
|
46
|
-
|
47
|
-
# In Rails 3.1+, #call takes the place of #compile
|
48
|
-
def self.call(template)
|
49
|
-
new.compile(template)
|
50
|
-
end
|
51
|
-
|
52
|
-
# suss out a constant name for the given template
|
53
|
-
def mustache_class_from_template(template)
|
54
|
-
const_name = ActiveSupport::Inflector.camelize(template.virtual_path.to_s)
|
55
|
-
begin
|
56
|
-
const_name.constantize
|
57
|
-
rescue NameError, LoadError => e
|
58
|
-
# Only rescue NameError/LoadError concerning our mustache_class
|
59
|
-
if e.message.match(/#{const_name}$/)
|
60
|
-
Stache::View
|
61
|
-
else
|
62
|
-
raise e
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
data/lib/stache/view.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'mustache'
|
2
|
-
|
3
|
-
module Stache
|
4
|
-
#
|
5
|
-
# A Convienent Base Class for the views. Subclass this for autoloading magic with your templates.
|
6
|
-
#
|
7
|
-
# e.g. if the handler is loading a template from templates/
|
8
|
-
class View < ::Mustache
|
9
|
-
attr_accessor :view, :template, :virtual_path
|
10
|
-
|
11
|
-
def method_missing(method, *args, &block)
|
12
|
-
view.send(method, *args, &block)
|
13
|
-
end
|
14
|
-
|
15
|
-
def respond_to?(method, include_private=false)
|
16
|
-
super(method, include_private) || view.respond_to?(method, include_private)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Redefine where Stache::View templates locate their partials:
|
20
|
-
#
|
21
|
-
# (1) in the same directory as the current template file.
|
22
|
-
# (2) in the shared templates path (can be configured via Config.shared_path=(value))
|
23
|
-
#
|
24
|
-
def partial(name)
|
25
|
-
partial_name = "_#{name}.#{Stache.template_extension}"
|
26
|
-
template_dir = self.virtual_path.split("/")[0..-2].join("/")
|
27
|
-
partial_path = File.expand_path(File.join(Stache.template_base_path, template_dir, partial_name))
|
28
|
-
# ::Rails.logger.info "Checking for #{partial_path} in template_dir: #{template_dir}"
|
29
|
-
unless File.file?(partial_path)
|
30
|
-
partial_path = "#{Stache.shared_path}/#{partial_name}"
|
31
|
-
end
|
32
|
-
|
33
|
-
# ::Rails.logger.info "LOADING PARTIAL: #{partial_path}"
|
34
|
-
File.read(partial_path)
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|