mirror of
https://github.com/status-im/reagent.git
synced 2025-01-24 19:00:43 +00:00
Start on docs and demos
This commit is contained in:
parent
cb60a6094f
commit
454a7af31d
58
test/demo.cljs
Normal file
58
test/demo.cljs
Normal 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
5
test/demoutil.clj
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
(ns demoutil
|
||||||
|
(:require [clojure.java.io :as io]))
|
||||||
|
|
||||||
|
(defmacro get-source [srcfile]
|
||||||
|
(slurp (io/resource srcfile)))
|
@ -5,6 +5,7 @@
|
|||||||
[cloact.debug :refer [dbg println]])
|
[cloact.debug :refer [dbg println]])
|
||||||
(:require [cemerick.cljs.test :as t]
|
(:require [cemerick.cljs.test :as t]
|
||||||
[cloact.core :as cloact :refer [atom]]
|
[cloact.core :as cloact :refer [atom]]
|
||||||
|
[demo :as demo]
|
||||||
[todomvc :as todomvc]))
|
[todomvc :as todomvc]))
|
||||||
|
|
||||||
(defn ^:export console-print [x]
|
(defn ^:export console-print [x]
|
||||||
@ -36,6 +37,7 @@
|
|||||||
(defn examples []
|
(defn examples []
|
||||||
(let [p {:style {:color "#aaa"}}]
|
(let [p {:style {:color "#aaa"}}]
|
||||||
[:div.runtests
|
[:div.runtests
|
||||||
|
[demo/demo]
|
||||||
[:div
|
[:div
|
||||||
[:h2 p "Test results:"]
|
[:h2 p "Test results:"]
|
||||||
[test-output]]
|
[test-output]]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user