Browse Source

wip: making the article design themable

master
Christian Mueller 14 years ago
parent
commit
5186d01b59
  1. 35
      src/NoteHub/views/common.clj
  2. 13
      src/NoteHub/views/pages.clj

35
src/NoteHub/views/common.clj

@ -1,6 +1,7 @@
(ns NoteHub.views.common (ns NoteHub.views.common
(:use (:use
[cssgen] [cssgen]
[cssgen.types]
[noir.core :only [defpartial]] [noir.core :only [defpartial]]
[hiccup.page :only [include-js html5]] [hiccup.page :only [include-js html5]]
[hiccup.element :only [javascript-tag]])) [hiccup.element :only [javascript-tag]]))
@ -25,7 +26,22 @@
:margin-left "auto" :margin-left "auto"
:margin-right "auto")) :margin-right "auto"))
(def global-css (defn color [theme tone]
(get-in {:dark-theme {:background :#fff
:foreground :#333
:background-halftone :#efefef
:foreground-halftone :#888 }
:bright-theme {:background :#fff
:foreground :#333
:background-halftone :#efefef
:foreground-halftone :#888 }} [theme tone]))
(defn global-css [arg]
(let [theme (if-not arg :bright-theme)
background (mixin (color theme :background))
foreground (color theme :foreground)
background-halftone (color theme :background-halftone)
foreground-halftone (color theme :foreground-halftone)]
(css (css
(rule ".landing-button" (rule ".landing-button"
:box-shadow [0 :2px :5px :#aaa] :box-shadow [0 :2px :5px :#aaa]
@ -40,7 +56,8 @@
(rule "&:hover" (rule "&:hover"
:background :#0b2)) :background :#0b2))
(rule "html, body" (rule "html, body"
:color :#333 :background background
:color foreground
:margin 0 :margin 0
:padding 0) :padding 0)
(rule "#hero" (rule "#hero"
@ -59,8 +76,8 @@
(rule "pre" (rule "pre"
:border-radius :3px :border-radius :3px
:padding :1em :padding :1em
:border [:1px :dotted :gray] :border [:1px :dotted foreground-halftone]
:background :#efefef) :background background-halftone)
(rule "*:focus" (rule "*:focus"
:outline [:0px :none :transparent]) :outline [:0px :none :transparent])
(rule "textarea" (rule "textarea"
@ -77,19 +94,19 @@
:border-radius :3px :border-radius :3px
helvetica-neue helvetica-neue
:cursor :pointer :cursor :pointer
:border [:1px :solid] :border [:1px :solid foreground]
:opacity 0.8 :opacity 0.8
:font-size :1em :font-size :1em
:background :white) :background background)
(rule ".central-element" (rule ".central-element"
central-element) central-element)
(rule "h1" (rule "h1"
:font-size :2em) :font-size :2em)
(rule "#preview-start-line" (rule "#preview-start-line"
:border-bottom [:1px :dashed :gray] :border-bottom [:1px :dashed foreground-halftone]
:margin-bottom :5em) :margin-bottom :5em)
(rule "h1, h2, h3, h4" (rule "h1, h2, h3, h4"
:font-family (gen-comma-list "'Noticia Text'" "'PT Serif'")))) :font-family (gen-comma-list "'Noticia Text'" "'PT Serif'")))))
(defpartial generate-layout (defpartial generate-layout
[params title & content] [params title & content]
@ -101,7 +118,7 @@
"&subset=latin,cyrillic" ) "&subset=latin,cyrillic" )
:rel "stylesheet" :rel "stylesheet"
:type "text/css"}] :type "text/css"}]
[:style {:type "text/css"} global-css]] [:style {:type "text/css"} (global-css (params :theme))]]
(if (params :js) (if (params :js)
[:body content [:body content
(javascript-tag "var CLOSURE_NO_DEPS = true;") (javascript-tag "var CLOSURE_NO_DEPS = true;")

13
src/NoteHub/views/pages.clj

@ -73,17 +73,16 @@
[:div#preview-start-line.hidden] [:div#preview-start-line.hidden]
[:article#preview])) [:article#preview]))
; Note URL (defn get-article-page [theme [[year month day] :as date] title]
(defpage "/:year/:month/:day/:title" {:keys [year month day title]} (let [post (get-note date title)
(let [date [year month day]
post (get-note date title)
title (-?> post (split #"\n") first (sreplace #"[_\*#]" ""))] title (-?> post (split #"\n") first (sreplace #"[_\*#]" ""))]
(if post (if post
(common/layout title (common/layout {:theme theme} title [:article (md-to-html post)])
[:article
(md-to-html post)])
(status 404 "")))) (status 404 ""))))
(defpage "/:year/:month/:day/:title" {:keys [year month day title]}
(get-article-page :default-theme [year month day] title))
; New Note Posting ; New Note Posting
(defpage [:post "/post-note"] {:keys [draft session-key session-value]} (defpage [:post "/post-note"] {:keys [draft session-key session-value]}
(let [valid-session (flash-get session-key) ; it was posted from a newly generated form (let [valid-session (flash-get session-key) ; it was posted from a newly generated form

Loading…
Cancel
Save