Permalink
Browse files

Support allowed liberal tag names

  • Loading branch information...
1 parent 4b1e24b commit b43d2cf9cdf7a4a75d2952b3d99b855f8e5c2ac6 @ksheurs ksheurs committed Feb 20, 2014
Showing with 34 additions and 0 deletions.
  1. +5 −0 lib/mustache/context.rb
  2. +1 −0 test/fixtures/liberal.mustache
  3. +22 −0 test/fixtures/liberal.rb
  4. +6 −0 test/mustache_test.rb
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}}

0 comments on commit b43d2cf

Please sign in to comment.