From 712189f4e8f812a27bf862a86890ca0b1a258fb7 Mon Sep 17 00:00:00 2001 From: Pieter van Prooijen Date: Sun, 15 Apr 2018 13:44:55 +0200 Subject: [PATCH] Fixes #143 tag classes combined with non-literal class attributes Allow for the combination of classes in the tag keyword and non-literal class attributes by evaluating the latter at runtime. --- src/hiccup/compiler.clj | 1 + test/hiccup/core_test.clj | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/hiccup/compiler.clj b/src/hiccup/compiler.clj index 791c11c..51d4527 100644 --- a/src/hiccup/compiler.clj +++ b/src/hiccup/compiler.clj @@ -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] diff --git a/test/hiccup/core_test.clj b/test/hiccup/core_test.clj index 3f5cc6d..d6df2b9 100644 --- a/test/hiccup/core_test.clj +++ b/test/hiccup/core_test.clj @@ -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}]) + "
"))))) (deftest render-modes (testing "closed tag"