Fix site-generation and simplify title setting

This commit is contained in:
Dan Holmsand 2014-11-29 19:51:45 +01:00
parent bffbae231d
commit bc89612a76
11 changed files with 60 additions and 47 deletions

View File

@ -46,8 +46,9 @@ serve-site: trigger-build
trigger-build: trigger-build:
# always trigger build to make sure page-generation works # always trigger build to make sure page-generation works
@echo "(ns empty.generated.ns)" > demo/empty.cljs @echo "(ns empty.generated.ns)" > demo/empty.cljs
cat examples/todomvc/todos.css examples/simple/example.css \ @(echo "/* Generated, do not modify */\n\n" && \
> site/public/css/examples.css cat examples/todomvc/todos.css examples/simple/example.css) \
> site/public/css/examples.css

View File

@ -24,11 +24,14 @@
(def index-page "index.html") (def index-page "index.html")
(def news-page "news/index.html") (def news-page "news/index.html")
(tools/register-page index-page (fn [] [intro/main])) (tools/register-page index-page
(tools/register-page news-page (fn [] [news/main])) (fn [] [intro/main])
"Reagent: Minimalistic React for ClojureScript")
(tools/register-page news-page
(fn [] [news/main])
"Reagent news")
(defn demo [] (defn demo []
(dbg "demo")
[:div [:div
[:div.nav [:div.nav
[:ul.nav [:ul.nav
@ -43,4 +46,6 @@
(defn start! [{:keys [test-results]}] (defn start! [{:keys [test-results]}]
(reset! test-results-comp test-results) (reset! test-results-comp test-results)
(tools/start! {:body (fn [] [demo])})) (tools/start! {:body (fn [] [demo])
:css-infiles ["site/public/css/main.css"
"site/public/css/examples.css"]}))

View File

@ -5,7 +5,7 @@
[reagent.debug :refer-macros [dbg println]] [reagent.debug :refer-macros [dbg println]]
[clojure.string :as string] [clojure.string :as string]
[reagentdemo.syntax :refer-macros [get-source]] [reagentdemo.syntax :refer-macros [get-source]]
[sitetools :refer [link title]] [sitetools :refer [link]]
[reagentdemo.common :as common :refer [demo-component]] [reagentdemo.common :as common :refer [demo-component]]
[simpleexample :as simple] [simpleexample :as simple]
[todomvc :as todo])) [todomvc :as todo]))
@ -323,7 +323,6 @@
(js/setTimeout #(reset! show-all true) 500) (js/setTimeout #(reset! show-all true) 500)
(fn [] (fn []
[:div.reagent-demo [:div.reagent-demo
[title head]
[:h1 head] [:h1 head]
[intro] [intro]
[managing-state] [managing-state]

View File

@ -3,7 +3,7 @@
[reagent.interop :refer-macros [.' .!]] [reagent.interop :refer-macros [.' .!]]
[reagent.debug :refer-macros [dbg println]] [reagent.debug :refer-macros [dbg println]]
[reagentdemo.common :as common :refer [demo-component]] [reagentdemo.common :as common :refer [demo-component]]
[sitetools :as tools :refer [title link]] [sitetools :as tools :refer [link]]
[reagentdemo.news.anyargs :as anyargs] [reagentdemo.news.anyargs :as anyargs]
[reagentdemo.news.async :as async] [reagentdemo.news.async :as async]
[reagentdemo.news.undodemo :as undodemo] [reagentdemo.news.undodemo :as undodemo]
@ -11,7 +11,6 @@
(defn main [] (defn main []
[:div [:div
[title "Reagent news"]
[clock/main {:summary true}] [clock/main {:summary true}]
[anyargs/main {:summary true}] [anyargs/main {:summary true}]
[async/main {:summary true}] [async/main {:summary true}]

View File

@ -3,11 +3,12 @@
[reagent.interop :refer-macros [.' .!]] [reagent.interop :refer-macros [.' .!]]
[reagent.debug :refer-macros [dbg println]] [reagent.debug :refer-macros [dbg println]]
[reagentdemo.syntax :refer-macros [get-source]] [reagentdemo.syntax :refer-macros [get-source]]
[sitetools :as tools :refer [title link]] [sitetools :as tools :refer [link]]
[reagentdemo.common :as common :refer [demo-component]] [reagentdemo.common :as common :refer [demo-component]]
[geometry.core :as geometry])) [geometry.core :as geometry]))
(def url "news/any-arguments.html") (def url "news/any-arguments.html")
(def title "All arguments allowed")
(def funmap (-> ::this get-source common/fun-map)) (def funmap (-> ::this get-source common/fun-map))
(def src-for (partial common/src-for funmap)) (def src-for (partial common/src-for funmap))
@ -33,12 +34,10 @@
[:p "Some other text in bold."]]]) [:p "Some other text in bold."]]])
(defn main [{:keys [summary]}] (defn main [{:keys [summary]}]
(let [head "All arguments allowed" (let [geometry {:href "https://github.com/reagent-project/reagent/tree/master/examples/geometry"}
geometry {:href "https://github.com/reagent-project/reagent/tree/master/examples/geometry"}
jonase {:href "https://github.com/jonase"}] jonase {:href "https://github.com/jonase"}]
[:div.reagent-demo [:div.reagent-demo
[:h1 [link {:href url} head]] [:h1 [link {:href url} title]]
[title (str "Reagent 0.4.0: " head)]
[:div.demo-text [:div.demo-text
[:h2 "If it looks like a function…"] [:h2 "If it looks like a function…"]
@ -132,4 +131,5 @@
[demo-component {:comp geometry-example}]])]])) [demo-component {:comp geometry-example}]])]]))
(tools/register-page url (fn [] [main])) (tools/register-page url (fn [] [main])
(str "Reagent: " title))

View File

@ -3,10 +3,11 @@
[reagent.interop :refer-macros [.' .!]] [reagent.interop :refer-macros [.' .!]]
[reagent.debug :refer-macros [dbg println]] [reagent.debug :refer-macros [dbg println]]
[reagentdemo.syntax :refer-macros [get-source]] [reagentdemo.syntax :refer-macros [get-source]]
[sitetools :as tools :refer [title link]] [sitetools :as tools :refer [link]]
[reagentdemo.common :as common :refer [demo-component]])) [reagentdemo.common :as common :refer [demo-component]]))
(def url "news/reagent-is-async.html") (def url "news/reagent-is-async.html")
(def title "Faster by waiting")
(def funmap (-> "reagentdemo/news/async.cljs" get-source common/fun-map)) (def funmap (-> "reagentdemo/news/async.cljs" get-source common/fun-map))
(def src-for (partial common/src-for funmap)) (def src-for (partial common/src-for funmap))
@ -93,8 +94,7 @@
(defn main [{:keys [summary]}] (defn main [{:keys [summary]}]
(let [om-article {:href "http://swannodette.github.io/2013/12/17/the-future-of-javascript-mvcs/"}] (let [om-article {:href "http://swannodette.github.io/2013/12/17/the-future-of-javascript-mvcs/"}]
[:div.reagent-demo [:div.reagent-demo
[title "Reagent: Faster by waiting"] [:h1 [link {:href url} title]]
[:h1 [link {:href url} "Faster by waiting"]]
[:div.demo-text [:div.demo-text
[:h2 "Reagent gets async rendering"] [:h2 "Reagent gets async rendering"]
@ -196,4 +196,5 @@
:reset-random-colors :color-choose :ncolors-choose :reset-random-colors :color-choose :ncolors-choose
:palette :color-demo])}]])]])) :palette :color-demo])}]])]]))
(tools/register-page url (fn [] [main])) (tools/register-page url (fn [] [main])
(str "Reagent: " title))

View File

@ -3,11 +3,12 @@
[reagent.interop :refer-macros [.' .!]] [reagent.interop :refer-macros [.' .!]]
[reagent.debug :refer-macros [dbg]] [reagent.debug :refer-macros [dbg]]
[reagentdemo.syntax :refer-macros [get-source]] [reagentdemo.syntax :refer-macros [get-source]]
[sitetools :as tools :refer [title link]] [sitetools :as tools :refer [link]]
[reagentdemo.common :as common :refer [demo-component]] [reagentdemo.common :as common :refer [demo-component]]
[reagentdemo.news.binaryclock :as binaryclock])) [reagentdemo.news.binaryclock :as binaryclock]))
(def url "news/binary-clock.html") (def url "news/binary-clock.html")
(def title "A binary clock")
(def funmap (-> "reagentdemo/news/binaryclock.cljs" (def funmap (-> "reagentdemo/news/binaryclock.cljs"
get-source common/fun-map)) get-source common/fun-map))
@ -18,16 +19,14 @@
:no-heading true}]) :no-heading true}])
(defn main [{:keys [summary]}] (defn main [{:keys [summary]}]
(let [head "A binary clock" (let [lexclock {:href "http://www.lexicallyscoped.com/2014/01/23/clojurescript-react-om-binary-clock.html"}
lexclock {:href "http://www.lexicallyscoped.com/2014/01/23/clojurescript-react-om-binary-clock.html"}
hopclock {:href "http://pmbauer.github.io/2014/01/27/hoplon-binary-clock/"} hopclock {:href "http://pmbauer.github.io/2014/01/27/hoplon-binary-clock/"}
om {:href "https://github.com/swannodette/om"} om {:href "https://github.com/swannodette/om"}
hoplon {:href "http://hoplon.io"} hoplon {:href "http://hoplon.io"}
clocksrc {:href "https://github.com/reagent-project/reagent/blob/master/demo/reagentdemo/news/binaryclock.cljs"}] clocksrc {:href "https://github.com/reagent-project/reagent/blob/master/demo/reagentdemo/news/binaryclock.cljs"}]
[:div.reagent-demo [:div.reagent-demo
[:h1 [link {:href url} head]] [:h1 [link {:href url} title]]
[title head]
[:div.demo-text [:div.demo-text
(when-not summary (when-not summary
@ -121,4 +120,5 @@
description that corresponds to those arguments, and leave it description that corresponds to those arguments, and leave it
to React to actually display that UI."]])]])) to React to actually display that UI."]])]]))
(tools/register-page url (fn [] [main])) (tools/register-page url (fn [] [main])
(str "Reagent: " title))

View File

@ -3,11 +3,12 @@
[reagent.interop :refer-macros [.' .!]] [reagent.interop :refer-macros [.' .!]]
[reagent.debug :refer-macros [dbg println]] [reagent.debug :refer-macros [dbg println]]
[reagentdemo.syntax :refer-macros [get-source]] [reagentdemo.syntax :refer-macros [get-source]]
[sitetools :as tools :refer [title link]] [sitetools :as tools :refer [link]]
[reagentdemo.common :as common :refer [demo-component]] [reagentdemo.common :as common :refer [demo-component]]
[todomvc :as todomvc])) [todomvc :as todomvc]))
(def url "news/cloact-reagent-undo-demo.html") (def url "news/cloact-reagent-undo-demo.html")
(def title "Cloact becomes Reagent: Undo is trivial")
(def funmap (-> ::this get-source common/fun-map)) (def funmap (-> ::this get-source common/fun-map))
(def src-for (partial common/src-for funmap)) (def src-for (partial common/src-for funmap))
@ -48,10 +49,9 @@
(remove-watch state ::undo-watcher))})) (remove-watch state ::undo-watcher))}))
(defn main [{:keys [summary]}] (defn main [{:keys [summary]}]
(let [head "Cloact becomes Reagent: Undo is trivial"] (let [head title]
[:div.reagent-demo [:div.reagent-demo
[:h1 [link {:href url} head]] [:h1 [link {:href url} head]]
[title head]
[:div.demo-text [:div.demo-text
[:h2 "(reset! cloact-name \"Reagent\")"] [:h2 "(reset! cloact-name \"Reagent\")"]
@ -88,4 +88,4 @@
[undo-demo-cleanup]])]])) [undo-demo-cleanup]])]]))
(tools/register-page url (fn [] [main])) (tools/register-page url (fn [] [main]) title)

View File

@ -21,6 +21,7 @@
(defonce config (atom {:page-map {"index.html" (defonce config (atom {:page-map {"index.html"
(fn [] [:div "Empty"])} (fn [] [:div "Empty"])}
:page-titles {}
:body (fn [] [:div (page-content)]) :body (fn [] [:div (page-content)])
:site-dir "outsite/public" :site-dir "outsite/public"
:css-infiles ["site/public/css/main.css"] :css-infiles ["site/public/css/main.css"]
@ -31,14 +32,19 @@
:allow-html5-history false})) :allow-html5-history false}))
(defonce page (atom "index.html")) (defonce page (atom "index.html"))
(defonce page-title (atom (:default-title @config)))
(defonce page-state (atom {:has-history false})) (defonce page-state (atom {:has-history false}))
(defn register-page [pageurl comp] (defn register-page
(assert (string? pageurl) (str "expected string, not " pageurl)) ([pageurl comp]
(assert (fn? comp)) (register-page pageurl comp nil))
(swap! config update-in [:page-map] assoc pageurl comp)) ([pageurl comp title]
(assert (string? pageurl)
(str "expected string, not " pageurl))
(assert (fn? comp))
(assert (or (nil? title)
(string? title)))
(swap! config update-in [:page-map] assoc pageurl comp)
(swap! config update-in [:page-titles] assoc pageurl title)))
;;; Components ;;; Components
@ -61,14 +67,6 @@
identity)) identity))
child])) child]))
(defn title [name]
(when (= @page-title "")
;; First title on a page wins
(reset! page-title name)
(when reagent/is-client
(set! (.-title js/document) @page-title)))
nil)
(defn page-content [] (defn page-content []
[(get-in @config [:page-map @page] [(get-in @config [:page-map @page]
(get-in @config [:page-map "index.html"]))]) (get-in @config [:page-map "index.html"]))])
@ -78,13 +76,19 @@
;;; Implementation: ;;; Implementation:
(defn get-title []
(get-in @config [:page-titles @page]
(:default-title @config)))
(defn default-content [] (defn default-content []
[:div "Empty"]) [:div "Empty"])
(add-watch page ::title-watch (add-watch page ::title-watch
(fn [_ _ _ p] (fn [_ _ _ p]
(when reagent/is-client
(set! (.-title js/document) (get-title)))
;; First title on a page wins ;; First title on a page wins
(reset! page-title ""))) #_(reset! page-title "")))
;;; History ;;; History
@ -185,7 +189,7 @@
(reset! page page-name) (reset! page page-name)
(let [b (reagent/render-component-to-string (body))] (let [b (reagent/render-component-to-string (body))]
(str "<!doctype html>" (str "<!doctype html>"
(html-template {:title @page-title (html-template {:title (get-title)
:body b :body b
:page-conf {:allow-html5-history true :page-conf {:allow-html5-history true
:page-name page-name} :page-name page-name}
@ -255,5 +259,6 @@
(set-start-page page-name)) (set-start-page page-name))
(swap! config merge conf) (swap! config merge conf)
(setup-history) (setup-history)
(set! (.-title js/document) (get-title))
(reagent/render-component (body) (reagent/render-component (body)
(.' js/document :body))))) (.' js/document :body)))))

View File

@ -23,7 +23,7 @@
:output-dir :output-dir
"outsite/public/js/out"}}}}} "outsite/public/js/out"}}}}}
:site {:resource-paths ^:replace ["outsite"] :site {:resource-paths ^:replace ["outsite" "vendor"]
:figwheel {:css-dirs ^:replace ["outsite/public/css"]} :figwheel {:css-dirs ^:replace ["outsite/public/css"]}
:cljsbuild {:builds :cljsbuild {:builds
{:client {:client

View File

@ -1,3 +1,6 @@
/* Generated, do not modify */
@charset "utf-8"; @charset "utf-8";
html, html,
body { body {