Back

defhtml (clj)

(source)

macro

(defhtml name & fdecl)
Define a function, but wrap its output in an implicit [[hiccup.core/html]] macro.

Examples

hiccup
(ns hiccup.def_test
  (:require [clojure.test :refer :all]
            [hiccup.def :refer :all]))

(deftest test-defhtml
  (testing "basic html function"
    (defhtml basic-fn [x] [:span x])
    (is (= (str (basic-fn "foo")) "<span>foo</span>")))
  (testing "html function with overloads"
    (defhtml overloaded-fn
      ([x] [:span x])
      ([x y] [:span x [:div y]]))
    (is (= (str (overloaded-fn "foo")) "<span>foo</span>"))
    (is (= (str (overloaded-fn "foo" "bar"))
           "<span>foo<div>bar</div></span>"))))
weavejester/hiccup
(ns hiccup.def_test
  (:require [clojure.test :refer :all]
            [hiccup.def :refer :all]))

(deftest test-defhtml
  (testing "basic html function"
    (defhtml basic-fn [x] [:span x])
    (is (= (str (basic-fn "foo")) "<span>foo</span>")))
  (testing "html function with overloads"
    (defhtml overloaded-fn
      ([x] [:span x])
      ([x y] [:span x [:div y]]))
    (is (= (str (overloaded-fn "foo")) "<span>foo</span>"))
    (is (= (str (overloaded-fn "foo" "bar"))
           "<span>foo<div>bar</div></span>"))))