   {:for {:handler for-handler}
    :block {:handler
            (fn [args rdr]
-             (let [content (tag-content :endblock rdr)]
+             (let [content (tag-content rdr :endblock)]
                (fn [args] (render content args))))}})
 
 (defn expr-tag [{:keys [tag-name args] :as tag} rdr]

            (if (= tag-open ch)
              (do
                ;we hit a tag so we append the buffer content to the template
                ; and empty the buffer, then we proceed to parse the tag                  
                (conj! template (.toString buf))
                (.setLength buf 0)
                (conj! template (handle-tag rdr))

;{:args ("i" "in" "nums"), :tag-name "for", :tag-type :expr}

#_(read-tag-info (java.io.StringReader. "{ nums }}"))

(defn parse-tag [{:keys [tag-type] :as tag} rdr]
  (if (= :filter tag-type)
    (filter-tag tag)
    (expr-tag tag rdr)))

(defn tag-content [rdr & end-tags]
  (let [buf (StringBuilder.)]    
    (loop [ch       (read-char rdr)
           tags     {}
           content  []
           end-tags end-tags]
      (cond 
        (empty? end-tags)
        tags 
        
        (= tag-open ch)
        (let [{:keys [tag-name tag-type] :as tag} (read-tag-info rdr)]            
          (if (some #{tag-name} end-tags)              
            (let [tags     (assoc tags tag-name (conj content (.toString buf)))
                  end-tags (rest (drop-while #(not= tag-name %) end-tags))]                                
              (.setLength buf 0)
              (recur (read-char rdr) tags [] end-tags))
            (let [content (-> content 
                                  (conj (.toString buf))
                                  (conj (parse-tag tag rdr)))]
              (.setLength buf 0)
              (recur (read-char rdr) tags content end-tags))))
        :else
        (do
          (.append buf ch)
          (recur (read-char rdr) tags content end-tags))))))

#_(tag-content (java.io.StringReader. "foo bar {%else%} baz{% endif %}") :else :endif)
#_(tag-content (java.io.StringReader. "foo {{name}} bar  baz {{test}} bat{% endfor %}") :endfor)

#_(render (tag-content (java.io.StringReader. "foo {{name.first}} bar {% endfor %}") :endfor) {:name {:first "Bob"}})
;"foo Bob bar "

(defn handle-tag [rdr]
  (let [tag (read-tag-info rdr)]
    (parse-tag tag rdr)))

(defn parse [file]
  (with-open [rdr (clojure.java.io/reader file)]
