Skip to content

Commit

Permalink
Allow tag keyword class names combined with non-literal class names
Browse files Browse the repository at this point in the history
Generate the correct class attribute of an element when the class names
are both present as:

- part of the element keyword (using the dot notation)
- a non-literal value of the :class key in the attribute map
  (specifically when using a symbol as the value).

Fixes issue weavejester#143
  • Loading branch information
Pieter van Prooijen committed Apr 17, 2018
1 parent 846d7ef commit d36e5e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/hiccup/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
(cond
(nil? class) classes
(string? class) (str classes " " class)
(symbol? class) (list `str classes " " class)
:else (str classes " " (str/join " " class))))

(defn- merge-attributes [map-attrs id classes]
Expand Down
6 changes: 5 additions & 1 deletion test/hiccup/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@
(let [times-called (atom 0)
foo #(swap! times-called inc)]
(html [:div (foo)])
(is (= @times-called 1)))))
(is (= @times-called 1))))
(testing "defer evaluation of non-literal class names when combined with tag classes"
(let [class-local-var "class-foo class-bar"]
(is (= (html [:div.test {:class class-local-var}])
"<div class=\"test class-foo class-bar\"></div>")))))

(deftest render-modes
(testing "closed tag"
Expand Down

0 comments on commit d36e5e4

Please sign in to comment.