diff --git a/project.clj b/project.clj index 70d36c4..6dd21bc 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject cryogen-core "0.1.40" +(defproject cryogen-core "0.1.41" :description "Cryogen's compiler" :url "https://github.com/cryogen-project/cryogen-core" :license {:name "Eclipse Public License" @@ -12,6 +12,6 @@ [io.aviso/pretty "0.1.26"] [hiccup "1.0.5"] [selmer "1.0.4"] - [pandect "0.5.4"] + [pandect "0.6.0"] [hawk "0.2.10"] [clj-tagsoup "0.3.0" :exclusions [org.clojure/clojure]]]) diff --git a/resources/.gitkeep b/resources/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 3f4d139..dfbf151 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -31,15 +31,30 @@ [ext] (re-pattern (str (s/replace ext "." "\\.") "$"))) +(defn find-entries + "Returns a list of files under the templates directory according to the + implemented Markup protocol and specified root directory. It defaults to + looking under the implemented protocol's subdirectory, but fallsback to look + at the templates directory." + [root mu ignored-files] + (let [assets (find-assets (path "templates" (m/dir mu) root) + (m/ext mu) + ignored-files)] + (if (seq assets) + assets + (find-assets (path "templates" root) + (m/ext mu) + ignored-files)))) + (defn find-posts - "Returns a list of markdown files representing posts under the post root in templates/md" + "Returns a list of markdown files representing posts under the post root." [{:keys [post-root ignored-files]} mu] - (find-assets (path "templates" (m/dir mu) post-root) (m/ext mu) ignored-files)) + (find-entries post-root mu ignored-files)) (defn find-pages - "Returns a list of markdown files representing pages under the page root in templates/md" + "Returns a list of markdown files representing pages under the page root." [{:keys [page-root ignored-files]} mu] - (find-assets (path "templates" (m/dir mu) page-root) (m/ext mu) ignored-files)) + (find-entries page-root mu ignored-files)) (defn parse-post-date "Parses the post date from the post's file name and returns the corresponding java date object" @@ -381,14 +396,26 @@ [posts config] (map #(update-in % [:tags] (partial map (partial tag-info config))) posts)) +(defn- template-dir? + "Checks that the dir exists in the templates directory." + [dir] + (.isDirectory (file (str "resources/templates/" dir)))) + +(defn- markup-entries [post-root page-root] + (let [entries (for [mu (m/markups) + t (distinct [post-root page-root])] + [(str (m/dir mu) "/" t) t])] + (apply concat entries))) + (defn copy-resources-from-markup-folders - "Copy resources from markup folders" + "Copy resources from markup folders. This does not copy the markup entries." [{:keys [post-root page-root] :as config}] - (copy-resources - (merge config - {:resources (for [mu (m/markups) - t (distinct [post-root page-root])] (str (m/dir mu) "/" t)) - :ignored-files (map #(re-pattern-from-ext (m/ext %)) (m/markups))}))) + (let [folders (->> (markup-entries post-root page-root) + (filter template-dir?))] + (copy-resources + (merge config + {:resources folders + :ignored-files (map #(re-pattern-from-ext (m/ext %)) (m/markups))})))) (defn read-config "Reads the config file" diff --git a/src/cryogen_core/markup.clj b/src/cryogen_core/markup.clj index 69b671c..d9c7143 100644 --- a/src/cryogen_core/markup.clj +++ b/src/cryogen_core/markup.clj @@ -26,3 +26,13 @@ Markups." [] @markup-registry) + +(defn register-markup + "Add a Markup implementation to the registry." + [mu] + (swap! markup-registry conj mu)) + +(defn clear-registry + "Reset the Markup registry." + [] + (reset! markup-registry [])) diff --git a/test/cryogen_core/compiler_test.clj b/test/cryogen_core/compiler_test.clj index e7e77ca..7a79396 100644 --- a/test/cryogen_core/compiler_test.clj +++ b/test/cryogen_core/compiler_test.clj @@ -1,6 +1,10 @@ (ns cryogen-core.compiler-test (:require [clojure.test :refer :all] - [cryogen-core.compiler :refer :all])) + [cryogen-core.compiler :refer :all] + [cryogen-core.io :refer [path]] + [cryogen-core.markup :as m] + [me.raynes.fs :as fs]) + (:import [java.io File])) ; Test that the content-until-more-marker return nil or correct html text. (deftest test-content-until-more-marker @@ -21,3 +25,85 @@ and more content. "