       (assoc blocks block-name 
              (->buf [buf]
                     (.append buf block-tag)
-                    (consume-block rdr buf))))))
+                    (consume-block rdr buf blocks))))))
 
 (defn process-block [rdr buf block-tag blocks]  
   (let [block-name (get-tag-params #"block" block-tag)]

  (let [template (get-tag-params #"extends" tag-str)]
    (.substring template 1 (dec (.length template)))))

(defn consume-block [rdr & [^StringBuilder buf]]
  (loop [ch (read-char rdr)
         blocks-to-close 1]
    (when (and (pos? blocks-to-close) ch)
      (if (= *tag-open* ch)
        (let [content (read-tag-content rdr)]
          (when buf (.append buf content))
          (recur (read-char rdr) 
                 (long 
                   (cond 
                     (re-matches #"\{\%\s*block.*" content)
                     (inc blocks-to-close)                     
                     (re-matches #"\{\%\s*endblock.*" content)
                     (dec blocks-to-close)
                     :else blocks-to-close))))
        (do
          (when buf (.append buf ch))
          (recur (read-char rdr) blocks-to-close))))))

(defn read-block [rdr block-tag blocks]
  (let [block-name (get-tag-params #"block" block-tag)]

  (-> (read-template template {}) insert-includes))

#_(preprocess-template "templates/inheritance/inherit-c.html")
#_(println "\n----------\n" (preprocess-template "templates/inheritance/inherit-c.html"))
