diff --git a/project.clj b/project.clj index e3b51d4..41b2b35 100644 --- a/project.clj +++ b/project.clj @@ -11,6 +11,7 @@ [org.apache.commons/commons-math3 "3.6.1"] [org.clojure/core.async "0.4.474"] [quil "2.6.0"] - [hiccup "1.0.5"]] + [hiccup "1.0.5"] + [garden "1.3.5"]] :plugins [[lein-ring "0.9.7"]] :ring {:handler sketchbook.handler/app}) diff --git a/src_clj/sketchbook/handler.clj b/src_clj/sketchbook/handler.clj index af745fb..4208110 100644 --- a/src_clj/sketchbook/handler.clj +++ b/src_clj/sketchbook/handler.clj @@ -7,7 +7,8 @@ [ring.server.standalone :refer [serve]] [clojure.core.async :refer [! 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 [] (r/set-seed seed) (setup)) diff --git a/src_clj/sketchbook/style.clj b/src_clj/sketchbook/style.clj new file mode 100644 index 0000000..12d8d94 --- /dev/null +++ b/src_clj/sketchbook/style.clj @@ -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) diff --git a/src_clj/sketchbook/views.clj b/src_clj/sketchbook/views.clj index 056114e..be679c5 100644 --- a/src_clj/sketchbook/views.clj +++ b/src_clj/sketchbook/views.clj @@ -1,27 +1,34 @@ (ns sketchbook.views - (:require [hiccup.core :refer [html]] + (:require [hiccup.page :refer [html5 include-css]] [sketchbook.sketches :refer [sketches]])) +(defmacro page + "A template for a website page" + [& body] + `(html5 + [:head + (include-css "stylesheet")] + [:body ~@body])) + (defn sketch-img "A sketch image" [name width height] - (html - [:img {:src (str "/api/sketches/" name "?width=" width "&height=" height) - :width width - :height height}])) + [:img {:src (str "/api/sketches/" name "?width=" width "&height=" height) + :width width + :height height}]) (defn sketch-thumbnail "A thumbnail of a sketch" [title name width height] - (html - [:h1 title] + [:div + [:h3.sketch-thumbnail-title title] [:a {:href (str "/" name)} - (sketch-img name width height)])) + (sketch-img name width height)]]) -(defn index +(defn index-page "The index page" [] - (html + (page (map #(sketch-thumbnail (:title (second %)) (name (first %)) 300 @@ -31,6 +38,6 @@ (defn sketch-page "Page for an individual sketch" [title name] - (html + (page [:h1 title] (sketch-img name 768 768)))