diff --git a/test/demo.cljs b/test/demo.cljs new file mode 100644 index 0000000..9e8f8b2 --- /dev/null +++ b/test/demo.cljs @@ -0,0 +1,58 @@ +(ns demo + (:require [cloact.core :as cloact :refer [atom]] + [clojure.string :as string]) + (:require-macros [demoutil :refer [get-source]] + [cloact.debug :refer [dbg println]])) + +(def demosrc (get-source "demo.cljs")) + +(defn src-parts [src] + (->> + (string/split src #"\n\(") + rest + (map #(str "(" %)))) + +(defn src-defs [parts] + (into {} (for [x parts] + [(keyword (nth (string/split x #"\s+") 1)) + x]))) + +(def srcmap + (-> "demo.cljs" + get-source + src-parts + src-defs)) + +(def nssrc + "(ns example + (:require [cloact.core :as cloact :refer [atom]]) +") + +(defn src-for-names [names] + (let [defs (merge srcmap {:ns nssrc})] + (string/join "\n" + (map #(% defs) names)))) + +(defn src-for [{:keys [defs]}] + [:pre (src-for-names defs)]) + +(defn simple-component [] + [:div + [:h3 "I am a component!"] + [:p.someclass + "I have " [:strong "bold"] + [:span {:style {:color "red"}} " and red "] + "text."]]) + +(defn demo-simple [] + [:div + [:h2 "This is a simple component"] + [simple-component] + [:p "Source:" + [src-for {:defs [:ns :simple-component]}]]]) + +(defn demo [] + [:div + [:h1 "This will become a demo"] + [demo-simple] + [:p "WIP"]]) diff --git a/test/demoutil.clj b/test/demoutil.clj new file mode 100644 index 0000000..d015b3c --- /dev/null +++ b/test/demoutil.clj @@ -0,0 +1,5 @@ +(ns demoutil + (:require [clojure.java.io :as io])) + +(defmacro get-source [srcfile] + (slurp (io/resource srcfile))) diff --git a/test/runtests.cljs b/test/runtests.cljs index 6e0a296..7c69a69 100644 --- a/test/runtests.cljs +++ b/test/runtests.cljs @@ -5,6 +5,7 @@ [cloact.debug :refer [dbg println]]) (:require [cemerick.cljs.test :as t] [cloact.core :as cloact :refer [atom]] + [demo :as demo] [todomvc :as todomvc])) (defn ^:export console-print [x] @@ -36,6 +37,7 @@ (defn examples [] (let [p {:style {:color "#aaa"}}] [:div.runtests + [demo/demo] [:div [:h2 p "Test results:"] [test-output]]