   (let [template (clean-up template)
         template (m/replace-in-template template (template-qualifier dataset extract-type) "{{>")
         template-key (template-key dataset extract-type name)]
-      (try 
+      (try
         (m/register template-key template)
         (m/render template-key {}) ;check template can be rendered with empty map
         {:template template-key :status "registered"}

(defn template-key [dataset extract-type name]
  (str (template-qualifier dataset extract-type) name))

(defn- template-with-metadata* [dataset file]
  (let [file-name (.getName file)]
    {:dataset dataset
     :extract-type (cond-> file 
                           (-> file .getParentFile .getName (= "partials")) .getParentFile
                           true .getParentFile 
                           true .getName) 
     :name (subs file-name 0 (.lastIndexOf file-name ".")) 
     :template (slurp (.getPath file))}))

(defn templates-with-metadata [dataset template-location]
    "Returns the template-contents with metadata included. 
     The metadata is based on dataset and where template-file in direcotry structure is located."
  (let [template-files (filter #(.isFile %) (file-seq (io/file template-location)))]
    (map (partial template-with-metadata* dataset) template-files)))

(defn- clean-up [source]

        (log/error "Template: " template-key " cannot be registered")
        (log/error e)
        false))))
