           (read-char rdr))
         templates))))
 
-#_(preprocess-template "templates/inheritance/inherit-c.html")+#_(let [template "templates/inheritance/inherit-c.html"
+        templates (preprocess-template template)]
+    (find-root template templates)
+    (fill-blocks template templates {}))
(ns selmer.template-parser
  (:require [clojure.java.io :refer [reader]]
            [selmer.util :refer :all]))

(declare preprocess-template)


      
      templates)))

(defn find-block [template parent-template block-name]
  )

(defn fill-blocks [template templates block-map]
  (println template block-map)
  (let [blocks (difference (set (get-in templates [template :blocks]))
                           (set (keys block-map)))
        block-map (into block-map (map vector blocks (repeat template)))
        parent (get-in templates [template :extends])]
    (if parent (recur parent templates block-map) block-map)))

(defn find-root [template templates]
  (if-let [parent (get-in templates [template :extends])]
    (recur parent templates)
    template))

(defn preprocess-template [filename & [templates]]
  (with-open [rdr (reader (str (resource-path) filename))]
    (loop [templates (assoc (or templates {}) filename {})
