Skip to content

Commit

Permalink
implicit iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Feb 24, 2011
1 parent c183699 commit 68a3667
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/mustache/context.rb
Expand Up @@ -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|
Expand Down
12 changes: 12 additions & 0 deletions test/mustache_test.rb
Expand Up @@ -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 <<text, view.render
* Chris
* Mark
* Scott
text
end

def test_dot_notation
assert_equal <<-text.chomp, DotNotation.render
* Chris Firescythe
Expand Down

0 comments on commit 68a3667

Please sign in to comment.