diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index 0dc7142..996411e 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -23,12 +23,12 @@ (def File s/Any) ; java.io.File -(def Resource +(def Resource {:path Path :uri Uri - :file File + :file File :source-type SourceType - :resource-type ResourceType }) + :resource-type ResourceType}) (def public "resources/public") @@ -62,7 +62,7 @@ :uri (.toURI file) :file file :source-type source-type - :resource-type (cond + :resource-type (cond (.isDirectory file) :dir (.isFile file) :file :else :unknown)})) @@ -106,7 +106,7 @@ file-from-cp (if from-cp (file-from-cp full-path) nil)] - (cond + (cond (some? file-from-fs) (create-resource resource-path file-from-fs :filesystem) (some? file-from-cp) @@ -145,7 +145,7 @@ path-to-work-with :from-cp from-cp :from-fs from-fs) - result (into result + result (into result [resource-to-work-with])] (cond (nil? resource-to-work-with) [] @@ -165,18 +165,17 @@ & {:keys [from-cp from-fs] :or {from-cp true from-fs true}}] - (map #(:path %) + (map #(:path %) (get-resources-recursive fs-prefix base-path paths :from-cp from-cp - :from-fs from-fs)) - ) + :from-fs from-fs))) ; TODO: Add files to keep (s/defn delete-resource-recursive! [path :- s/Str] (let [resource-paths - (reverse (get-resource-paths-recursive + (reverse (get-resource-paths-recursive "" path [""] :from-cp false))] (doseq [resource-path resource-paths] (io/delete-file (str path resource-path))))) @@ -191,18 +190,18 @@ ] (let [resource-paths (get-resource-paths-recursive fs-prefix base-path source-paths)] - (if (empty? resource-paths) - (throw (IllegalArgumentException. (str "resource " resource-paths ", " + (if (empty? resource-paths) + (throw (IllegalArgumentException. (str "resource " resource-paths ", " source-paths " not found"))) - (doseq [resource-path resource-paths] - (let [target-file (io/file target-path resource-path) - source-file (io/file (file-from-cp-or-fs - fs-prefix - base-path - resource-path))] - (io/make-parents target-file) - (when (.isFile source-file) - (io/copy source-file target-file))))))) + (doseq [resource-path resource-paths] + (let [target-file (io/file target-path resource-path) + source-file (io/file (file-from-cp-or-fs + fs-prefix + base-path + resource-path))] + (io/make-parents target-file) + (when (.isFile source-file) + (io/copy source-file target-file))))))) (defn copy-resources-from-user! [fs-prefix resources target-path ignore-patterns] @@ -210,10 +209,39 @@ (copy-resources! fs-prefix resource-path resources target-path ignore-patterns))) -(defn copy-resources-from-theme! +(defn copy-resources-from-theme! [fs-prefix theme target-path ignore-patterns] (let [theme-path (str "templates/themes/" theme)] - (copy-resources! fs-prefix theme-path ["css" "js"] + (copy-resources! fs-prefix theme-path ["css" "js"] target-path ignore-patterns) (copy-resources! fs-prefix (str theme-path "/html") ["404.html"] target-path ignore-patterns))) + +(defn distinct-resources-by-path + [resources] + (loop [paths (set (map :path resources)) + resources resources + acc []] + (cond (empty? resources) acc + (contains? paths (:path (first resources))) (recur (disj paths (:path (first resources))) + (rest resources) + (conj acc (first resources))) + :else (recur paths (rest resources) acc)))) + +(defn get-distinct-markup-dirs + [fs-prefix posts pages ignore-patterns] + (let [base-path "templates/md" + resources (get-resources-recursive + fs-prefix base-path [pages posts]) + filtered-resources (->> (filter #(= (:resource-type %) :dir) resources) + (distinct-resources-by-path))] + filtered-resources)) + +(defn create-dirs-from-markup-folders! + "Copy resources from markup folders. This does not copy the markup entries." + [fs-prefix posts pages target-path ignore-patterns] + (let [resources (get-distinct-markup-dirs fs-prefix posts pages + ignore-patterns)] + (doseq [resource resources] + (io/make-parents (io/file (str target-path "/" (:path resource)))) + (.mkdir (io/file (str target-path "/" (:path resource))))))) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 11b09f6..d9d42e8 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -494,37 +494,37 @@ author-root-uri theme debug? page-model page-root-uri resources] :as config} (read-config) - posts (map klipsify (add-prev-next (read-posts config))) - posts-by-tag (group-by-tags posts) - posts (tag-posts posts config) - latest-posts (->> posts (take recent-posts) vec) - klipsified-pages (map klipsify (read-pages config)) - modelled-pages (cond - (= page-model :flat) klipsified-pages - (= page-model :hierarchic) (hierarchic/build-hierarchic-map page-root-uri klipsified-pages)) - home-page (->> modelled-pages - (filter #(boolean (:home? %))) - (first)) - other-pages (->> modelled-pages - (remove #{home-page}) - (add-prev-next)) - params (merge config - {:today (java.util.Date.) - :title (:site-title config) - :active-page "home" - :tags (map (partial tag-info config) (keys posts-by-tag)) - :latest-posts latest-posts - :pages other-pages - :home-page (if home-page - home-page - (assoc (first latest-posts) :layout "home.html")) - :archives-uri (page-uri "archives.html" config) - :index-uri (page-uri "index.html" config) - :tags-uri (page-uri "tags.html" config) - :rss-uri (cryogen-io/path "/" blog-prefix rss-name) - :site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)}) - file-resource-path (str "file:resources/templates/themes/" theme) - classpath-resource-path (str "templates/themes/" theme)] + posts (map klipsify (add-prev-next (read-posts config))) + posts-by-tag (group-by-tags posts) + posts (tag-posts posts config) + latest-posts (->> posts (take recent-posts) vec) + klipsified-pages (map klipsify (read-pages config)) + modelled-pages (cond + (= page-model :flat) klipsified-pages + (= page-model :hierarchic) (hierarchic/build-hierarchic-map page-root-uri klipsified-pages)) + home-page (->> modelled-pages + (filter #(boolean (:home? %))) + (first)) + other-pages (->> modelled-pages + (remove #{home-page}) + (add-prev-next)) + params (merge config + {:today (java.util.Date.) + :title (:site-title config) + :active-page "home" + :tags (map (partial tag-info config) (keys posts-by-tag)) + :latest-posts latest-posts + :pages other-pages + :home-page (if home-page + home-page + (assoc (first latest-posts) :layout "home.html")) + :archives-uri (page-uri "archives.html" config) + :index-uri (page-uri "index.html" config) + :tags-uri (page-uri "tags.html" config) + :rss-uri (cryogen-io/path "/" blog-prefix rss-name) + :site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)}) + file-resource-path (str "file:resources/templates/themes/" theme) + classpath-resource-path (str "templates/themes/" theme)] (when debug? (println (blue "debug: page-model:")) (println "\t-->" (cyan page-model)) @@ -548,7 +548,12 @@ ignored-files) ;TODO: replace this ; Nur directories kopieren - (copy-resources-from-markup-folders config) + ;(copy-resources-from-markup-folders config) + (cp-io/create-dirs-from-markup-folders! "resources/" + (:posts config) + (:pages config) + (cp-io/path "resources/public" blog-prefix) + ignored-files) (compile-pages params modelled-pages) (compile-posts params posts) (compile-tags params posts-by-tag) diff --git a/src/cryogen_core/hierarchic.clj b/src/cryogen_core/hierarchic.clj index 8ed09d4..3577a94 100644 --- a/src/cryogen_core/hierarchic.clj +++ b/src/cryogen_core/hierarchic.clj @@ -1,39 +1,36 @@ (ns cryogen-core.hierarchic - (:require - [clojure.string :as s])) + (:require + [clojure.string :as s])) (defn normalized-page-root-uri [page-root-uri] - (cond + (cond (= "" page-root-uri) "" - (and - (s/starts-with? page-root-uri "/") - (s/ends-with? page-root-uri "/")) page-root-uri - (and - (s/starts-with? page-root-uri "/") - (not (s/ends-with? page-root-uri "/"))) (str page-root-uri "/") - (and - (not (s/starts-with? page-root-uri "/")) - (s/ends-with? page-root-uri "/")) (str "/" page-root-uri) - (and - (not (s/starts-with? page-root-uri "/")) - (not (s/ends-with? page-root-uri "/"))) (str "/" page-root-uri "/")) - ) + (and + (s/starts-with? page-root-uri "/") + (s/ends-with? page-root-uri "/")) page-root-uri + (and + (s/starts-with? page-root-uri "/") + (not (s/ends-with? page-root-uri "/"))) (str page-root-uri "/") + (and + (not (s/starts-with? page-root-uri "/")) + (s/ends-with? page-root-uri "/")) (str "/" page-root-uri) + (and + (not (s/starts-with? page-root-uri "/")) + (not (s/ends-with? page-root-uri "/"))) (str "/" page-root-uri "/"))) (defn uri-level [uri] - (- (count - (s/split uri #"/")) - 1) - ) + (- (count + (s/split uri #"/")) + 1)) (defn filter-pages-for-uri [uri pages] (let [html? (s/ends-with? uri ".html") clean? (s/ends-with? uri "/") - clean-uri (cond + clean-uri (cond html? (subs uri 0 (- (count uri) 5)) clean? (subs uri 0 (- (count uri) 1)) :default uri)] - (filter #(s/starts-with? (:uri %) clean-uri) pages)) - ) + (filter #(s/starts-with? (:uri %) clean-uri) pages))) (defn build-hierarchic-level "builds one level of hierarchic tree recurs to next level." @@ -41,20 +38,17 @@ (let [current-level (+ 1 (uri-level parent-uri)) pages-of-parent (filter-pages-for-uri parent-uri pages) pages-on-level (filter #(= current-level (uri-level (:uri %))) pages-of-parent) - pages-on-child-level (filter #(< current-level (uri-level (:uri %))) pages-of-parent) - ] + pages-on-child-level (filter #(< current-level (uri-level (:uri %))) pages-of-parent)] (sort-by :page-index (map #(let [page-on-level % - child-pages (filter-pages-for-uri (:uri page-on-level) pages-on-child-level)] + child-pages (filter-pages-for-uri (:uri page-on-level) pages-on-child-level)] (if (empty? child-pages) - page-on-level + page-on-level (merge page-on-level - {:children (build-hierarchic-level (:uri page-on-level) child-pages)}))) pages-on-level)) - )) + {:children (build-hierarchic-level (:uri page-on-level) child-pages)}))) pages-on-level)))) (defn build-hierarchic-map "builds a hierarchic tree from pages" [page-root-uri pages] (let [sorted-pages (sort-by :uri pages)] - (build-hierarchic-level (normalized-page-root-uri page-root-uri) sorted-pages) - )) + (build-hierarchic-level (normalized-page-root-uri page-root-uri) sorted-pages))) diff --git a/src/cryogen_core/io.clj b/src/cryogen_core/io.clj index e595ead..9c4bc01 100644 --- a/src/cryogen_core/io.clj +++ b/src/cryogen_core/io.clj @@ -6,7 +6,7 @@ (def public "resources/public") (defn path - "Creates path from given parts, ignore empty elements" + "Creates path from given parts, ignore empty elements" [& path-parts] (->> path-parts (remove s/blank?) @@ -88,7 +88,7 @@ [config] (let [theme-path (str "themes/" (:theme config))] (copy-resources - (merge config - {:resources [(str theme-path "/css") - (str theme-path "/js") - (str theme-path "/html/404.html")]})))) + (merge config + {:resources [(str theme-path "/css") + (str theme-path "/js") + (str theme-path "/html/404.html")]})))) diff --git a/src/cryogen_core/klipse.clj b/src/cryogen_core/klipse.clj index e3be3ee..430568c 100644 --- a/src/cryogen_core/klipse.clj +++ b/src/cryogen_core/klipse.clj @@ -62,9 +62,9 @@ [html settings] (letfn [(tag [h clas] (enlive/sniptest h - [(keyword (str "code" clas))] - (fn [x] - (update-in x [:attrs :class] #(str % " nohighlight")))))] + [(keyword (str "code" clas))] + (fn [x] + (update-in x [:attrs :class] #(str % " nohighlight")))))] (reduce tag html (eval-classes settings)))) (def defaults diff --git a/src/cryogen_core/rss.clj b/src/cryogen_core/rss.clj index ef28bff..326409b 100644 --- a/src/cryogen_core/rss.clj +++ b/src/cryogen_core/rss.clj @@ -4,30 +4,29 @@ [cryogen-core.io :as cryogen-io]) (:import java.util.Date)) - (defn posts-to-items [^String site-url posts] (map - (fn [{:keys [uri title content date enclosure author description]}] - (let [link (str (if (.endsWith site-url "/") (apply str (butlast site-url)) site-url) uri) - enclosure (if (nil? enclosure) "" enclosure)] - {:guid link - :link link - :title title - :description (or description content) - :author author - :enclosure enclosure - :pubDate date})) - posts)) + (fn [{:keys [uri title content date enclosure author description]}] + (let [link (str (if (.endsWith site-url "/") (apply str (butlast site-url)) site-url) uri) + enclosure (if (nil? enclosure) "" enclosure)] + {:guid link + :link link + :title title + :description (or description content) + :author author + :enclosure enclosure + :pubDate date})) + posts)) (defn make-channel [config posts] (apply - (partial rss/channel-xml - false - {:title (:site-title config) - :link (:site-url config) - :description (:description config) - :lastBuildDate (Date.)}) - (posts-to-items (:site-url config) posts))) + (partial rss/channel-xml + false + {:title (:site-title config) + :link (:site-url config) + :description (:description config) + :lastBuildDate (Date.)}) + (posts-to-items (:site-url config) posts))) (defn make-filtered-channels [{:keys [rss-filters blog-prefix] :as config} posts-by-tag] (doseq [filter rss-filters] diff --git a/src/cryogen_core/sitemap.clj b/src/cryogen_core/sitemap.clj index edaaf0e..9242f15 100644 --- a/src/cryogen_core/sitemap.clj +++ b/src/cryogen_core/sitemap.clj @@ -16,13 +16,13 @@ (defn generate [site-url ignored-files] (with-out-str (emit - {:tag :urlset - :attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"} - :content - (for [^java.io.File f (cryogen-io/find-assets "public" ".html" ignored-files)] - {:tag :url - :content - [{:tag :loc - :content [(str site-url (loc f))]} - {:tag :lastmod - :content [(-> f (.lastModified) (Date.) format-date)]}]})}))) + {:tag :urlset + :attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"} + :content + (for [^java.io.File f (cryogen-io/find-assets "public" ".html" ignored-files)] + {:tag :url + :content + [{:tag :loc + :content [(str site-url (loc f))]} + {:tag :lastmod + :content [(-> f (.lastModified) (Date.) format-date)]}]})}))) diff --git a/src/cryogen_core/toc.clj b/src/cryogen_core/toc.clj index 3544ba3..16166ee 100644 --- a/src/cryogen_core/toc.clj +++ b/src/cryogen_core/toc.clj @@ -12,13 +12,13 @@ headings." [content] (reduce - (fn [headings {:keys [tag attrs content] :as elm}] - (if (some #{tag} _h) - (conj headings elm) - (if-let [more-headings (get-headings content)] - (into headings more-headings) - headings))) - [] content)) + (fn [headings {:keys [tag attrs content] :as elm}] + (if (some #{tag} _h) + (conj headings elm) + (if-let [more-headings (get-headings content)] + (into headings more-headings) + headings))) + [] content)) (defn- zip-toc-tree-to-insertion-point "Given a toc-tree zipper and a header level, navigate @@ -46,25 +46,24 @@ and return it." [headings] (loop [zp (z/zipper - map? - :children - (fn [node children] (assoc node :children (apply vector children))) - {:value :root :children []}) + map? + :children + (fn [node children] (assoc node :children (apply vector children))) + {:value :root :children []}) items headings] (if-let [{tag :tag {id :id} :attrs [{{name :name} :attrs} title :as htext] :content} (first items)] (let [anchor (or id name)] (if (nil? anchor) (recur zp (rest items)) (recur (insert-toc-tree-entry zp - {:tag tag - :anchor anchor - :text (or - (if (string? title) title (-> title :content first)) - (first htext))}) + {:tag tag + :anchor anchor + :text (or + (if (string? title) title (-> title :content first)) + (first htext))}) (rest items)))) (z/root zp)))) - (defn- make-toc-entry "Given an anchor link and some text, construct a toc entry consisting of link to the anchor using the given text, wrapped @@ -73,7 +72,6 @@ (when (and anchor text) [:li [:a {:href (str "#" anchor)} text]])) - (defn- build-toc "Given the root of a toc tree and either :ol or :ul, generate the table of contents and return it as a hiccup tree." @@ -86,9 +84,9 @@ ; Create hiccup sequence of :ol/:ul tag and sequence of :li tags (if (seq children) (let [sublist [first-list-open (map build-toc children - (repeat list-open) - (repeat :outer-list?) - (repeat false))]] + (repeat list-open) + (repeat :outer-list?) + (repeat false))]] (if-let [li li] ; The root element has nothing so ignore it (seq [li sublist]) ; Use seq to lazily concat the li with the sublists sublist)) @@ -105,8 +103,8 @@ [html & {:keys [list-type] :or {list-type :ol}}] (let [list-type (if (true? list-type) :ol list-type)] (-> html - (enlive/html-snippet) - (get-headings) - (build-toc-tree) - (build-toc list-type) - (hiccup/html)))) + (enlive/html-snippet) + (get-headings) + (build-toc-tree) + (build-toc list-type) + (hiccup/html)))) diff --git a/test-resources/templates/md/test_pages/home/.gitkeep b/test-resources/templates/md/test_pages/home/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test-resources/templates/md/test_posts/home/.gitkeep b/test-resources/templates/md/test_posts/home/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/cryogen_core/classpath_able_io_test.clj b/test/cryogen_core/classpath_able_io_test.clj index e0da43a..a63d1ad 100644 --- a/test/cryogen_core/classpath_able_io_test.clj +++ b/test/cryogen_core/classpath_able_io_test.clj @@ -37,15 +37,15 @@ (deftest test-resource-from-cp-or-fs (is - (.exists - (:file + (.exists + (:file (sut/resource-from-cp-or-fs "./test-resources/" "templates/themes/bootstrap4-test" "js")))) (is - (.exists - (:file + (.exists + (:file (sut/resource-from-cp-or-fs "./" "" ".gitkeep")))) (is @@ -60,7 +60,7 @@ {:path "js/subdir" :source-type :classpath :resource-type :dir} - (filter-object + (filter-object (sut/resource-from-cp-or-fs "./not-existing-so-load-from-cp" "templates/themes/bootstrap4-test" @@ -77,54 +77,73 @@ (map filter-object (sut/get-resources-recursive "" "templates/themes/bootstrap4-test" ["js/dummy.js"])))) + (is (= + [] + (sut/get-resources-recursive + "" "templates/themes/bootstrap4-test" ["js/dummy.js"] :from-cp false))) (is (= ["js/subdir" - "js/subdir/test.js" - "js/subdir/subdummy.js"] - (map #(:path %) - (sut/get-resources-recursive - "" "templates/themes/bootstrap4-test" ["js/subdir"]))))) - -(deftest test-get-resource-paths-recursive - (is (= - [] - (sut/get-resource-paths-recursive "" "templates/themes/bootstrap4-test" ["not-existing"]))) - (is (= - ["js/dummy.js"] - (sut/get-resource-paths-recursive - "" "templates/themes/bootstrap4-test" ["js/dummy.js"]))) - (is (= - [] - (sut/get-resource-paths-recursive - "" "templates/themes/bootstrap4-test" ["js/dummy.js"] - :from-cp false))) - (is (= - ["js/subdir" - "js/subdir/test.js" - "js/subdir/subdummy.js"] - (sut/get-resource-paths-recursive - "" "templates/themes/bootstrap4-test" ["js/subdir"]))) + "js/subdir/subdummy.js" + "js/subdir/test.js"] + (sort (map :path + (sut/get-resources-recursive + "" "templates/themes/bootstrap4-test" ["js/subdir"]))))) (is (= ["." "./css" "./css/dummy.css" - "./js" - "./js/subdir" - "./js/subdir/test.js" - "./js/subdir/subdummy.js" - "./js/dummy.js" "./html" "./html/403.html" - "./html/404.html"] - (sut/get-resource-paths-recursive "" "templates/themes/bootstrap4-test" ["."]))) - ) + "./html/404.html" + "./js" + "./js/dummy.js" + "./js/subdir" + "./js/subdir/subdummy.js" + "./js/subdir/test.js"] + (sort (map :path + (sut/get-resources-recursive + "" "templates/themes/bootstrap4-test" ["."])))))) -(deftest test-delete-resource-recursive +(deftest test-get-distinct-markup-dirs + (is (= + ["test_pages" + "test_pages/home" + "test_posts" + "test_posts/home"] + (sort (map :path + (sut/get-distinct-markup-dirs + "not-existing-get-from-cp" + "test_posts" "test_pages" + "")))))) + +(deftest test-distinct-resources-by-path + (is (= [{:path "pages/test"} + {:path "pages/test1"} + {:path "pages/test2"}] + (sut/distinct-resources-by-path [{:path "pages/test"} + {:path "pages/test1"} + {:path "pages/test2"} + {:path "pages/test1"}])))) + +(deftest test-create-dirs-from-markup-folders! + (is (do + (sut/delete-resource-recursive! (str target "2")) + (sut/create-dirs-from-markup-folders! + "not-existing-get-from-cp" "test_posts" "test_pages" + (str target "2") "") + (and (verify-dir-exists + (str (str target "2") "/test_pages")) + (verify-dir-exists + (str (str target "2") "/test_posts")) + (verify-dir-exists + (str (str target "2") "/test_pages/home")))))) + +(deftest test-delete-resource-recursive! (is (do - (.mkdir (io/file (str "target/tmp" target))) - (sut/delete-resource-recursive! (str "target/tmp" target)) - (not (verify-dir-exists (str "target/tmp" target)))))) + (.mkdir (io/file target)) + (sut/delete-resource-recursive! target) + (not (verify-dir-exists target))))) (deftest test-filter-for-ignore-patterns (is (= @@ -132,18 +151,17 @@ (sut/filter-for-ignore-patterns #".*\.ignore" ["file.js" "file.ignore"])))) (deftest test-copy-resources-from-theme! (is (do - (sut/delete-resource-recursive! (str "target/tmp" target)) - (sut/copy-resources-from-theme! "./" theme target "") - (and (verify-dir-exists - (str target "/js")) - (verify-file-exists - (str target "/js/dummy.js")) - (verify-dir-exists - (str target "/js/subdir")) - (verify-file-exists - (str target "/js/subdir/subdummy.js")) - (verify-file-exists - (str target "/css/dummy.css")) - (verify-file-exists - (str target "/404.html")) - )))) + (sut/delete-resource-recursive! target) + (sut/copy-resources-from-theme! "./" theme target "") + (and (verify-dir-exists + (str target "/js")) + (verify-file-exists + (str target "/js/dummy.js")) + (verify-dir-exists + (str target "/js/subdir")) + (verify-file-exists + (str target "/js/subdir/subdummy.js")) + (verify-file-exists + (str target "/css/dummy.css")) + (verify-file-exists + (str target "/404.html")))))) diff --git a/test/cryogen_core/compiler_test.clj b/test/cryogen_core/compiler_test.clj index dcd9525..0442b5f 100644 --- a/test/cryogen_core/compiler_test.clj +++ b/test/cryogen_core/compiler_test.clj @@ -55,21 +55,21 @@ and more content. (let [mu (markdown)] (testing "Finds no files" (is (empty? (check-for-posts mu)) - (is (empty? (check-for-pages mu)))) + (is (empty? (check-for-pages mu)))) - (let [dir->file - [[check-for-posts "resources/templates/md/posts" "post.md"] - [check-for-posts "resources/templates/posts" "post.md"] - [check-for-pages "resources/templates/md/pages" "page.md"] - [check-for-pages "resources/templates/pages" "page.md"]]] - (doseq [[check-fn dir file] dir->file] - (testing (str "Finds files in " dir) - (create-entry dir file) - (let [entries (check-fn mu)] - (is (= 1 (count entries))) - (is (= (.getAbsolutePath (File. (str dir File/separator file))) - (.getAbsolutePath (first entries))))) - (reset-resources))))))) + (let [dir->file + [[check-for-posts "resources/templates/md/posts" "post.md"] + [check-for-posts "resources/templates/posts" "post.md"] + [check-for-pages "resources/templates/md/pages" "page.md"] + [check-for-pages "resources/templates/pages" "page.md"]]] + (doseq [[check-fn dir file] dir->file] + (testing (str "Finds files in " dir) + (create-entry dir file) + (let [entries (check-fn mu)] + (is (= 1 (count entries))) + (is (= (.getAbsolutePath (File. (str dir File/separator file))) + (.getAbsolutePath (first entries))))) + (reset-resources))))))) (defmacro with-markup [mu & body] `(do @@ -92,9 +92,9 @@ and more content. (str "entry" (m/ext mu))))) (with-markup mu (copy-resources-from-markup-folders - {:post-root posts-root - :page-root pages-root - :blog-prefix "/blog"})) + {:post-root posts-root + :page-root pages-root + :blog-prefix "/blog"})) (doseq [dir dirs] (is (.isDirectory (File. (str "resources/public/blog/" dir)))))) @@ -102,9 +102,9 @@ and more content. (reset-resources) (testing "No pages or posts nothing to copy" (copy-resources-from-markup-folders - {:post-root "pages" - :page-root "posts" - :blog-prefix "/blog"}) + {:post-root "pages" + :page-root "posts" + :blog-prefix "/blog"}) (is (not (.isDirectory (File. (str "resources/public/blog/pages"))))) (is (not (.isDirectory (File. (str "resources/public/blog/posts")))))) diff --git a/test/cryogen_core/hierarchic_test.clj b/test/cryogen_core/hierarchic_test.clj index 9f9cb10..dad8a54 100644 --- a/test/cryogen_core/hierarchic_test.clj +++ b/test/cryogen_core/hierarchic_test.clj @@ -1,104 +1,95 @@ (ns cryogen-core.hierarchic-test - (:require - [clojure.test :refer :all] - [cryogen-core.hierarchic :as sut])) + (:require + [clojure.test :refer :all] + [cryogen-core.hierarchic :as sut])) -(defn- page [uri page-index] - {:uri uri - :content uri +(defn- page [uri page-index] + {:uri uri + :content uri :page-index page-index}) -(defn- enhanced-page [uri page-index children] - {:uri uri +(defn- enhanced-page [uri page-index children] + {:uri uri :content uri :page-index page-index :children children}) - + (deftest test-normalized-page-root-uri - (testing - (is (= "" (sut/normalized-page-root-uri ""))) + (testing + (is (= "" (sut/normalized-page-root-uri ""))) (is (= "/root/" (sut/normalized-page-root-uri "root"))) (is (= "/root/" (sut/normalized-page-root-uri "/root"))) (is (= "/root/" (sut/normalized-page-root-uri "root/"))) - (is (= "/root/" (sut/normalized-page-root-uri "/root/"))) - )) + (is (= "/root/" (sut/normalized-page-root-uri "/root/"))))) (deftest test-uri-level - (testing - (is (= 2 (sut/uri-level "/pages/nav1/"))) - (is (= 2 (sut/uri-level "/pages/nav1.html"))) - )) + (testing + (is (= 2 (sut/uri-level "/pages/nav1/"))) + (is (= 2 (sut/uri-level "/pages/nav1.html"))))) -(def pages-clean-1 [(page "/pages/nav1/" 0) +(def pages-clean-1 [(page "/pages/nav1/" 0) (page "/pages/nav1/nav11/" 1) (page "/pages/nav1/nav13/" 3) (page "/pages/nav1/nav11/nav112/" 2) (page "/pages/nav1/nav12/" 2) - (page "/pages/nav1/nav11/xnav111/" 1) - ]) + (page "/pages/nav1/nav11/xnav111/" 1)]) -(def expected-clean-1 [(enhanced-page - "/pages/nav1/" 0 - [(enhanced-page - "/pages/nav1/nav11/" 1 - [(page "/pages/nav1/nav11/xnav111/" 1) - (page "/pages/nav1/nav11/nav112/" 2)]) - (page "/pages/nav1/nav12/" 2) - (page "/pages/nav1/nav13/" 3)] - )]) +(def expected-clean-1 [(enhanced-page + "/pages/nav1/" 0 + [(enhanced-page + "/pages/nav1/nav11/" 1 + [(page "/pages/nav1/nav11/xnav111/" 1) + (page "/pages/nav1/nav11/nav112/" 2)]) + (page "/pages/nav1/nav12/" 2) + (page "/pages/nav1/nav13/" 3)])]) -(def pages-dirty [(page "/pages/nav1.html" 0) +(def pages-dirty [(page "/pages/nav1.html" 0) (page "/pages/nav1/nav11.html" 1) (page "/pages/nav1/nav13.html" 3) (page "/pages/nav1/nav11/nav112.html" 2) (page "/pages/nav1/nav12.html" 2) - (page "/pages/nav1/nav11/xnav111.html" 1) - ]) + (page "/pages/nav1/nav11/xnav111.html" 1)]) -(def expected-dirty [(enhanced-page - "/pages/nav1.html" 0 - [(enhanced-page - "/pages/nav1/nav11.html" 1 - [(page "/pages/nav1/nav11/xnav111.html" 1) - (page "/pages/nav1/nav11/nav112.html" 2)]) - (page "/pages/nav1/nav12.html" 2) - (page "/pages/nav1/nav13.html" 3)] - )]) +(def expected-dirty [(enhanced-page + "/pages/nav1.html" 0 + [(enhanced-page + "/pages/nav1/nav11.html" 1 + [(page "/pages/nav1/nav11/xnav111.html" 1) + (page "/pages/nav1/nav11/nav112.html" 2)]) + (page "/pages/nav1/nav12.html" 2) + (page "/pages/nav1/nav13.html" 3)])]) -(def pages-clean-2 [(page "/pages/1/" 0) +(def pages-clean-2 [(page "/pages/1/" 0) (page "/pages/2/" 1) (page "/pages/2/22/" 0)]) (def expected-clean-2 [(page "/pages/1/" 0) - (enhanced-page - "/pages/2/" 1 - [(page "/pages/2/22/" 0)])]) + (enhanced-page + "/pages/2/" 1 + [(page "/pages/2/22/" 0)])]) -(def pages-clean-3 [(page "/1/" 0) +(def pages-clean-3 [(page "/1/" 0) (page "/2/" 1) (page "/2/22/" 0)]) (def expected-clean-3 [(page "/1/" 0) - (enhanced-page - "/2/" 1 - [(page "/2/22/" 0)])]) + (enhanced-page + "/2/" 1 + [(page "/2/22/" 0)])]) (deftest test-hierarchic-pages - (testing - "hierarchic expectations" - (is (= expected-clean-1 - (sut/build-hierarchic-map "pages" pages-clean-1))) - (is (= expected-dirty - (sut/build-hierarchic-map "pages" pages-dirty))) - (is (= expected-clean-2 - (sut/build-hierarchic-map "pages" pages-clean-2))) - (is (= expected-clean-3 - (sut/build-hierarchic-map "" pages-clean-3))) - ) - ) + (testing + "hierarchic expectations" + (is (= expected-clean-1 + (sut/build-hierarchic-map "pages" pages-clean-1))) + (is (= expected-dirty + (sut/build-hierarchic-map "pages" pages-dirty))) + (is (= expected-clean-2 + (sut/build-hierarchic-map "pages" pages-clean-2))) + (is (= expected-clean-3 + (sut/build-hierarchic-map "" pages-clean-3))))) (deftest test-filter-pages-for-uri - (testing - (is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1/" pages-clean-1)))) - (is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1.html" pages-dirty)))) - )) \ No newline at end of file + (testing + (is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1/" pages-clean-1)))) + (is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1.html" pages-dirty)))))) \ No newline at end of file diff --git a/test/cryogen_core/toc_test.clj b/test/cryogen_core/toc_test.clj index 83bb390..ff9c881 100644 --- a/test/cryogen_core/toc_test.clj +++ b/test/cryogen_core/toc_test.clj @@ -27,9 +27,9 @@ ; Test that the make-toc-entry ignores invalid input (deftest test-make-toc-entry (is (nil? - (make-toc-entry nil "Text"))) + (make-toc-entry nil "Text"))) (is (nil? - (make-toc-entry "anchor" nil))) + (make-toc-entry "anchor" nil))) (is (= [:li [:a {:href "#anchor"} "Text"]] (make-toc-entry "anchor" "Text")))) @@ -45,20 +45,20 @@ no-headers [:div [:p "This is not a header"]] closing-header-larger-than-opening-1 - [:div [:h2 [:a {:name "starting_low"}] - "Starting Low"] - [:h1 [:a {:name "finishing_high"}] - "Finishing High"]] + [:div [:h2 [:a {:name "starting_low"}] + "Starting Low"] + [:h1 [:a {:name "finishing_high"}] + "Finishing High"]] closing-header-larger-than-opening-2 - [:div [:h2 [:a {:name "starting_low"}] - "Starting Low"] - [:h4 [:a {:name "jumping_in"}] - "Jumping Right In"] - [:h3 [:a {:name "pulling_back"}] - "But then pull back"] - [:h2 [:a {:name "to_the_top"}] - "To the top"]]] + [:div [:h2 [:a {:name "starting_low"}] + "Starting Low"] + [:h4 [:a {:name "jumping_in"}] + "Jumping Right In"] + [:h3 [:a {:name "pulling_back"}] + "But then pull back"] + [:h2 [:a {:name "to_the_top"}] + "To the top"]]] (is (= [:ol.content (seq [[:li [:a {:href "#test"} "Test"]]])] (-> simplest-header (parse-to-headings) @@ -90,7 +90,6 @@ "but outer headers cannot be less indented " "than the original header."])))) - (deftest test-generate-toc (let [htmlString "

Test

"] (is (= "
  1. Test
"