mustache 0.12.1 → 0.13.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.
@@ -362,6 +362,11 @@ class Mustache
362
362
  if data.is_a? Hash
363
363
  ctx = data
364
364
  tpl = templateify(template)
365
+ elsif data.is_a? Symbol
366
+ old_template_name = self.class.template_name
367
+ self.class.template_name = data
368
+ tpl = templateify(template)
369
+ self.class.template_name = old_template_name
365
370
  else
366
371
  tpl = templateify(data)
367
372
  end
@@ -105,7 +105,7 @@ class Mustache
105
105
  Mustache::Template.new(v.call(#{raw.inspect}).to_s).render(ctx.dup)
106
106
  else
107
107
  # Shortcut when passed non-array
108
- v = [v] if v.respond_to?(:has_key?) || !v.respond_to?(:map)
108
+ v = [v] if v.respond_to?(:has_key?) || !v.respond_to?(:map) || v.is_a?(Struct)
109
109
 
110
110
  v.map { |h| ctx.push(h); r = #{code}; ctx.pop; r }.join
111
111
  end
@@ -1,3 +1,3 @@
1
1
  class Mustache
2
- Version = VERSION = '0.12.1'
2
+ Version = VERSION = '0.13.0'
3
3
  end
@@ -233,6 +233,24 @@ data
233
233
  :deploy_to => '/var/www/example.com' )
234
234
  end
235
235
 
236
+ def test_render_from_symbol
237
+ expected = <<-data
238
+ <VirtualHost *>
239
+ ServerName example.com
240
+ DocumentRoot /var/www/example.com
241
+ RailsEnv production
242
+ </VirtualHost>
243
+ data
244
+ old_path, Mustache.template_path = Mustache.template_path, File.dirname(__FILE__) + "/fixtures"
245
+ old_extension, Mustache.template_extension = Mustache.template_extension, "conf"
246
+
247
+ assert_equal expected, Mustache.render(:passenger, :stage => 'production',
248
+ :server => 'example.com',
249
+ :deploy_to => '/var/www/example.com' )
250
+
251
+ Mustache.template_path, Mustache.template_extension = old_path, old_extension
252
+ end
253
+
236
254
  def test_doesnt_execute_what_it_doesnt_need_to
237
255
  instance = Mustache.new
238
256
  instance[:show] = false
@@ -471,6 +489,14 @@ end
471
489
  template
472
490
  end
473
491
 
492
+ def test_struct
493
+ person = Struct.new(:name, :age)
494
+ view = Mustache.new
495
+ view[:person] = person.new('Marvin', 25)
496
+ view.template = '{{#person}}{{name}} is {{age}}{{/person}}'
497
+ assert_equal 'Marvin is 25', view.render
498
+ end
499
+
474
500
  def test_inherited_attributes
475
501
  Object.const_set :TestNamespace, Module.new
476
502
  base = Class.new(Mustache)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mustache
3
3
  version: !ruby/object:Gem::Version
4
- hash: 45
4
+ hash: 43
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 12
9
- - 1
10
- version: 0.12.1
8
+ - 13
9
+ - 0
10
+ version: 0.13.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Wanstrath
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-22 00:00:00 -08:00
18
+ date: 2011-02-23 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21