Skip to content

Commit 7e2561b

Browse files
authored
Fix #3: allow dynamic attribute value (#11)
1 parent 8635f7f commit 7e2561b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Unreleased changes are available via `io.github.borkdude/html {:git/sha "..."}`
44

55
[html](https://github.com/borkdude/html): Produce HTML from hiccup in Clojure and ClojureScript
66

7+
## 0.1.2
8+
9+
- Fix [#3](https://github.com/borkdude/html/issues/3): allow dynamic attribute value: `(html [:a {:a (+ 1 2 3)}])`
10+
711
## 0.1.1
812

913
- Fix [#7](https://github.com/borkdude/html/issues/7): boolean HTML attributes

src/borkdude/html.cljc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@
5050
(let [m (merge base-map m)]
5151
(->attrs opts m))))
5252

53+
(defn constant? [v]
54+
(not (seq? v)))
55+
5356
(defn- compile-attrs [opts m]
54-
(if (contains? m :&)
57+
(if (or (contains? m :&)
58+
(not (every? constant? (vals m))))
5559
`(->attrs ~opts ~(get m :&) ~(dissoc m :&))
5660
(->attrs opts m)))
5761

test/borkdude/html_test.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
"<input checked=\"true\"></input>"
7575
(xml [:input {:checked true}])
7676

77-
)
77+
"<a href=\"http://dude\"></a>"
78+
(html [:a {:href (str "http://" "dude")}]))
7879
)
7980

8081
(comment

0 commit comments

Comments
 (0)