Generate demo page

This commit is contained in:
Dan Holmsand 2014-01-05 11:16:01 +01:00
parent 93759f6043
commit 2c2dca026c
8 changed files with 60 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
index.html
site/demo.js
target
pom.xml
.lein-repl-history

View File

@ -16,7 +16,7 @@ all: buildrun
run: openbrowser buildrun
leinbuild: setup
lein -o cljsbuild once $(CLJSBUILD)
lein -o with-profile $(PROF) cljsbuild once $(CLJSBUILD)
openbrowser:
(sleep 1 && open site/test.html) &
@ -49,6 +49,14 @@ src/cloact/impl/react.min.js: bower_components/react/react-with-addons.min.js Ma
copyjs: bower_components src/cloact/impl/react.min.js
gensite:
node bin/gen-site.js
prodbuild:
$(MAKE) PROF=prod,test leinbuild
buildsite: prodbuild gensite
setversion:
version=$(VERSION); \
find . -name project.clj | \

35
bin/gen-site.js Executable file
View File

@ -0,0 +1,35 @@
#! /usr/bin/env node
var fs = require("fs");
var vm = require('vm');
var srcFile = "target/cljs-client.js";
var src = fs.readFileSync(srcFile);
vm.runInThisContext(src, srcFile);
console.log('Generating page');
var main = demo.genpage();
var head = ['<head>',
'<meta charset="utf-8">',
'<title>This is Cloact</title>',
'<link rel="stylesheet" href="examples/todomvc/todos.css">',
'<link rel="stylesheet" href="examples/todomvc/todosanim.css">',
'<link rel="stylesheet" href="examples/simple/example.css">',
'<link rel="stylesheet" href="site/demo.css">',
'</head>'].join('\n');
var body = ['<body>',
main,
'<script type="text/javascript" src="site/demo.js"></script>',
'<script type="text/javascript">',
'demo.mountdemo();',
'</script>',
'</body>'].join('\n');
var html = ['<html>', head, body, '</html>'].join('\n');
console.log('Writing site');
fs.writeFileSync("index.html", html);
fs.writeFileSync("site/demo.js", src);
console.log('Wrote site');

View File

@ -12,7 +12,7 @@
{:builds
{:client {:compiler
{:optimizations :advanced
:pretty-print true}}}}}
:pretty-print false}}}}}
:test {:plugins [[com.cemerick/clojurescript.test "0.2.1"]]
:cljsbuild
{:builds

View File

@ -9,6 +9,7 @@
(def React tmpl/React)
;; (defn as-component [comp]
;; (tmpl/as-component comp))

View File

@ -107,7 +107,9 @@
(assert C)
(when (nil? (.-cljsRatom C))
(set! (.-cljsRatom C)
(reaction :auto-run #(.forceUpdate C)
(reaction :auto-run (if tmpl/isClient
#(.forceUpdate C)
identity)
(do-render C (.-cljsRenderFn C)))))
(ratom/run (.-cljsRatom C)))

View File

@ -6,6 +6,9 @@
(def React reacts/React)
(def isClient (not (nil? (try (.-document js/window)
(catch js/Object e nil)))))
(defn dash-to-camel [dashed]
(let [words (string/split (name dashed) #"-")
camels (map string/capitalize (rest words))]

View File

@ -266,3 +266,9 @@
[essential-api]
[bmi-demo]
[:p "WIP"]])
(defn ^:export mountdemo []
(cloact/render-component [demo] (.-body js/document)))
(defn ^:export genpage []
(cloact/render-component-to-string [demo]))