Skip to content

Commit

Permalink
Experimental: add ^:as-html support
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Feb 6, 2014
1 parent e8b108e commit 44dc21f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

(defproject reagent "0.3.0"
(defproject com.taoensso.forks/reagent "0.3.0"
:url "http://github.com/holmsand/reagent"
:license {:name "MIT"}
:description "A simple ClojureScript interface to React"
Expand Down
35 changes: 31 additions & 4 deletions src/reagent/impl/template.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,44 @@
(let [[tag props] v
hasmap (map? props)
first-child (if (or hasmap (nil? props)) 2 1)
children (if (> (count v) first-child)
(subvec v first-child))
c (as-class tag)
jsprops (js-obj cljs-props (if hasmap props)
cljs-children (if (> (count v) first-child)
(subvec v first-child))
cljs-level level)]
__html (when (:as-html (meta v)) (apply str children))
jsprops
(js-obj cljs-props
(cond
(and hasmap __html)
(assoc props :dangerouslySetInnerHTML {:__html __html})

hasmap props
__html {:dangerouslySetInnerHTML {:__html __html}})

cljs-children (when-not __html children)
cljs-level level)]
(when hasmap
(let [key (:key props)]
(when-not (nil? key)
(aset jsprops "key" key))))
(c jsprops)))

(comment
(defn vec-to-comp [v level]
(assert (pos? (count v)))
(let [[tag props] v
hasmap (map? props)
first-child (if (or hasmap (nil? props)) 2 1)
c (as-class tag)
jsprops (js-obj cljs-props (if hasmap props)
cljs-children (if (> (count v) first-child)
(subvec v first-child))
cljs-level level)]
(when hasmap
(let [key (:key props)]
(when-not (nil? key)
(aset jsprops "key" key))))
(c jsprops))))

(defn as-component
([x] (as-component x 0))
([x level]
Expand Down

0 comments on commit 44dc21f

Please sign in to comment.