Include styles

This commit is contained in:
Jeremy Dormitzer 2018-04-09 06:35:00 -04:00
parent 2f9eb55c36
commit 22abc6b217
No known key found for this signature in database
GPG Key ID: 04F17C0F5A32C320
5 changed files with 49 additions and 15 deletions

View File

@ -11,6 +11,7 @@
[org.apache.commons/commons-math3 "3.6.1"] [org.apache.commons/commons-math3 "3.6.1"]
[org.clojure/core.async "0.4.474"] [org.clojure/core.async "0.4.474"]
[quil "2.6.0"] [quil "2.6.0"]
[hiccup "1.0.5"]] [hiccup "1.0.5"]
[garden "1.3.5"]]
:plugins [[lein-ring "0.9.7"]] :plugins [[lein-ring "0.9.7"]]
:ring {:handler sketchbook.handler/app}) :ring {:handler sketchbook.handler/app})

View File

@ -7,7 +7,8 @@
[ring.server.standalone :refer [serve]] [ring.server.standalone :refer [serve]]
[clojure.core.async :refer [<!! <! go]] [clojure.core.async :refer [<!! <! go]]
[sketchbook.sketches :as sketches] [sketchbook.sketches :as sketches]
[sketchbook.views :as views]) [sketchbook.views :as views]
[sketchbook.style :as style])
(:import [java.io ByteArrayInputStream])) (:import [java.io ByteArrayInputStream]))
(defn sketch-handler (defn sketch-handler
@ -42,7 +43,9 @@
(context "/api" [] (context "/api" []
(GET "/sketches/:sketch" [sketch width height] sketch-handler) (GET "/sketches/:sketch" [sketch width height] sketch-handler)
(GET "/sketches/:sketch/:seed" [sketch seed width height] sketch-handler)) (GET "/sketches/:sketch/:seed" [sketch seed width height] sketch-handler))
(GET "/" [] (views/index)) (GET "/" [] (views/index-page))
(GET "/stylesheet" []
(content-type (response (style/stylesheet)) "text/css"))
(GET "/:sketch" [sketch] (GET "/:sketch" [sketch]
(let [sketch-item ((keyword sketch) sketches/sketches)] (let [sketch-item ((keyword sketch) sketches/sketches)]
(views/sketch-page (:title sketch-item) sketch))) (views/sketch-page (:title sketch-item) sketch)))

View File

@ -29,7 +29,7 @@
(with-open [in (io/input-stream filename)] (with-open [in (io/input-stream filename)]
(io/copy in out)) (io/copy in out))
(go (>! channel (.toByteArray out)))) (go (>! channel (.toByteArray out))))
(q/sketch :size [(/ (first size) 2) (/ (second size) 2)] ;; For some reason images were coming out twice as large as they should be (q/sketch :size size
:setup (fn [] :setup (fn []
(r/set-seed seed) (r/set-seed seed)
(setup)) (setup))

View File

@ -0,0 +1,23 @@
(ns sketchbook.style
(:require [garden.core :refer [css]]))
(def sizes
{:tiny "9px"
:small "12px"
:medium "16px"
:large "21px"
:huge "28px"})
(defn sketch-thumbnail-styles
"Styles for sketch thumbnails"
[]
[:h3.sketch-thumbnail-title
{:font-size (:small sizes)
:margin-bottom 0
:text-transform "uppercase"}])
(def stylesheet-css
(css (sketch-thumbnail-styles)))
(defn stylesheet []
stylesheet-css)

View File

@ -1,27 +1,34 @@
(ns sketchbook.views (ns sketchbook.views
(:require [hiccup.core :refer [html]] (:require [hiccup.page :refer [html5 include-css]]
[sketchbook.sketches :refer [sketches]])) [sketchbook.sketches :refer [sketches]]))
(defmacro page
"A template for a website page"
[& body]
`(html5
[:head
(include-css "stylesheet")]
[:body ~@body]))
(defn sketch-img (defn sketch-img
"A sketch image" "A sketch image"
[name width height] [name width height]
(html [:img {:src (str "/api/sketches/" name "?width=" width "&height=" height)
[:img {:src (str "/api/sketches/" name "?width=" width "&height=" height) :width width
:width width :height height}])
:height height}]))
(defn sketch-thumbnail (defn sketch-thumbnail
"A thumbnail of a sketch" "A thumbnail of a sketch"
[title name width height] [title name width height]
(html [:div
[:h1 title] [:h3.sketch-thumbnail-title title]
[:a {:href (str "/" name)} [:a {:href (str "/" name)}
(sketch-img name width height)])) (sketch-img name width height)]])
(defn index (defn index-page
"The index page" "The index page"
[] []
(html (page
(map #(sketch-thumbnail (:title (second %)) (map #(sketch-thumbnail (:title (second %))
(name (first %)) (name (first %))
300 300
@ -31,6 +38,6 @@
(defn sketch-page (defn sketch-page
"Page for an individual sketch" "Page for an individual sketch"
[title name] [title name]
(html (page
[:h1 title] [:h1 title]
(sketch-img name 768 768))) (sketch-img name 768 768)))