Closed JulianBirch closed 10 years ago
I can think of several ways to support this. I will try to sketch something out later today.
One caveat is the HTML would be pulled in at compile time.
Definitely wouldn't work for me, sadly. I see that JSX supports raw HTML, but I'm not sure how it achieves it or whether Om has abstracted away the feature that would allow you to do that.
http://facebook.github.io/react/docs/jsx-gotchas.html
The use case, incidentally, is a CMS or comment system.
Thanks for looking at it.
I think there is a way to do this but it requires using Kioo with another library. @r0man's sablono will interpret an xml clojure data structure [:tag {:attr1 ""} "content"] into react nodes. You could create a remote call that returned the clojure xml representation to your app and use sablono to convert it into react nodes. This would allow you to use kioo for the page layout the structure around the comments but the comments themselves would be pushed in using sablono and cljs.reader.
(ns example
(:require [om.core :as om :include-macros true]
[kioo.core :as kioo include-macros]
[cljs.reader :as edn]
[sablono.core :as html :refer [html] :include-macros true]))
(defn comments-event-hander [app-cursor val]
;;do a remote call to get the
;;html as a string in clojure xml
;;[:tag {:attr1 "val1"} "content]
(remote-comment-call val #(om/update! app assoc :comments (edn/read-string %))))
(defn my-page [app-cursor]
(kioo/component "page-layout"
{[:#content] (content (:content app-cursor))
[:ul.comments] (content
(html (:comments app-cursor))
Looks like I might be able to do what I need just by setting a dangerouslySetInnerHTML
attribute on the enclosing DIV.
http://facebook.github.io/react/docs/special-non-dom-attributes.html
I'll let you know. :)
After thinking about this a bit more I think it can be done. If I get a change I will try to prototype something this weekend.
I add the html-content transform. You can also now pull kioo from clojars.
@JulianBirch I didn't state it before but the implementation of html-content works at run time and should eliminate the need to use dangerouslySetInnerHTML.
I'm looking to try using this, but have a requirement to include raw HTML from a database. I know it's listed as "won't be supported" but it would be quite useful in this case...