Start on docs and demos

This commit is contained in:
Dan Holmsand 2014-01-02 14:04:30 +01:00
parent cb60a6094f
commit 454a7af31d
3 changed files with 65 additions and 0 deletions

58
test/demo.cljs Normal file
View File

@ -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"]])

5
test/demoutil.clj Normal file
View File

@ -0,0 +1,5 @@
(ns demoutil
(:require [clojure.java.io :as io]))
(defmacro get-source [srcfile]
(slurp (io/resource srcfile)))

View File

@ -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]]