Support allowed liberal tag names in classes #145

Merged
merged 1 commit into from Mar 1, 2014
View
@@ -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
@@ -0,0 +1 @@
+{{first-name}} {{middle_name!}} {{lastName?}}
View
@@ -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
View
@@ -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}}