stache 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 351c235cf203b65a8eacf4a9fcb01b9236eb54e1
4
- data.tar.gz: 6540207101f87ff30024205a56c8b308e690280e
3
+ metadata.gz: 35a70dffe63e8b3339b268a7e7e8f392b7b23fcb
4
+ data.tar.gz: e096b6bcf5d4aab498db1fb9032d9a34f07bf169
5
5
  SHA512:
6
- metadata.gz: 689692a05dcf7dc95b82adac7cfb37cd1b0d91f618277584115baffa5a543bc7f0af4e456e172826b5c5dae398b1c06e25822876c14de7a77835fad706e8af2f
7
- data.tar.gz: cfd7331c2b602ac2a777ab3c98f22df598f280a5a25a5b8e7eaef54557b06d7297b07be29134db2a81ba2643125e74cfc31b492a6b37363207f886b443f1e345
6
+ metadata.gz: ce5651630bf430ecef53aa54a69c4d6a8687fd8d7166e385bc1e52c4a3547ace23b998e0dd633a70295ac193897ce4f506ce9f18c2447b4144e1b5b56d70e739
7
+ data.tar.gz: 1a262d6abdb6429f377aa95ef034d17b7d4f52e21aef22fb4651887d937bd61155ac4dda506d7f6c43dd5ca914ec7ced0908330df00b9a5f74f2d47c3ab91ca2
@@ -1,5 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.1
3
+ - 2.1.5
4
+ - 2.2.1
data/README.md CHANGED
@@ -12,7 +12,7 @@ I'm investigating whether or not this is something that can be/needs to be porte
12
12
 
13
13
  If you want Rails 4, you'll have to use 1.0.3.
14
14
 
15
- ## Usage
15
+ ## Installation
16
16
 
17
17
  gem "mustache" # or "handlebars"
18
18
  gem "stache"
@@ -51,7 +51,15 @@ Stache.template_base_path = File.join(Rails.root, "app", "şablon")
51
51
  Stache.template_cache = ActiveSupport::Cache::MemoryStore.new if Rails.env.production?
52
52
  ```
53
53
 
54
- There is as of right now one provided helper, `template_include_tag`. Give it the name of a partial and it will write it raw to a script block.
54
+ ## Helper methods
55
+
56
+ There is currently just one helper method; `template_include_tag`. If you pass it the name of a partial it will write out the contents of the partial in a `script` tag, so that you can access it from within your JavaScript.
57
+
58
+ ```erb
59
+ <%= template_include_tag 'profiles/profile' %>
60
+ ```
61
+
62
+ Specify the template to include with a path *relative to your template base path* (i.e. `profiles/profile` rather than just `profile`).
55
63
 
56
64
  ## A View Class of your Very Own
57
65
 
@@ -151,6 +159,49 @@ View:
151
159
  end
152
160
  ```
153
161
 
162
+ ## Stache + ActionMailer
163
+
164
+ Stache should work just fine with `ActionMailer`, with one minor configuration:
165
+
166
+ Assuming you have a view directory like this:
167
+
168
+ ```
169
+ views/
170
+ user_mailer/
171
+ confirm_sign_up.html.mustache
172
+ confirm_sign_up.rb
173
+ confirm_sign_up.text.mustache
174
+ ```
175
+
176
+ You'd define your `UserMailer` like so:
177
+
178
+ ```ruby
179
+ class UserMailer < ActionMailer::Base
180
+ default from: 'notifications@example.com'
181
+
182
+ def confirm_sign_up
183
+ mail(to: 'user@example.com', subject: 'Welcome to StacheMail') do |format|
184
+ format.text
185
+ format.html
186
+ end
187
+ end
188
+ end
189
+ ```
190
+
191
+ **N.B.** the `do |format|` block is very important: `ActionMailer` will render the code in the `.rb` file as a multipart text/html component, which is probably not what you want unless you really want to show off your View class to all your recipients :).
192
+
193
+ The `confirm_sign_up.rb` file contains an utterly normal `::Stache::Mustache::View` subclass, e.g. Note that it is nested inside the `UserMailer` class.
194
+
195
+ ```ruby
196
+ class UserMailer
197
+ class ConfirmSignUp < ::Stache::Mustache::View
198
+ def full_name
199
+ ["Bob", "Jones"].join(' ')
200
+ end
201
+ end
202
+ end
203
+ ```
204
+
154
205
  ## Of Note
