Browse files

Add some documentation

  • Loading branch information...
amalloy committed Sep 13, 2011
1 parent 38f24b4 commit 8e2c92c84cdc8fda8b026208dfa155c6df06b405
Showing with 17 additions and 2 deletions.
  1. +17 −2 src/foreclojure/utils.clj
@@ -33,8 +33,17 @@
-(defn image-builder [data & {:keys [alt src] :or {alt identity,
- src identity}}]
+(defn image-builder
+ "Return a function for constructing an [:img] element from a keyword.
+ data should be a map from image \"names\" to pairs [src, alt]. The function
+ returned by image-builder will look up its argument as an image name, and
+ return an img element with the appropriate src and alt attributes.
+ Optionally, additional keyword arguments :alt and :src may be supplied to
+ image-builder - these functions will be called to transform the alt and src
+ attributes of the returned img."
+ [data & {:keys [alt src] :or {alt identity, src identity}}]
(fn [key]
(let [[src-prop alt-prop] (get data key)]
[:img {:src (src src-prop)
@@ -109,18 +118,24 @@
(>= (count (get-solved username))
(:advanced-user-count config))))
(defprotocol PageWriter
+ "Specify how an object should be converted to the {:title \"foo\" :content
+ [:div ...] :baz-attr true} format used by def-page for rendering pages."
(page-attributes [this]))
(extend-protocol PageWriter
+ ;; Supplied map should be used verbatim
(page-attributes [this] this)
+ ;; User probably just returned a Hiccup structure; shove it into :content
(page-attributes [this]
{:content this})
+ ;; Allow to return nothing at all so Compojure keeps looking
(page-attributes [this] nil))
(let [defaults {:content nil

0 comments on commit 8e2c92c

Please sign in to comment.