From 38250c763b16dc9412b32903654b227a7ba3dcd8 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Tue, 15 Sep 2015 13:36:02 +0200 Subject: [PATCH] Cleanup config handling --- demo/sitetools/core.cljs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/demo/sitetools/core.cljs b/demo/sitetools/core.cljs index d425d7e..c8d571c 100644 --- a/demo/sitetools/core.cljs +++ b/demo/sitetools/core.cljs @@ -46,23 +46,25 @@ (defonce history nil) -(defn demo-handler [state [id x y :as event]] +(defn demo-handler [state [id x :as event]] (case id - :set-content (let [title (if y - (str (:title-prefix state) y) - (str (:default-title state)))] - (assert (vector? x)) + :set-content (let [page x + title (:title page) + _ (assert (vector? (:content page))) + title (if title + (str (:title-prefix state) title) + (str (:default-title state))) + page (assoc page :title title)] (when r/is-client (set! js/document.title title)) - (assoc state :main-content x :title title)) - :set-page (do (assert (string? x)) - (let [{pages :pages} state - p (get pages x (get pages "/index.html"))] - (-> state - (assoc :page-path x) - (recur [:set-content (:content p) (:title p)])))) - :goto-page (do - (assert (string? x)) + (assoc state :current-page page)) + :set-page (let [path x + _ (assert (string? path)) + ps (:pages state) + p (get ps path (get ps "/index.html"))] + (recur state [:set-content p])) + :goto-page (let [path x + _ (assert (string? path))] (when-some [h history] (.setToken h x) (r/next-tick #(set! js/document.body.scrollTop 0)) @@ -118,7 +120,7 @@ child]) (defn main-content [] - (let [{comp :main-content} @config] + (let [comp (get-in @config [:current-page :content])] (assert (vector? comp)) comp)) @@ -152,12 +154,14 @@ (defn gen-page [page-path conf] (dispatch [:set-page page-path]) - (let [b (:body conf) + (let [conf (merge conf @config) + b (:body conf) _ (assert (vector? b)) bhtml (r/render-component-to-string b)] (str "\n" (html-template (assoc conf :page-conf {:page-path page-path} + :title (-> conf :current-page :title) :body-html bhtml))))) (defn fs [] (js/require "fs"))