Created
September 7, 2011 15:31
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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