Back
raw (clj)
(source)variable
Short alias for [[hiccup.util/raw-string]].
Examples
hiccup
(ns hiccup2.core_test
(:require [clojure.test :refer :all]
[hiccup2.core :refer :all]
[hiccup.util :as util]))
(deftest return-types
(testing "html returns a RawString"
(is (util/raw-string? (html [:div]))))
(testing "converting to string"
(= (str (html [:div])) "<div></div>")))
(deftest auto-escaping
(testing "literals"
(is (= (str (html "<>")) "<>"))
(is (= (str (html :<>)) "<>"))
(is (= (str (html ^String (str "<>"))) "<>"))
(is (= (str (html {} {"<a>" "<b>"})) "{"<a>" "<b>"}"))
(is (= (str (html #{"<>"})) "#{"<>"}"))
(is (= (str (html 1)) "1"))
(is (= (str (html ^Number (+ 1 1))) "2")))
(testing "non-literals"
(is (= (str (html (list [:p "<foo>"] [:p "<bar>"])))
"<p><foo></p><p><bar></p>"))
(is (= (str (html ((constantly "<foo>")))) "<foo>"))
(is (= (let [x "<foo>"] (str (html x))) "<foo>")))
(testing "optimized forms"
(is (= (str (html (if true :<foo> :<bar>))) "<foo>"))
(is (= (str (html (for [x [:<foo>]] x))) "<foo>")))
(testing "elements"
(is (= (str (html [:p "<>"])) "<p><></p>"))
(is (= (str (html [:p :<>])) "<p><></p>"))
(is (= (str (html [:p {} {"<foo>" "<bar>"}]))
"<p>{"<foo>" "<bar>"}</p>"))
(is (= (str (html [:p {} #{"<foo>"}]))
"<p>#{"<foo>"}</p>"))
(is (= (str (html [:p {:class "<\">"}]))
"<p class=\"<">\"></p>"))
(is (= (str (html [:p {:class ["<\">"]}]))
"<p class=\"<">\"></p>"))
(is (= (str (html [:ul [:li "<foo>"]]))
"<ul><li><foo></li></ul>")))
(testing "raw strings"
(is (= (str (html (util/raw-string "<foo>"))) "<foo>"))
(is (= (str (html [:p (util/raw-string "<foo>")])) "<p><foo></p>"))
(is (= (str (html (html [:p "<>"]))) "<p><></p>"))
(is (= (str (html [:ul (html [:li "<>"])])) "<ul><li><></li></ul>"))))
(deftest html-escaping
(testing "precompilation"
(is (= (str (html {:escape-strings? true} [:p "<>"])) "<p><></p>"))
(is (= (str (html {:escape-strings? false} [:p "<>"])) "<p><></p>")))
(testing "dynamic generation"
(let [x [:p "<>"]]
(is (= (str (html {:escape-strings? true} x)) "<p><></p>"))
(is (= (str (html {:escape-strings? false} x)) "<p><></p>"))))
(testing "attributes"
(is (= (str (html {:escape-strings? true} [:p {:class "<>"}]))
"<p class=\"<>\"></p>"))
(is (= (str (html {:escape-strings? false} [:p {:class "<>"}]))
"<p class=\"<>\"></p>")))
(testing "raw strings"
(is (= (str (html {:escape-strings? true} [:p (util/raw-string "<>")]))
"<p><></p>"))
(is (= (str (html {:escape-strings? false} [:p (util/raw-string "<>")]))
"<p><></p>"))
(is (= (str (html {:escape-strings? true} [:p (raw "<>")]))
"<p><></p>"))
(is (= (str (html {:escape-strings? false} [:p (raw "<>")]))
"<p><></p>"))))
coast-framework/coast
(ns coast
(:require [coast.potemkin.namespaces :as namespaces]
[hiccup2.core]
[coast.db]
[coast.db.connection]
[coast.theta]
[coast.env]
[coast.time2]
[coast.components]
[coast.responses]
[coast.utils]
[coast.error]
[coast.router]
[coast.validation])
(:refer-clojure :exclude [update]))
[hiccup2.core
raw
html])