Skip to content

Instantly share code, notes, and snippets.

@au-phiware
Last active November 26, 2017 22:32
Show Gist options
  • Save au-phiware/d2b9cba46f7f60cd1a76e9e94d94f23c to your computer and use it in GitHub Desktop.
Save au-phiware/d2b9cba46f7f60cd1a76e9e94d94f23c to your computer and use it in GitHub Desktop.
Server-side rendering of html entities.
out
node_modules
package.json
main.js
*.jar
.git
.gitignore
Dockerfile
README.md
.dockerignore
/out/
/node_modules/
package.json
/main.js
/*.jar

Steps to reproduce

  1. git clone https://gist.github.com/d2b9cba46f7f60cd1a76e9e94d94f23c.git reagent-html-entity && cd reagent-html-entity
  2. docker build -t reagent-html-entity .
  3. docker run reagent-html-entity

Expected outcome

java -cp cljs.jar:reagent-0.8.0-alpha2.jar:test.cljs clojure.main build.clj
node main.js
<p><i>Does not work: &amp;nbsp;</i>
<i>       Does work: &nbsp;</i>
<i>     Should work: &nbsp;</i></p>

Actual outcome

java -cp cljs.jar:reagent-0.8.0-alpha2.jar:test.cljs clojure.main build.clj
node main.js
<p><i>Does not work: &amp;nbsp;</i>
<i>       Does work: &nbsp;</i>
<i>     Should work: &amp;nbsp;</i></p>
(require 'cljs.build.api)
(cljs.build.api/build
"."
{:main 'test.core
:output-to "main.js"
:target :nodejs
:install-deps true
:npm-deps
{:react "15.6.2"
:react-dom "15.6.2"
:jsdom "11.4.0"
:jsdom-global "3.0.2"
:create-react-class "15.6.2"}})
FROM pgoudreau/docker-maven-node
CMD make
WORKDIR /usr/src/app
RUN apk add --virtual .build-dependencies --update wget ca-certificates bash \
&& wget -q "https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein" \
-O /usr/local/bin/lein \
&& chmod 0755 /usr/local/bin/lein \
&& git clone --shallow-since=2016-05-28T22:57:31Z https://github.com/clojure/clojurescript.git /usr/src/clojurescript \
&& cd /usr/src/clojurescript \
&& script/uberjar \
&& cp target/cljs.jar /usr/src/app \
&& git clone --depth 1 https://github.com/reagent-project/reagent.git /usr/src/reagent \
&& cd /usr/src/reagent \
&& lein install \
&& cp target/reagent-0.8.0-alpha2.jar /usr/src/app \
&& cd /usr/src/app \
&& rm -rf /usr/src/clojurescript /usr/src/reagent /usr/local/bin/lein /root/.* || true \
&& apk del .build-dependencies \
&& apk add make
COPY . /usr/src/app
.PHONY: repl clean all run
all: run
run: main.js
node main.js
main.js: reagent-0.8.0-alpha2.jar cljs.jar build.clj test.cljs
java -cp cljs.jar:reagent-0.8.0-alpha2.jar:test.cljs clojure.main build.clj
clean:
rm -rf out node_modules package.json main.js
repl:
java -cp cljs.jar:reagent-0.8.0-alpha2.jar clojure.main -e "(require 'cljs.repl 'cljs.repl.node) (cljs.repl/repl (cljs.repl.node/repl-env))"
(ns test.core
(:require
[cljs.nodejs :as nodejs]
[goog.string :refer [unescapeEntities]]
[reagent.dom.server :as dom]))
(nodejs/enable-util-print!)
(print
(dom/render-to-static-markup
[:p
[:i "Does not work: " "&nbsp;"] "\n"
[:i {:dangerouslySetInnerHTML {:__html " Does work: &nbsp;"}}] "\n"
[:i " Should work: " (unescapeEntities "&nbsp;")]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment