2014-01-02 14:04:30 +01:00
|
|
|
(ns demo
|
2014-01-17 11:12:11 +01:00
|
|
|
(:require [reagent.core :as reagent :refer [atom]]
|
2014-01-06 12:46:58 +01:00
|
|
|
[clojure.string :as string]
|
2014-01-21 11:50:08 +01:00
|
|
|
[reagentdemo.page :as page :refer [page-map page link prefix]]
|
|
|
|
[reagentdemo.common :as common :refer [demo-component]]
|
2014-01-18 11:31:43 +01:00
|
|
|
[reagentdemo.intro :as intro]
|
2014-01-20 09:42:16 +01:00
|
|
|
[reagentdemo.news :as news]
|
2014-01-17 11:12:11 +01:00
|
|
|
[reagent.debug :refer-macros [dbg println]]))
|
2014-01-02 14:04:30 +01:00
|
|
|
|
2014-01-20 11:37:57 +01:00
|
|
|
(swap! page-map assoc
|
|
|
|
"index.html" intro/main
|
|
|
|
"news/index.html" news/main)
|
2014-01-17 12:35:40 +01:00
|
|
|
|
2014-01-22 08:40:04 +01:00
|
|
|
(def github {:href "https://github.com/holmsand/reagent"})
|
|
|
|
|
2014-01-07 17:01:28 +01:00
|
|
|
(defn github-badge []
|
|
|
|
[:a.github-badge
|
2014-01-22 08:40:04 +01:00
|
|
|
github
|
2014-01-07 17:01:28 +01:00
|
|
|
[:img {:style {:position "absolute" :top 0 :left 0 :border 0}
|
2014-01-22 08:40:04 +01:00
|
|
|
:alt "Fork me on GitHub"
|
|
|
|
:src "https://s3.amazonaws.com/github/ribbons/forkme_left_orange_ff7600.png"}]])
|
2014-01-07 17:01:28 +01:00
|
|
|
|
2014-01-02 14:04:30 +01:00
|
|
|
(defn demo []
|
2014-01-06 19:16:53 +01:00
|
|
|
[:div
|
2014-01-20 09:42:16 +01:00
|
|
|
[:div.nav
|
|
|
|
[:ul.nav
|
2014-01-20 11:37:57 +01:00
|
|
|
[:li.brand [link {:href intro/main} "Reagent:"]]
|
2014-01-22 08:40:04 +01:00
|
|
|
[:li [link {:href intro/main} "Intro"]]
|
|
|
|
[:li [link {:href news/main} "News"]]
|
|
|
|
[:li [:a github "GitHub"]]]]
|
2014-01-20 11:37:57 +01:00
|
|
|
(let [comp (get @page-map @page intro/main)]
|
|
|
|
[comp])
|
2014-01-09 14:37:11 +01:00
|
|
|
[github-badge]])
|
2014-01-05 11:16:01 +01:00
|
|
|
|
2014-01-19 12:13:19 +01:00
|
|
|
(defn ^:export mountdemo [p]
|
2014-01-27 22:30:42 +01:00
|
|
|
(when p (page/set-start-page p))
|
2014-01-17 11:12:11 +01:00
|
|
|
(reagent/render-component [demo] (.-body js/document)))
|
2014-01-05 11:16:01 +01:00
|
|
|
|
2014-01-19 12:13:19 +01:00
|
|
|
(defn gen-page [p timestamp]
|
|
|
|
(reset! page p)
|
|
|
|
(let [body (reagent/render-component-to-string [demo])
|
2014-01-27 22:30:42 +01:00
|
|
|
title @page/title-atom
|
|
|
|
load-page (case p "index.html" "" p)]
|
2014-01-19 12:13:19 +01: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'>
|
2014-01-27 22:30:42 +01:00
|
|
|
setTimeout(function() {demo.mountdemo('" load-page "')}, 200);
|
2014-01-19 12:13:19 +01:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>")))
|
|
|
|
|
|
|
|
(defn ^:export genpages []
|
|
|
|
(let [timestamp (str "?" (.now js/Date))]
|
2014-01-20 11:37:57 +01:00
|
|
|
(->> (keys @page-map)
|
2014-01-19 12:13:19 +01:00
|
|
|
(map #(vector % (gen-page % timestamp)))
|
|
|
|
(into {})
|
|
|
|
clj->js)))
|