-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Hiccup macro which uses always the same output mode
Why: - Hiccup generates 8 code paths every time the hiccup2.core/html macro is used, one for each combination of the output formats (html, xhtml, xml, sgml) and string escape mode (true, false). In practice, an application uses only one or two of them, and the rest is dead code. - This fixes the problem of exponential amount of generated code in some situations. See weavejester/hiccup#210
- Loading branch information
Showing
22 changed files
with
71 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
;; Copyright © 2015-2024 Esko Luontola | ||
;; This software is released under the Apache License 2.0. | ||
;; The license text is at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
(ns territory-bro.ui.hiccup | ||
(:require [hiccup.compiler :as compiler] | ||
[hiccup.util :as util])) | ||
|
||
(defmacro html [& content] | ||
(binding [util/*html-mode* :html ; compile time options | ||
util/*escape-strings?* true] | ||
`(binding [util/*html-mode* :html ; runtime options | ||
util/*escape-strings?* true] | ||
(util/raw-string ~(apply compiler/compile-html content))))) | ||
|
||
(def raw util/raw-string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
;; Copyright © 2015-2024 Esko Luontola | ||
;; This software is released under the Apache License 2.0. | ||
;; The license text is at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
(ns territory-bro.ui.hiccup-test | ||
(:require [clojure.test :refer :all] | ||
[territory-bro.ui.hiccup :as h]) | ||
(:import (hiccup.util RawString))) | ||
|
||
(deftest html-test | ||
(is (instance? RawString (h/html))) | ||
(is (= "" (str (h/html)))) | ||
|
||
(testing "produces HTML 5" | ||
(testing "at compile time" | ||
(is (= "<p flag>foo</p>" (str (h/html [:p {:flag true} "foo"])))) | ||
(is (= "<br>" (str (h/html [:br]))))) | ||
|
||
(testing "at runtime" | ||
(is (= "<p flag>foo</p>" (str (h/html (identity [:p {:flag true} "foo"]))))) | ||
(is (= "<br>" (str (h/html (identity [:br]))))))) | ||
|
||
(testing "escapes text" | ||
(testing "at compile time" | ||
(is (= "<p><script></p>" (str (h/html [:p "<script>"]))))) | ||
|
||
(testing "at runtime" | ||
(is (= "<p><script></p>" (str (h/html [:p (identity "<script>")]))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters