<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>TODO.md</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -7,8 +7,10 @@ module H2o
   COMMENT_START = '{*'
   COMMENT_END = '*}'
   
+  IDENTIFIER_RE = /[a-zA-Z_][a-zA-Z0-9_]*/
+  
   NAME_RE = /
-    [a-zA-Z_][a-zA-Z0-9_]*
+    #{IDENTIFIER_RE}
     (?:\.[a-zA-Z0-9][a-zA-Z0-9_-]*)*
   /x
   </diff>
      <filename>lib/h2o/constants.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,11 @@
 module H2o
   module Tags
     class For &lt; Tag
-      Syntax = /(?:(#{H2o::NAME_RE}),\s?)?(#{H2o::NAME_RE})\s+in\s+(#{H2o::NAME_RE})\s*(reversed)?/
+      Syntax = /
+        (?:(#{H2o::IDENTIFIER_RE}),\s?)?
+        (#{H2o::IDENTIFIER_RE})\s+in\s+(#{H2o::NAME_RE})\s*
+        (reversed)?
+      /x
 
       def initialize(parser, argstring)
         @key = false</diff>
      <filename>lib/h2o/tags/for.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,45 +1,78 @@
 require 'spec/spec_helper.rb'
 require 'pp'
 
-describe &quot;For tags&quot; do
+describe &quot;For tag - Iterations&quot; do
   
   it &quot;should iteration through array&quot; do
-    r = parse(&quot;{% for a in list %}{{ a }}{% endfor %}&quot;).render(:list =&gt; [1,2,3])
-    
-    r.should == '123'
+    t = parse(&quot;{% for a in list %}{{ a }}{% endfor %}&quot;)
+    t.render(:list =&gt; [1,2,3]).should == '123'
   end
   
   it &quot;should iterate through array subclass&quot; do
-    context = {:user =&gt; {:lucky_numbers =&gt; Collection.new([1,2,3,4,5,6])}}
-    r = parse(&quot;{% for a in user.lucky_numbers %}{{a}}{%endfor%}&quot;).render(context)
+    t = parse(&quot;{% for i, user in users %}{{ i }}.{{ user }}{% endfor %}&quot;)
+    t.render(:users =&gt;%w(PeterIT ManHoodHero)).should == '0.PeterIT1.ManHoodHero'
+  end
+
+  it &quot;should iterate through a hash object&quot; do
+    person = {:name =&gt; 'taylor', :age =&gt; 19 }
     
-    r.should == '123456'
+    t = parse(&quot;{% for a in person %}{{ a }}{% endfor %}&quot;)
+    t.render(:person =&gt; person).should == 'taylor19'
+
+    t = parse(&quot;{%for a, b in person %}{{ a }}{{ b }}{% endfor %}&quot;)
+    t.render(:person =&gt; person).should == 'nametaylorage19'
   end
   
-  it &quot;should iterate through a hash object&quot; do
-    context = {:person =&gt; {:name =&gt; 'taylor', :age =&gt; 19}}
-    r = parse(&quot;{%for a in person%}{{ a }}{% endfor %}&quot;).render(context)
+end
+
+
+describe &quot;For Tag - Magic loop variable&quot; do
+  
+  before do
+    @context = {:words=&gt; %w(something else about this person) }
+  end
+  
+  it &quot;should correct iteration counters&quot; do
+    fortag('{{ loop.counter }}').render(@context).should == '12345'
+    fortag('{{ loop.counter0 }}').render(@context).should == '01234'
+
+    fortag('{{ loop.revcounter }}').render(@context).should == '54321'
+    fortag('{{ loop.revcounter0 }}').render(@context).should == '43210'
+  end
+  
+  it &quot;should have .even and .odd iteration flag&quot; do
+    fortag('{% if loop.even %}{{ item }}{% endif %}').render(@context).should == 'elsethis'
+    fortag('{% if loop.odd %}{{ item}}{% endif %}').render(@context).should == 'somethingaboutperson'
+  end
+  
+  it &quot;should have .first and .last flag to indicate if it's first/last iteration&quot; do
+    fortag('{%if loop.first %}{{ item }}{% endif }').render(@context).should == 'something'
+    fortag('{%if loop.last %}{{ item }}{% endif }').render(@context).should == 'person'
+  end
+  
+  it &quot;should have parent property pointer to parent loop&quot; do
+    
+    result = fortag(
+      '{% for num in numbers %}{{ loop.parent.counter }}-{{ item }}{% endfor %}'
+    ).render(@context.merge(:numbers=&gt; [6,8]))
     
-    if RUBY_VERSION.match(&quot;1.8&quot;)
-      r.should == '19taylor' 
-    else
-      r.should == 'taylor19'
-    end
+    result.should == '1-something1-something2-else2-else3-about3-about4-this4-this5-person5-person'
     
-    r = parse(&quot;{%for a, b in person %}{{ a }}{{ b }}{% endfor %}&quot;).render(context)
+    result = fortag(
+      '{% for num in numbers %}{% if loop.parent.first %}{{ num }}-{{ item }}{% endif %}{% endfor %}'
+    ).render(@context.merge(:numbers=&gt; [88,99,66]))
+
+    result.should == '88-something99-something66-something'
     
-    if RUBY_VERSION.match(&quot;1.8&quot;)
-      r.should == 'age19nametaylor'
-    else
-      r.should == 'nametaylorage19'
-    end
   end
 
+  def fortag(body)
+    parse(&quot;{% for item in words %}#{body}{% endfor %}&quot;)
+  end
 end
 
 
+
 def parse(source)
   H2o::Template.parse(source)
 end
-
-class Collection &lt; Array;end
\ No newline at end of file</diff>
      <filename>spec/tags_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f538d0c7e5a433af8f9c57faa23faffb88f9b4c7</id>
    </parent>
  </parents>
  <author>
    <name>speedmax</name>
    <email>subjective@gmail.com</email>
  </author>
  <url>http://github.com/speedmax/h2o/commit/7c6557a56c904ace21a88f10e9874b1eaf3b6f85</url>
  <id>7c6557a56c904ace21a88f10e9874b1eaf3b6f85</id>
  <committed-date>2009-05-09T00:33:01-07:00</committed-date>
  <authored-date>2009-05-09T00:33:01-07:00</authored-date>
  <message> - Fixed fortag key, value to be local variable only
 - updated tags_spec for better for_tag testing (iteration, magic loop variable)</message>
  <tree>5eb8929536bb76751cfc6f38fbf27648ef1771ac</tree>
  <committer>
    <name>speedmax</name>
    <email>subjective@gmail.com</email>
  </committer>
</commit>
