reagent/demo/demo.cljs

67 lines
2.1 KiB
Plaintext
Raw Normal View History

2014-01-02 13:04:30 +00:00
(ns demo
2014-01-17 10:12:11 +00:00
(:require [reagent.core :as reagent :refer [atom]]
2014-01-06 11:46:58 +00:00
[clojure.string :as string]
[reagentdemo.common :as common
:refer [demo-component page link reverse-page-map prefix]]
2014-01-18 10:31:43 +00:00
[reagentdemo.intro :as intro]
[reagentdemo.news :as news]
2014-01-17 10:12:11 +00:00
[reagent.debug :refer-macros [dbg println]]))
2014-01-02 13:04:30 +00:00
(common/set-page-map {:index ["index.html" [intro/main]]
:news ["news/index.html" [news/main]]
:undo-demo ["news/cloact-reagent-undo-demo.html"
[news/main]]})
2014-01-07 16:01:28 +00:00
(defn github-badge []
[:a.github-badge
2014-01-17 10:12:11 +00:00
{:href "https://github.com/holmsand/reagent"}
2014-01-07 16:01:28 +00:00
[:img {:style {:position "absolute" :top 0 :left 0 :border 0}
:src "https://s3.amazonaws.com/github/ribbons/forkme_left_orange_ff7600.png"
:alt "Fork me on GitHub"}]])
2014-01-02 13:04:30 +00:00
(defn demo []
[:div
[:div.nav
[:ul.nav
[:li.brand [link {:href :index} "Reagent:"]]
[:li [link {:href :index} "Introduction"]]
[:li [link {:href :news} "News"]]]]
(let [p @page
[_ comp] (get @reverse-page-map p
(:index @common/page-map))]
comp)
2014-01-09 13:37:11 +00:00
[github-badge]])
2014-01-05 10:16:01 +00:00
2014-01-19 11:13:19 +00:00
(defn ^:export mountdemo [p]
(when p (reset! page p))
2014-01-17 10:12:11 +00:00
(reagent/render-component [demo] (.-body js/document)))
2014-01-05 10:16:01 +00:00
2014-01-19 11:13:19 +00:00
(defn gen-page [p timestamp]
(reset! page p)
(let [body (reagent/render-component-to-string [demo])
title @common/title-atom]
2014-01-19 11:13:19 +00:00
(str "<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<title>" title "</title>
<meta name='viewport' content='width=device-width, initial-scale=1.0' />
<link rel='stylesheet' href='" (prefix "assets/demo.css") timestamp "'>
</head>
<body>
" body "
<script type='text/javascript'
src='" (prefix "assets/demo.js") timestamp "'></script>
<script type='text/javascript'>
setTimeout(function() {demo.mountdemo('" p "')}, 200);
</script>
</body>
</html>")))
(defn ^:export genpages []
(let [timestamp (str "?" (.now js/Date))]
(->> (keys @reverse-page-map)
2014-01-19 11:13:19 +00:00
(map #(vector % (gen-page % timestamp)))
(into {})
clj->js)))