Skip to content

Commit

Permalink
adding Enlive actions for idempotent templates
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijndevos committed Sep 22, 2010
1 parent e6afccc commit 4a01b10
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utterson/compile.clj
Expand Up @@ -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.

Copy link
@cgrand

cgrand Sep 22, 2010

(seq (en/select % [(en/has selector)])) should simply be ((en/has selector) %)

This comment has been minimized.

Copy link
@pepijndevos

pepijndevos Sep 22, 2010

Author Owner

That gives a NullPointerException for me.

This comment has been minimized.

Copy link
@cgrand

cgrand Sep 22, 2010

true, my bad, has is a selector step so the function it returns takes a zipper as its sole arg, not a node.

(seq (en/select % [(en/has selector)])) could be (seq (en/select % selector])) but it behaves slightly differently when the selector matches the current node.

(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,
Expand Down

0 comments on commit 4a01b10

Please sign in to comment.