Skip to content

Instantly share code, notes, and snippets.

@coopernurse
Created September 7, 2011 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coopernurse/1200882 to your computer and use it in GitHub Desktop.
Save coopernurse/1200882 to your computer and use it in GitHub Desktop.
example of injecting a helper function that provides data to a view func
(defn mock-sidebar-loader []
{ :total-users 302
:available-books 992
:activity [
{ :created 1315407000912
:status "have"
:title "Moby Dick"
:author "Herman Melville" }
{ :created 1315406000912
:status "have"
:title "Atlas Shrugged"
:author "Ayn Rand and some other really long text that I don't think will fit in the sidebar if it is not truncated" }
{ :created 1315307000912
:status "want"
:title "Programming Clojure"
:author "Stuart Halloway" }
]})
(def sidebar-loader (atom mock-sidebar-loader))
(defn set-sidebar-loader! [f]
(swap! sidebar-loader f))
(defpartial sidebar []
(let [stats (@sidebar-loader)]
[:div {:id "sidebar" :class "right"}
[:h3 {:class "title"} "Our Community"]
[:div {:class "recent-activity"}
[:div {:class "instructions"}
(str (:total-users stats) " users are sharing " (:available-books stats) " books")]
[:div {:class "instructions"}
[:a {:class "searchhave" :href "/available"} "View all available books"] ] ]
[:div {:class "recent-activity"}
(map recent-activity-row (:activity stats)) ] ]
(clear-div)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment