Skip to content
Browse files

support liberal tag names in classes

  • Loading branch information...
1 parent 5fa9607 commit f117f1cd26e879325966630a9c9e11f19652b38f @ksheurs ksheurs committed Nov 5, 2012
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
5 lib/mustache/context.rb
@@ -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)
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 f117f1c

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