Skip to content

Commit

Permalink
allow render to take a symbol identifying template by name
Browse files Browse the repository at this point in the history
this means i can do the following:

    Mustache.render(:foo, {:bar => :baz})

to get `foo.mustache` to render with the above data
  • Loading branch information
lenary authored and defunkt committed Feb 23, 2011
1 parent 44dfefd commit 48fadd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/mustache.rb
Expand Up @@ -362,6 +362,9 @@ def render(data = template, ctx = {})
if data.is_a? Hash
ctx = data
tpl = templateify(template)
elsif data.is_a? Symbol
self.class.template_name = data
tpl = templateify(template)
else
tpl = templateify(data)
end
Expand Down
18 changes: 18 additions & 0 deletions test/mustache_test.rb
Expand Up @@ -233,6 +233,24 @@ def test_render_from_file
:deploy_to => '/var/www/example.com' )
end

def test_render_from_symbol
expected = <<-data
<VirtualHost *>
ServerName example.com
DocumentRoot /var/www/example.com
RailsEnv production
</VirtualHost>
data
old_path, Mustache.template_path = Mustache.template_path, File.dirname(__FILE__) + "/fixtures"
old_extension, Mustache.template_extension = Mustache.template_extension, "conf"

assert_equal expected, Mustache.render(:passenger, :stage => 'production',
:server => 'example.com',
:deploy_to => '/var/www/example.com' )

Mustache.template_path, Mustache.template_extension = old_path, old_extension
end

def test_doesnt_execute_what_it_doesnt_need_to
instance = Mustache.new
instance[:show] = false
Expand Down

0 comments on commit 48fadd7

Please sign in to comment.