package com.wizzardo.http.framework.template.taglib.g;

import com.wizzardo.http.framework.template.Body;
import com.wizzardo.http.framework.template.ExpressionHolder;
import com.wizzardo.http.framework.template.RenderResult;
import com.wizzardo.http.framework.template.Tag;

import java.util.Collection;
import java.util.Map;

/**
 * @author: moxa
 * Date: 7/3/13
 */
public class Each extends Tag {

    public Each(Map<String, String> attrs, final Body body, String offset) {
        super(attrs, body, offset);

        ExpressionHolder<Collection> raw = new ExpressionHolder<>(attrs.get("in"));
        Object varName = attrs.get("var");
        String var = varName == null ? "it" : String.valueOf(varName);

        add(model -> {
            Collection in = raw.getRaw(model);
            RenderResult result = new RenderResult();
            for (Object ob : in) {
                model.put(var, ob);
                result.add(body.get(model));
            }
            return result;
        });
    }
}
@@ -704,24 +704,73 @@
 (varName);%0A%0A
+        String indexName = attrs.get(%22status%22);%0A%0A
         add(
@@ -780,16 +780,16 @@
 el -%3E %7B%0A
-
         
@@ -881,16 +881,39 @@
 sult();%0A
+            int i = 0;%0A
         
@@ -935,24 +935,24 @@
  ob : in) %7B%0A
-
             
@@ -975,16 +975,103 @@
 r, ob);%0A
+                if (indexName != null)%0A                    model.put(indexName, i++);%0A%0A
         

add status