Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #145 from vhx/master

Support allowed liberal tag names in classes
  • Loading branch information...
commit 0e170a145e3418c16267f5702fb38bf7d41e55a5 2 parents 4b1e24b + b43d2cf
@locks locks authored
View
5 lib/mustache/context.rb
@@ -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
View
1  test/fixtures/liberal.mustache
@@ -0,0 +1 @@
+{{first-name}} {{middle_name!}} {{lastName?}}
View
22 test/fixtures/liberal.rb
@@ -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
6 test/mustache_test.rb
@@ -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 0e170a1

Please sign in to comment.
Something went wrong with that request. Please try again.