Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support allowed liberal tag names in classes #145

Merged
merged 1 commit into from
Mar 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/mustache/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def find(obj, key, default = nil)
hash = obj.respond_to?(:to_hash)

if !hash
# If a class, we need to find tags (methods) per Parser::ALLOWED_CONTENT.
if key.to_s.include?('-')
key = key.to_s.gsub('-', '_')
end

if obj.respond_to?(key)
meth = obj.method(key) rescue proc { obj.send(key) }
if meth.arity == 1
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/liberal.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{first-name}} {{middle_name!}} {{lastName?}}
22 changes: 22 additions & 0 deletions test/fixtures/liberal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
require 'mustache'

class Liberal < Mustache
self.path = File.dirname(__FILE__)

def first_name
"kevin"
end

def middle_name!
'j'
end

def lastName?
'sheurs'
end
end

if $0 == __FILE__
puts Liberal.to_html
end
6 changes: 6 additions & 0 deletions test/mustache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,12 @@ def test_liberal_tag_names
assert_equal "chris j strath", Mustache.render(template, hash)
end

def test_liberal_tag_names_in_class
assert_equal <<-end_liberal, Liberal.render
kevin j sheurs
end_liberal
end

def test_nested_sections_same_names
template = <<template
{{#items}}
Expand Down