From 4a01b10d279bbacb692899e7b2219ecd849d50c6 Mon Sep 17 00:00:00 2001 From: Pepijn de Vos Date: Wed, 22 Sep 2010 11:41:39 +0200 Subject: [PATCH] adding Enlive actions for idempotent templates --- src/utterson/compile.clj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/utterson/compile.clj b/src/utterson/compile.clj index 178ed09..1de24ab 100644 --- a/src/utterson/compile.clj +++ b/src/utterson/compile.clj @@ -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)])) + (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,