diff --git a/lib/mustache/context.rb b/lib/mustache/context.rb index 7c1dc355..013095a0 100644 --- a/lib/mustache/context.rb +++ b/lib/mustache/context.rb @@ -96,8 +96,11 @@ def has_key?(key) def fetch(name, default = :__raise) @key = name - # support for dot.notation - if name.to_s.include? '.' + if name == :'.' + # implicit iterators - {{.}} + name = :to_s + elsif name.to_s.include? '.' + # dot notation - {{person.name}} parts = name.to_s.split('.') parts.each do |part| diff --git a/test/mustache_test.rb b/test/mustache_test.rb index 1f77ef41..d53fb11d 100644 --- a/test/mustache_test.rb +++ b/test/mustache_test.rb @@ -508,6 +508,18 @@ def escapeHTML(str) assert_equal 'nothing', Mustache.render("{{thing}}", :thing => "nothing") end + def test_implicit_iterator + view = Mustache.new + view.template = "{{#people}}* {{.}}\n{{/people}}" + view[:people] = %w( Chris Mark Scott ) + + assert_equal <