Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding Enlive actions for idempotent templates
- Loading branch information
1 parent
e6afccc
commit 4a01b10
Showing
1 changed file
with
10 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,16 @@ | |
(io/file % "index.html")) | ||
(iterate #(.getParentFile %) html)))))) | ||
|
||
(defn action-or-update | ||
[action selector & nodes] | ||
(let [append (apply action nodes)] | ||
#(if (seq (en/select % [(en/has selector)])) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cgrand
|
||
(en/at % selector (apply en/substitute nodes)) | ||
(append %)))) | ||
|
||
(def append-or-update (partial action-or-update en/append)) | ||
|
||
(def prepend-or-update (partial action-or-update en/prepend)) | ||
|
||
(defmacro defgen | ||
"Like deftemplate in Enlive, | ||
|
(seq (en/select % [(en/has selector)])) should simply be ((en/has selector) %)