A big ol' cleanup

This commit is contained in:
Carmen La 2017-01-16 02:37:19 -05:00
parent abf45945d0
commit dec80185e5
11 changed files with 223 additions and 278 deletions

View file

@ -4,16 +4,16 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[clj-rss "0.2.3"]
[me.raynes/fs "1.4.6"]
[crouton "0.1.2"]
[cheshire "5.6.3"]
[clj-rss "0.2.3"]
[clj-text-decoration "0.0.3"]
[io.aviso/pretty "0.1.33"]
[hiccup "1.0.5"]
[selmer "1.10.3"]
[pandect "0.6.1"]
[crouton "0.1.2"]
[enlive "1.1.6"]
[hawk "0.2.11"]
[enlive "1.1.6"]]
[hiccup "1.0.5"]
[io.aviso/pretty "0.1.33"]
[me.raynes/fs "1.4.6"]
[pandect "0.6.1"]
[selmer "1.10.3"]]
:deploy-repositories [["snapshots" :clojars]
["releases" :clojars]])

View file

@ -1,19 +1,17 @@
(ns cryogen-core.compiler
(:require [selmer.parser :refer [cache-off! render-file]]
[selmer.util :refer [set-custom-resource-path!]]
[io.aviso.exception :refer [write-exception]]
[clojure.java.io :refer [copy file reader writer]]
(:require [clojure.java.io :as io]
[clojure.string :as s]
[text-decoration.core :refer :all]
[io.aviso.exception :refer [write-exception]]
[net.cgrand.enlive-html :as enlive]
[cryogen-core.toc :refer [generate-toc]]
[cryogen-core.sass :as sass]
[selmer.parser :refer [cache-off! render-file]]
[selmer.util :refer [set-custom-resource-path!]]
[text-decoration.core :refer :all]
[cryogen-core.io :as cryogen-io]
[cryogen-core.markup :as m]
[cryogen-core.io :refer
[get-resource find-assets create-folder create-file-recursive create-file wipe-public-folder
copy-resources copy-resources-from-theme path]]
[cryogen-core.rss :as rss]
[cryogen-core.sass :as sass]
[cryogen-core.sitemap :as sitemap]
[cryogen-core.rss :as rss])
[cryogen-core.toc :as toc])
(:import java.util.Locale))
(cache-off!)
@ -36,12 +34,14 @@
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)
(let [assets (cryogen-io/find-assets
(cryogen-io/path "templates" (m/dir mu) root)
(m/ext mu)
ignored-files)]
(if (seq assets)
assets
(find-assets (path "templates" root)
(cryogen-io/find-assets
(cryogen-io/path "templates" root)
(m/ext mu)
ignored-files))))
@ -66,9 +66,9 @@
([file-name params]
(page-uri file-name nil params))
([file-name uri-type {:keys [blog-prefix clean-urls?] :as params}]
(let [page-uri (params uri-type)
(let [page-uri (get params uri-type)
uri-end (if clean-urls? (s/replace file-name #"(index)?\.html" "/") file-name)]
(path "/" blog-prefix page-uri uri-end))))
(cryogen-io/path "/" blog-prefix page-uri uri-end))))
(defn read-page-meta
"Returns the clojure map from the top of a markdown page/post"
@ -82,7 +82,7 @@
"Returns a map with the given page's file-name, metadata and content parsed from
the file with the given markup."
[^java.io.File page config markup]
(with-open [rdr (java.io.PushbackReader. (reader page))]
(with-open [rdr (java.io.PushbackReader. (io/reader page))]
(let [re-root (re-pattern (str "^.*?(" (:page-root config) "|" (:post-root config) ")/"))
page-fwd (s/replace (str page) "\\" "/") ;; make it work on Windows
page-name (s/replace page-fwd re-root "")
@ -101,7 +101,7 @@
{:file-name file-name
:content content
:toc (if-let [toc (:toc page-meta)]
(generate-toc content :list-type toc))}))
(toc/generate-toc content :list-type toc))}))
(defn parse-page
"Parses a page/post and returns a map of the content, uri, date etc."
@ -121,7 +121,7 @@
(let [date (if (:date page-meta)
(.parse (java.text.SimpleDateFormat. (:post-date-format config)) (:date page-meta))
(parse-post-date file-name (:post-date-format config)))
archive-fmt (java.text.SimpleDateFormat. (get config :archive-group-format "yyyy MMMM") (Locale/getDefault))
archive-fmt (java.text.SimpleDateFormat. (:archive-group-format config "yyyy MMMM") (Locale/getDefault))
formatted-group (.format archive-fmt date)]
{:date date
:formatted-archive-group formatted-group
@ -133,13 +133,13 @@
"Returns a sequence of maps representing the data from markdown files of posts.
Sorts the sequence by post date."
[config]
(->> (mapcat
(->> (m/markups)
(mapcat
(fn [mu]
(->>
(find-posts config mu)
(pmap #(parse-post % config mu))
(remove #(= (:draft? %) true))))
(m/markups))
(remove #(= (:draft? %) true)))))
(sort-by :date)
reverse
(drop-while #(and (:hide-future-posts? config) (.after (:date %) (java.util.Date.))))))
@ -148,12 +148,12 @@
"Returns a sequence of maps representing the data from markdown files of pages.
Sorts the sequence by post date."
[config]
(->> (mapcat
(->> (m/markups)
(mapcat
(fn [mu]
(->>
(find-pages config mu)
(map #(parse-page % config mu))))
(m/markups))
(map #(parse-page % config mu)))))
(sort-by :page-index)))
(defn tag-post
@ -161,7 +161,8 @@
[tags post]
(reduce (fn [tags tag]
(update-in tags [tag] (fnil conj []) (select-keys post [:uri :title :content :date :enclosure])))
tags (:tags post)))
tags
(:tags post)))
(defn group-by-tags
"Maps all the tags with a list of posts that contain each tag"
@ -219,26 +220,26 @@
"When `clean-urls?` is set, appends `/index.html` before spit; otherwise just spits."
[file-uri {:keys [clean-urls?]} data]
(if clean-urls?
(create-file-recursive (path file-uri "index.html") data)
(create-file file-uri data)))
(cryogen-io/create-file-recursive (cryogen-io/path file-uri "index.html") data)
(cryogen-io/create-file file-uri data)))
(defn compile-pages
"Compiles all the pages into html and spits them out into the public folder"
[{:keys [blog-prefix page-root-uri debug?] :as params} pages]
(when-not (empty? pages)
(println (blue "compiling pages"))
(create-folder (path "/" blog-prefix page-root-uri))
(cryogen-io/create-folder (cryogen-io/path "/" blog-prefix page-root-uri))
(doseq [{:keys [uri] :as page} pages]
(println "\t-->" (cyan uri))
(when debug?
(println "\t-->" (cyan page)))
(println "\t\tdebug-->" (cyan page)))
(write-html uri
params
(render-file (str "/html/" (:layout page))
(merge params
{:active-page "pages"
:home false
:servlet-context (path "/" blog-prefix "/")
:servlet-context (cryogen-io/path "/" blog-prefix "/")
:page page
:uri uri}))))))
@ -247,28 +248,27 @@
[{:keys [blog-prefix post-root-uri disqus-shortname debug?] :as params} posts]
(when-not (empty? posts)
(println (blue "compiling posts"))
(create-folder (path "/" blog-prefix post-root-uri))
(doseq [post posts]
(println "\t-->" (cyan (:uri post)))
(println "\t-->" (cyan debug?))
(cryogen-io/create-folder (cryogen-io/path "/" blog-prefix post-root-uri))
(doseq [{:keys [uri] :as post} posts]
(println "\t-->" (cyan uri))
(when debug?
(println "\t-->" (cyan post)))
(write-html (:uri post)
(println "\t\tdebug-->" (cyan post)))
(write-html uri
params
(render-file (str "/html/" (:layout post))
(merge params
{:active-page "posts"
:servlet-context (path "/" blog-prefix "/")
:servlet-context (cryogen-io/path "/" blog-prefix "/")
:post post
:disqus-shortname disqus-shortname
:uri (:uri post)}))))))
:uri uri}))))))
(defn compile-tags
"Compiles all the tag pages into html and spits them out into the public folder"
[{:keys [blog-prefix tag-root-uri] :as params} posts-by-tag]
(when-not (empty? posts-by-tag)
(println (blue "compiling tags"))
(create-folder (path "/" blog-prefix tag-root-uri))
(cryogen-io/create-folder (cryogen-io/path "/" blog-prefix tag-root-uri))
(doseq [[tag posts] posts-by-tag]
(let [{:keys [name uri]} (tag-info params tag)]
(println "\t-->" (cyan uri))
@ -277,12 +277,13 @@
(render-file "/html/tag.html"
(merge params
{:active-page "tags"
:servlet-context (path "/" blog-prefix "/")
:servlet-context (cryogen-io/path "/" blog-prefix "/")
:name name
:posts posts
:uri uri})))))))
(defn compile-tags-page [{:keys [blog-prefix] :as params}]
"Compiles a page with links to each tag page. Spits the page into the public folder"
(println (blue "compiling tags page"))
(let [uri (page-uri "tags.html" params)]
(write-html uri
@ -290,7 +291,7 @@
(render-file "/html/tags.html"
(merge params
{:active-page "tags"
:servlet-context (path "/" blog-prefix "/")
:servlet-context (cryogen-io/path "/" blog-prefix "/")
:uri uri})))))
(defn content-until-more-marker
@ -315,7 +316,7 @@
(defn create-previews
"Returns a sequence of vectors, each containing a set of post previews"
[posts-per-page blocks-per-preview posts]
[posts posts-per-page blocks-per-preview]
(->> posts
(map #(create-preview blocks-per-preview %))
(partition-all posts-per-page)
@ -327,38 +328,41 @@
[previews params]
(mapv (fn [[prev target next]]
(merge target
{:prev (if prev (page-uri (path "p" (str (:index prev) ".html")) params) nil)
:next (if next (page-uri (path "p" (str (:index next) ".html")) params) nil)}))
{:prev (if prev (page-uri (cryogen-io/path "p" (str (:index prev) ".html")) params) nil)
:next (if next (page-uri (cryogen-io/path "p" (str (:index next) ".html")) params) nil)}))
(partition 3 1 (flatten [nil previews nil]))))
(defn compile-preview-pages
"Compiles a series of pages containing 'previews' from each post"
[{:keys [blog-prefix posts-per-page blocks-per-preview] :as params} posts]
(when-not (empty? posts)
(let [previews (-> (create-previews posts-per-page blocks-per-preview posts)
(let [previews (-> posts
(create-previews posts-per-page blocks-per-preview)
(create-preview-links params))
previews (if (> (count previews) 1) (assoc-in previews [1 :prev] (page-uri "index.html" params)) previews)]
(create-folder (path "/" blog-prefix "p"))
previews (if (> (count previews) 1)
(assoc-in previews [1 :prev] (page-uri "index.html" params))
previews)]
(cryogen-io/create-folder (cryogen-io/path "/" blog-prefix "p"))
(doseq [{:keys [index posts prev next]} previews
:let [index-page? (= 1 index)]]
(write-html (if index-page? (page-uri "index.html" params) (page-uri (path "p" (str index ".html")) params))
(write-html
(if index-page? (page-uri "index.html" params)
(page-uri (cryogen-io/path "p" (str index ".html")) params))
params
(render-file "/html/previews.html"
(merge params
{:active-page "preview"
:home (when index-page? true)
:servlet-context (path "/" blog-prefix "/")
:servlet-context (cryogen-io/path "/" blog-prefix "/")
:posts posts
:prev-uri prev
:next-uri next})))))))
(defn compile-index
"Compiles the index page into html and spits it out into the public folder"
[{:keys [disqus?] :as params}]
[{:keys [disqus? debug? home-page] :as params}]
(println (blue "compiling index"))
(let [uri (page-uri "index.html" params)
debug? (-> params :debug?)
home-page (-> params :home-page)
meta {:active-page "home"
:home true
:disqus? disqus?
@ -366,7 +370,7 @@
:post home-page
:page home-page}]
(when debug?
(println "\t-->" (cyan meta)))
(println "\t\tdebug-->" (cyan meta)))
(write-html uri
params
(render-file (str "/html/" (:layout home-page))
@ -385,14 +389,14 @@
{:active-page "archives"
:archives true
:groups (group-for-archive posts)
:servlet-context (path "/" blog-prefix "/")
:servlet-context (cryogen-io/path "/" blog-prefix "/")
:uri uri})))))
(defn compile-authors
"For each author, creates a page with filtered posts."
[{:keys [blog-prefix author-root-uri author] :as params} posts]
(println (blue "compiling authors"))
(create-folder (path "/" blog-prefix author-root-uri))
(cryogen-io/create-folder (cryogen-io/path "/" blog-prefix author-root-uri))
;; if the post author is empty defaults to config's :author
(doseq [{:keys [author posts]} (group-for-author posts author)]
(let [uri (page-uri (str author ".html") :author-root-uri params)]
@ -403,7 +407,7 @@
(merge params
{:author author
:groups (group-for-archive posts)
:servlet-context (path "/" blog-prefix "/")
:servlet-context (cryogen-io/path "/" blog-prefix "/")
:uri uri}))))))
(defn tag-posts
@ -414,7 +418,7 @@
(defn- template-dir?
"Checks that the dir exists in the templates directory."
[dir]
(.isDirectory (file (str "resources/templates/" dir))))
(.isDirectory (io/file (str "resources/templates/" dir))))
(defn- markup-entries [post-root page-root]
(let [entries (for [mu (m/markups)
@ -427,7 +431,7 @@
[{:keys [post-root page-root] :as config}]
(let [folders (->> (markup-entries post-root page-root)
(filter template-dir?))]
(copy-resources
(cryogen-io/copy-resources
(merge config
{:resources folders
:ignored-files (map #(re-pattern-from-ext (m/ext %)) (m/markups))}))))
@ -437,7 +441,7 @@
[]
(try
(let [config (-> "templates/config.edn"
get-resource
cryogen-io/get-resource
slurp
read-string
(update-in [:blog-prefix] (fnil str ""))
@ -464,7 +468,8 @@
"Generates all the html and copies over resources specified in the config"
[]
(println (green "compiling assets..."))
(let [{:keys [^String site-url blog-prefix rss-name recent-posts sass-src sass-dest sass-path compass-path keep-files ignored-files previews? clean-urls? debug? author-root-uri] :as config} (read-config)
(let [{:keys [^String site-url blog-prefix rss-name recent-posts sass-dest keep-files ignored-files previews? author-root-uri theme]
:as config} (read-config)
posts (add-prev-next (read-posts config))
pages (add-prev-next (read-pages config))
home-pages (filter #(boolean (:home? %)) pages)
@ -488,18 +493,18 @@
:archives-uri (page-uri "archives.html" config)
:index-uri (page-uri "index.html" config)
:tags-uri (page-uri "tags.html" config)
:rss-uri (path "/" blog-prefix rss-name)
: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)
:theme-path (str "file:resources/templates/themes/" (:theme config))})]
:theme-path (str "file:resources/templates/themes/" theme)})]
(println (blue "debug info"))
(println "\t-->" (cyan navbar-pages))
(set-custom-resource-path! (:theme-path params))
(wipe-public-folder keep-files)
(cryogen-io/wipe-public-folder keep-files)
(println (blue "copying theme resources"))
(copy-resources-from-theme config)
(cryogen-io/copy-resources-from-theme config)
(println (blue "copying resources"))
(copy-resources config)
(cryogen-io/copy-resources config)
(copy-resources-from-markup-folders config)
(compile-pages params pages-without-home)
(compile-posts params posts)
@ -514,19 +519,16 @@
(println (blue "generating authors views"))
(compile-authors params posts))
(println (blue "generating site map"))
(create-file (path "/" blog-prefix "sitemap.xml") (sitemap/generate site-url ignored-files))
(cryogen-io/create-file (cryogen-io/path "/" blog-prefix "sitemap.xml") (sitemap/generate site-url ignored-files))
(println (blue "generating main rss"))
(create-file (path "/" blog-prefix rss-name) (rss/make-channel config posts))
(cryogen-io/create-file (cryogen-io/path "/" blog-prefix rss-name) (rss/make-channel config posts))
(println (blue "generating filtered rss"))
(rss/make-filtered-channels config posts-by-tag)
(println (blue "compiling sass"))
(sass/compile-sass->css!
{:path-sass sass-path
:path-compass compass-path
:src-sass sass-src
:dest-sass (path ".." "public" blog-prefix sass-dest)
:ignored-files ignored-files
:base-dir "resources/templates/"})))
(merge (select-keys config [:sass-path :compass-path :sass-src :ignored-files])
{:dest-sass (cryogen-io/path ".." "public" blog-prefix sass-dest)
:base-dir "resources/templates/"}))))
(defn compile-assets-timed []
(time

View file

@ -1,37 +0,0 @@
(ns cryogen-core.github
(:require [cheshire.core :as json])
(:import (org.apache.commons.codec.binary Base64 StringUtils)))
(defn get-gist [gist-uri]
(let [gist-id (last (clojure.string/split gist-uri #"/+")) ;;just need id for git api
gist-resp (try (slurp (str "https://api.github.com/gists/" gist-id))
(catch Exception e {:error (.getMessage e)}))]
(when-not (:error gist-resp)
(if-let [gist (-> (json/parse-string gist-resp)
(get "files")
first ;;todo: optionally get all gist files?
val)]
{:content (get gist "content")
:language (get gist "language")
:name (get gist "filename")
:id gist-id}))))
(defn get-src [git-file]
(let [git-re (re-find #"github.com/(.*)/blob/(.+?)/(.+)" git-file) ;;want second and last now (user/repo,file) for git api
git-res (str "https://api.github.com/repos/" (second git-re) "/contents/" (last git-re))
git-resp (try (slurp git-res)
(catch Exception e {:error (.getMessage e)}))]
(when-not (:error git-resp)
(if-let [git-src (json/parse-string git-resp)]
{:content (String. ^bytes (Base64/decodeBase64 ^String (get git-src "content")) "UTF-8")
:name (get git-src "name")
:uri (get (get git-src "_links") "html")}))))
(defn get-gits-ex []
[(get-gist "https://gist.github.com/viperscape/cec68f0791687f5959f1")
(get-src "https://github.com/viperscape/kuroshio/blob/master/examples/pubsub.clj")])
;(prn (get-gits-ex))

View file

@ -1,6 +1,5 @@
(ns cryogen-core.markup
(:require [clojure.string :as s])
(:import java.util.Collections))
(:require [clojure.string :as s]))
(defonce markup-registry (atom []))
@ -18,7 +17,7 @@
[blog-prefix text]
(if (s/blank? blog-prefix)
text
(clojure.string/replace text #"href=.?/|src=.?/" #(str (subs % 0 (dec (count %))) blog-prefix "/"))))
(s/replace text #"href=.?/|src=.?/" #(str (subs % 0 (dec (count %))) blog-prefix "/"))))
(defn markups
"Return a vector of Markup implementations. This is the primary entry point

View file

@ -1,6 +1,5 @@
(ns cryogen-core.plugins
(:require [cryogen-core.compiler :refer [compile-assets-timed]]
[clojure.edn :as edn]
(:require [clojure.edn :as edn]
[clojure.string :as s]
[text-decoration.core :refer :all]))

View file

@ -1,7 +1,7 @@
(ns cryogen-core.rss
(:require [clj-rss.core :as rss]
[text-decoration.core :refer :all]
[cryogen-core.io :refer [create-file path]])
[cryogen-core.io :as cryogen-io])
(:import java.util.Date))
@ -31,6 +31,6 @@
(defn make-filtered-channels [{:keys [rss-filters blog-prefix] :as config} posts-by-tag]
(doseq [filter rss-filters]
(let [uri (path "/" blog-prefix (str (name filter) ".xml"))]
(let [uri (cryogen-io/path "/" blog-prefix (str (name filter) ".xml"))]
(println "\t-->" (cyan uri))
(create-file uri (make-channel config (get posts-by-tag filter))))))
(cryogen-io/create-file uri (make-channel config (get posts-by-tag filter))))))

View file

@ -1,8 +1,8 @@
(ns cryogen-core.sass
(:require [clojure.java.shell :as shell]
[clojure.java.io :as io]
(:require [clojure.java.io :as io]
[clojure.java.shell :as shell]
[text-decoration.core :refer :all]
[cryogen-core.io :refer [ignore match-re-filter]]))
[cryogen-core.io :as cryogen-io]))
(defmacro sh
[& args]
@ -11,14 +11,14 @@
(defn sass-installed?
"Checks for the installation of Sass."
[path-sass]
(= 0 (:exit (sh path-sass "--version"))))
[sass-path]
(zero? (:exit (sh sass-path "--version"))))
(defn compass-installed?
"Checks for the installation of Compass."
[path-compass]
[compass-path]
(try
(= 0 (:exit (sh path-compass "--version")))
(zero? (:exit (sh compass-path "--version")))
(catch java.io.IOException _
false)))
@ -26,49 +26,36 @@
"Given a Diretory, gets files, Filtered to those having scss or sass
extention. Ignores files matching any ignored regexps."
[base-dir dir ignored-files]
(let [^java.io.FilenameFilter filename-filter (match-re-filter #"(?i:s[ca]ss$)")]
(let [^java.io.FilenameFilter filename-filter (cryogen-io/match-re-filter #"(?i:s[ca]ss$)")]
(->> (.listFiles (io/file base-dir dir) filename-filter)
(filter #(not (.isDirectory ^java.io.File %)))
(filter (ignore ignored-files))
(filter (cryogen-io/ignore ignored-files))
(map #(.getName ^java.io.File %)))))
(defn compile-sass-file!
"Given a sass file which might be in src-sass directory,
output the resulting css in dest-sass. All error handling is
"Given a sass file which might be in sass-src directory,
output the resulting css in sass-dest. All error handling is
done by sh / launching the sass command."
[{:keys [src-sass
dest-sass
path-sass
path-compass
base-dir]}]
[{:keys [sass-src sass-dest sass-path compass-path base-dir]}]
(shell/with-sh-dir base-dir
(if (compass-installed? path-compass)
(sh path-sass "--compass" "--update" (str src-sass ":" dest-sass))
(sh path-sass "--update" (str src-sass ":" dest-sass)))))
(if (compass-installed? compass-path)
(sh sass-path "--compass" "--update" (str sass-src ":" sass-dest))
(sh sass-path "--update" (str sass-src ":" sass-dest)))))
(defn compile-sass->css!
"Given a directory src-sass, looks for all sass files and compiles them into
dest-sass. Prompts you to install sass if he finds sass files and can't find
"Given a directory sass-src, looks for all sass files and compiles them into
sass-dest. Prompts you to install sass if he finds sass files and can't find
the command. Shows you any problems it comes across when compiling. "
[{:keys [src-sass
dest-sass
path-sass
ignored-files
base-dir] :as opts}]
(when-let [sass-files (seq (find-sass-files base-dir src-sass ignored-files))]
(if (sass-installed? path-sass)
;; I found sass files,
;; If sass is installed
[{:keys [sass-src sass-dest sass-path ignored-files base-dir] :as opts}]
(when (seq (find-sass-files base-dir sass-src ignored-files))
(if (sass-installed? sass-path)
(do
(println "\t" (cyan src-sass) "-->" (cyan dest-sass))
(println "\t" (cyan sass-src) "-->" (cyan sass-dest))
(let [result (compile-sass-file! opts)]
(if (zero? (:exit result))
;; no problems in sass compilation
(println "Successfully compiled sass files")
;; else I show the error
(println (red (:err result))
(red (:out result))))))
;; Else I prompt to install Sass
(println "Sass seems not to be installed, but you have scss / sass files in "
src-sass
sass-src
" - You might want to install it here: sass-lang.com"))))

View file

@ -1,6 +1,6 @@
(ns cryogen-core.sitemap
(:require [clojure.xml :refer [emit]]
[cryogen-core.io :refer [get-resource find-assets]])
[cryogen-core.io :as cryogen-io])
(:import java.util.Date))
;;generate sitemaps using the sitemap spec
@ -19,7 +19,7 @@
{:tag :urlset
:attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
:content
(for [^java.io.File f (find-assets "public" ".html" ignored-files)]
(for [^java.io.File f (cryogen-io/find-assets "public" ".html" ignored-files)]
{:tag :url
:content
[{:tag :loc

View file

@ -1,20 +1,20 @@
(ns cryogen-core.watcher
(:require [clojure.java.io :refer [file]]
[cryogen-core.io :refer [ignore]]
[pandect.algo.md5 :refer [md5]]
(:require [clojure.java.io :as io]
[clojure.set :as set]
[hawk.core :as hawk]
[clojure.set :as set]))
[pandect.algo.md5 :as md5]
[cryogen-core.io :as cryogen-io]))
(defn get-assets [path ignored-files]
(->> path
file
io/file
file-seq
(filter #(not (.isDirectory ^java.io.File %)))
(filter (ignore ignored-files))))
(filter (cryogen-io/ignore ignored-files))))
(defn checksums [path ignored-files]
(let [files (get-assets path ignored-files)]
(zipmap (map md5 files) files)))
(zipmap (map md5/md5 files) files)))
(defn find-changes [old-sums new-sums]
(let [old-sum-set (-> old-sums keys set)

View file

@ -1,9 +1,8 @@
(ns cryogen-core.compiler-test
(:require [clojure.test :refer :all]
[me.raynes.fs :as fs]
[cryogen-core.compiler :refer :all]
[cryogen-core.io :refer [path]]
[cryogen-core.markup :as m]
[me.raynes.fs :as fs])
[cryogen-core.markup :as m])
(:import [java.io File]))
; Test that the content-until-more-marker return nil or correct html text.

View file

@ -1,7 +1,6 @@
(ns cryogen-core.toc-test
(:require [clojure.test :refer :all]
[clojure.string :refer [join]]
[clojure.zip :as z]
[clojure.string :as s]
[crouton.html :as html]
[hiccup.core :as hiccup]
[cryogen-core.toc :refer :all]))
@ -9,8 +8,6 @@
; Reimport private functions
(def get-headings #'cryogen-core.toc/get-headings)
(def make-toc-entry #'cryogen-core.toc/make-toc-entry)
(def zip-toc-tree-to-insertion-point #'cryogen-core.toc/zip-toc-tree-to-insertion-point)
(def insert-toc-tree-entry #'cryogen-core.toc/insert-toc-tree-entry)
(def build-toc-tree #'cryogen-core.toc/build-toc-tree)
(def build-toc #'cryogen-core.toc/build-toc)
@ -46,11 +43,13 @@
(deftest test-build-toc
(let [simplest-header [:div [:h2 [:a {:name "test"}] "Test"]]
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"]]
closing-header-larger-than-opening-2
[:div [:h2 [:a {:name "starting_low"}]
"Starting Low"]
@ -61,38 +60,35 @@
[:h2 [:a {:name "to_the_top"}]
"To the top"]]]
(is (= [:ol.content (seq [[:li [:a {:href "#test"} "Test"]]])]
(-> simplest-header parse-to-headings build-toc-tree
(build-toc :ol))))
(is (nil?
(-> no-headers parse-to-headings build-toc-tree
(-> simplest-header
(parse-to-headings)
(build-toc-tree)
(build-toc :ol))))
(is (-> no-headers
(parse-to-headings)
(build-toc-tree)
(build-toc :ol)
(nil?)))
(is (= [:ol.content (seq [[:li [:a {:href "#starting_low"} "Starting Low"]]
[:li [:a {:href "#finishing_high"} "Finishing High"]]])]
(-> closing-header-larger-than-opening-1
parse-to-headings
build-toc-tree
(parse-to-headings)
(build-toc-tree)
(build-toc :ol)))
"No outer header should be less indented than the first header tag.")
(is (= [:ul.content
(seq [
(seq [
[:li [:a {:href "#starting_low"} "Starting Low"]]
(seq [(seq [[:li [:a {:href "#starting_low"} "Starting Low"]]
[:ul
(seq [
[:li [:a {:href "#jumping_in"} "Jumping Right In"]]
[:li [:a {:href "#pulling_back"} "But then pull back"]]
])
] ])
[:li [:a {:href "#to_the_top"} "To the top"]]
])]
(seq [[:li [:a {:href "#jumping_in"} "Jumping Right In"]]
[:li [:a {:href "#pulling_back"} "But then pull back"]]])]])
[:li [:a {:href "#to_the_top"} "To the top"]]])]
(-> closing-header-larger-than-opening-2
parse-to-headings
build-toc-tree
(parse-to-headings)
(build-toc-tree)
(build-toc :ul)))
(join "" ["Inner headers can be more indented, "
(s/join "" ["Inner headers can be more indented, "
"but outer headers cannot be less indented "
"than the original header."]))
))
"than the original header."]))))
(deftest test-generate-toc