155
206
 
156
207
  This is code that was ripped out of a research project. It probably has some rough edges.
@@ -15,7 +15,6 @@ module Stache
15
15
  # Call the Mustache's `partial` method and render the result.
16
16
  mustache.render(part, self)
17
17
  end
18
-
19
18
  end
20
19
  end
21
20
  end
@@ -35,7 +35,7 @@ module Stache
35
35
 
36
36
  mustache.virtual_path = '#{virtual_path}'
37
37
  mustache[:yield] = content_for(:layout)
38
- mustache.context.update(local_assigns)
38
+ mustache.context.push(local_assigns)
39
39
  variables = controller.instance_variables
40
40
  variables.delete(:@template)
41
41
  variables -= controller.class.protected_instance_variables.to_a
@@ -93,13 +93,14 @@ module Stache
93
93
  return Stache::Mustache::View
94
94
  end
95
95
 
96
- const_name = ActiveSupport::Inflector.camelize(template.virtual_path.to_s)
96
+ const_name = ActiveSupport::Inflector.camelize(ActiveSupport::Inflector.underscore(template.virtual_path.to_s))
97
97
  const_name = "#{Stache.wrapper_module_name}::#{const_name}" if Stache.wrapper_module_name
98
98
  begin
99
99
  const_name.constantize
100
100
  rescue NameError, LoadError => e
101
101
  # Only rescue NameError/LoadError concerning our mustache_class
