Created
December 7, 2016 06:31
-
-
Save alandipert/edab7814ec866ac8037ca790bb45bb55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(set-env! :source-paths #{"src"}) | |
(require '[boot.core :as core] | |
'[boot.util :as util] | |
'[clojure.java.io :as io]) | |
(core/deftask string-template | |
"Does the thing" | |
[f template-file VALUE str "Name of the template file to use" | |
t target-file VALUE str "Name of the output file to produce" | |
p placeholder VALUE str "The placeholder to recognize and replace" | |
c content VALUE str "Content to replace placeholder with"] | |
(core/with-pre-wrap [fs] | |
(let [tmpd (core/tmp-dir!)] | |
(if-let [template-file (some->> (core/input-files fs) | |
(core/by-name [template-file]) | |
first | |
core/tmp-file)] | |
(let [template-content (slurp template-file) | |
output-file (doto (io/file tmpd target-file) io/make-parents) | |
quoted-placeholder (java.util.regex.Pattern/quote placeholder)] | |
(spit output-file (.replaceAll template-content quoted-placeholder content)) | |
(-> fs | |
(core/add-resource tmpd) | |
commit!)) | |
(throw (ex-info "No template file found" {:opts *opts*})))))) | |
(defn route-content | |
[route] | |
(get {:veganism "foods most deloosh" | |
:consulting "making fat stacks" | |
:community "its all about the peeps" | |
:about-us "we rule"} | |
route | |
"something something yada yada")) | |
(core/deftask make-page | |
"Makes a page" | |
[r route VAL kw "Route to do it for" | |
t template-file NAME str "Name of the template file to use, default is template.html"] | |
(string-template :template-file (or template-file "template.html") | |
:target-file (str (name route) ".html") | |
:placeholder "{{CONTENT}}" | |
:content (route-content route))) | |
(core/deftask build | |
"Does every last thing" | |
[] | |
(comp (make-page :route :veganism) | |
(make-page :route :consulting) | |
(make-page :route :community) | |
(make-page :route :about-us))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment