Add a couple of asserts, and a link

This commit is contained in:
Dan Holmsand 2014-01-05 13:29:22 +01:00
parent 2c2dca026c
commit 62322c474f
3 changed files with 14 additions and 8 deletions

View File

@ -208,6 +208,7 @@
(defn create-class
[body]
(assert (map? body))
(let [spec (cljsify body)
res (.createClass React spec)
f (fn [& args]

View File

@ -32,7 +32,8 @@
[id class'])]))
(def attr-aliases {"class" "className"
"for" "htmlFor"})
"for" "htmlFor"
"charset" "charSet"})
(defn undash-prop-name [n]
(let [undashed (dash-to-camel n)]
@ -114,6 +115,7 @@
(declare wrapper)
(defn fn-to-class [f]
(assert (fn? f))
(let [spec (meta f)
withrender (merge spec {:render f})
res (cloact.core/create-class withrender)]
@ -130,6 +132,7 @@
(fn-to-class x)))))
(defn vec-to-comp [v]
(assert (pos? (count v)))
(let [[tag props] v
c (.-cljsReactClass (as-class tag))
obj (js-obj)]

View File

@ -38,11 +38,12 @@
"range" "nil\\?" "int" "or" "->" "%"])
(defn syntaxify [src]
;; quick and (very) dirty syntax coloring
(let [sep "\\][(){} \\t\\n"
str-p "\"[^\"]*\""
keyw-p (str ":[^" sep "]+")
res-p (string/join "|" (map #(str "\\b" % "(?=[" sep "])") builtins))
any-p (str "[^" sep "]+|.|\\n") ;; ".|\\n"
any-p (str "[^" sep "]+|.|\\n")
patt (re-pattern (str "("
(string/join ")|(" [str-p keyw-p res-p any-p])
")"))]
@ -54,18 +55,18 @@
res [:b res]
:else s)))))
(defn src-for [{:keys [defs]}]
(defn src-for [defs]
[:pre (syntaxify (src-for-names defs))])
(defn demo-component [props]
(defn demo-component [{:keys [comp defs]}]
[:div
(when (:comp props)
(when comp
[:div.demo-example
[:h3.demo-heading "Example"]
[(:comp props)]])
[comp]])
[:div.demo-source
[:h3.demo-heading "Source"]
[src-for props]]])
(src-for defs)]])
(defn simple-component []
[:div
@ -165,7 +166,8 @@
[:div
[:h2 "Introduction to Cloact"]
[:p "Cloact provides a minimalistic interface between "
[:p [:a {:href "https://github.com/holmsand/cloact"} "Cloact"]
" provides a minimalistic interface between "
[:a {:href "https://github.com/clojure/clojurescript"} "ClojureScript"]
" and " [:a {:href "http://facebook.github.io/react/"} "React"]
". It allows you to define React components using nothing but