102
- if e.message.match(/#{const_name}$/)
102
+ e_const_name = e.message.match(/ ([^ ]*)$/)[1]
103
+ if const_name.match(/#{e_const_name}(::|$)/)
103
104
  Stache::Mustache::View
104
105
  else
105
106
  raise e
@@ -1,3 +1,3 @@
1
1
  module Stache
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -0,0 +1,10 @@
1
+ class UserMailer < ActionMailer::Base
2
+ default from: 'notifications@example.com'
3
+
4
+ def confirm_sign_up
5
+ mail(to: 'user@example.com', subject: 'Welcome to StacheMail') do |format|
6
+ format.text
7
+ format.html
8
+ end
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ <h1>Welcome, {{full_name}}!</h1>
@@ -0,0 +1,7 @@
1
+ class UserMailer
2
+ class ConfirmSignUp < ::Stache::Mustache::View
3
+ def full_name
4
+ ["Bob", "Jones"].join(' ')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ Welcome, {{full_name}}!
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe UserMailer do
4
+ describe 'confirm_sign_up' do
5
+ let(:mail) { UserMailer.confirm_sign_up() }
6
+
7
+ it 'renders the subject' do
8
+ expect(mail.subject).to eql('Welcome to StacheMail')
9
+ end
10
+
11
+ it 'renders the mustache template correctly' do
12
+ expect(mail.body.encoded).to match('Welcome, Bob Jones!')
13
+ end
14
+ end
15
+ end
@@ -16,6 +16,12 @@ describe Stache::Mustache::Handler do
16
16
  @handler.mustache_class_from_template(@template).should == HelloWorld
17
17
  Object.send(:remove_const, :HelloWorld)
18
18
  end
19
+ it "handles templates with dashes in the filename" do
20
+ class HelloWorld < Stache::Mustache::View; end
21
+ @template.stub(:virtual_path).and_return 'hello-world'
22
+ @handler.mustache_class_from_template(@template).should == HelloWorld
23
+ Object.send(:remove_const, :HelloWorld)
24
+ end
19
25
  it "is clever about folders and such" do
20
26
  @template.stub(:virtual_path).and_return("profiles/index")
21
27
  module Profiles; class Index < Stache::Mustache::View; end; end
@@ -25,6 +31,10 @@ describe Stache::Mustache::Handler do
25
31
  it "retuns Stache::Mustache::View if it can't find none" do
26
32
  @handler.mustache_class_from_template(@template).should == Stache::Mustache::View
27
33
  end
34
+ it "handles nested paths" do
35
+ @template.stub(:virtual_path).and_return("profiles/sub/index")
36
+ @handler.mustache_class_from_template(@template).should == Stache::Mustache::View
37
+ end
28
38
  it "reraises error if loaded mustache_class raises a NameError" do
29
39
  @template.stub(:virtual_path).and_return("profiles/index")
30
40
  module Profiles; end
@@ -26,11 +26,12 @@ Gem::Specification.new do |s|
26
26
  s.require_paths = ['lib']
27
27
 
28
28
  s.add_development_dependency 'mustache'
29
- s.add_development_dependency 'handlebars', '~>0.4.0'
29
+ s.add_development_dependency 'handlebars', '~>0.6.0'
30
30
  s.add_development_dependency 'rails', '~>4.0.0'
31
31
  s.add_development_dependency 'rspec', '~>2.99.0'
32
32
  s.add_development_dependency 'rspec-rails', '~>2.99.0'
33
33
  s.add_development_dependency 'bundler'
34
34
  s.add_development_dependency 'rake'
35
+ s.add_development_dependency 'test-unit'
35
36
  end
36
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-05 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mustache
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.0
33
+ version: 0.6.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.4.0
40
+ version: 0.6.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: test-unit
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: A Rails 3.x and Rails 4.x compatible Mustache/Handlebars template handler
112
126
  email: mhw@hypomodern.com
113
127
  executables: []
@@ -152,6 +166,7 @@ files:
152
166
  - spec/dummy/app/controllers/handlebars_controller.rb
153
167
  - spec/dummy/app/controllers/stache_controller.rb
154
168
  - spec/dummy/app/helpers/application_helper.rb
169
+ - spec/dummy/app/mailers/user_mailer.rb
155
170
  - spec/dummy/app/views/handlebars/_eaten_by_a.html.hbs
156
171
  - spec/dummy/app/views/handlebars/index.html.hbs
157
172
  - spec/dummy/app/views/handlebars/with_helpers.html.hbs
@@ -178,6 +193,9 @@ files:
178
193
  - spec/dummy/app/views/stache/with_partials.html.mustache
179
194
  - spec/dummy/app/views/stache/with_partials.rb
180
195
  - spec/dummy/app/views/stache/with_wrapper.html.mustache
196
+ - spec/dummy/app/views/user_mailer/confirm_sign_up.html.mustache
197
+ - spec/dummy/app/views/user_mailer/confirm_sign_up.rb
198
+ - spec/dummy/app/views/user_mailer/confirm_sign_up.text.mustache
181
199
  - spec/dummy/config.ru
182
200
  - spec/dummy/config/application.rb
183
201
  - spec/dummy/config/boot.rb
@@ -210,6 +228,7 @@ files:
210
228
  - spec/dummy/public/javascripts/rails.js
211
229
  - spec/dummy/public/stylesheets/.gitkeep
212
230
  - spec/dummy/script/rails
231
+ - spec/mailers/user_mailer_spec.rb
213
232
  - spec/spec_helper.rb
214
233
  - spec/stache/asset_helper_spec.rb
215
234
  - spec/stache/config_spec.rb
@@ -258,6 +277,7 @@ test_files:
258
277
  - spec/dummy/app/controllers/handlebars_controller.rb
259
278
  - spec/dummy/app/controllers/stache_controller.rb
260
279
  - spec/dummy/app/helpers/application_helper.rb
280
+ - spec/dummy/app/mailers/user_mailer.rb
261
281
  - spec/dummy/app/views/handlebars/_eaten_by_a.html.hbs
262
282
  - spec/dummy/app/views/handlebars/index.html.hbs
263
283
  - spec/dummy/app/views/handlebars/with_helpers.html.hbs
@@ -284,6 +304,9 @@ test_files:
284
304
  - spec/dummy/app/views/stache/with_partials.html.mustache
285
305
  - spec/dummy/app/views/stache/with_partials.rb
286
306
  - spec/dummy/app/views/stache/with_wrapper.html.mustache
307
+ - spec/dummy/app/views/user_mailer/confirm_sign_up.html.mustache
308
+ - spec/dummy/app/views/user_mailer/confirm_sign_up.rb
309
+ - spec/dummy/app/views/user_mailer/confirm_sign_up.text.mustache
287
310
  - spec/dummy/config.ru
288
311
  - spec/dummy/config/application.rb
289
312
  - spec/dummy/config/boot.rb
@@ -316,6 +339,7 @@ test_files:
316
339
  - spec/dummy/public/javascripts/rails.js
317
340
  - spec/dummy/public/stylesheets/.gitkeep
318
341
  - spec/dummy/script/rails
342
+ - spec/mailers/user_mailer_spec.rb
319
343
  - spec/spec_helper.rb
320
344
  - spec/stache/asset_helper_spec.rb
321
345
  - spec/stache/config_spec.rb