Skip to content
This repository has been archived by the owner on May 6, 2019. It is now read-only.

Commit

Permalink
support liberal tag names in classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ksheurs committed Nov 5, 2012
1 parent 5fa9607 commit f117f1c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/mustache/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ def fetch(name, default = :__raise)
def find(obj, key, default = nil)
hash = obj.respond_to?(:has_key?)

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

if hash && obj.has_key?(key)
obj[key]
elsif hash && obj.has_key?(key.to_s)
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

0 comments on commit f117f1c

Please sign in to comment.