Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/kioo/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[clojure.string :as string]
[kioo.html-parser :as parser]
[hickory.core :as hickory]
[kioo.common :as common]
[clojure.java.io :as io]))

(declare compile component*)
Expand Down Expand Up @@ -91,9 +92,18 @@
(map? sel) {}
:else []) sel))

(defn apply-and-attach-transforms [node sel trans]
(cond
(vector? trans) (recur node sel {`(common/content) (list* trans)})
(not (map? trans)) (recur node sel {`identity trans})
:else (let [[compile-time runtime] (first trans)]
(-> node
(at (eval-selector sel) (eval compile-time))
(at (eval-selector sel) (attach-transform runtime))))))

(defn map-trans [node trans-lst]
(reduce (fn [node [sel trans]]
(at node (eval-selector sel) (attach-transform trans)))
(apply-and-attach-transforms node sel trans))
node
trans-lst))

Expand Down
8 changes: 8 additions & 0 deletions test/kioo/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
(let [comp (component "simple-div.html"
{[:div] (content "success")})]
(is (= "<div id=\"tmp\">success</div>" (render-dom comp)))))
(testing "compile-time content replace"
(let [comp (component "simple-div.html"
{[:div] {(kioo.common/content "success") (wrap :section {})}})]
(is (= "<section><div id=\"tmp\">success</div></section>" (render-dom comp)))))
(testing "compile-time empty content sugar"
(let [comp (component "simple-div.html"
{[:div] [wrap :section {}]})]
(is (= "<section><div id=\"tmp\"></div></section>" (render-dom comp)))))
(testing "first-of-type naked symbol"
(let [comp (component "list.html" [:ul [:li first-of-type]] {})]
(is (= "<li>1</li>" (render-dom comp)))))
Expand Down