Created
October 18, 2012 02:38
-
-
Save dgrnbrg/3909566 to your computer and use it in GitHub Desktop.
Enlive - Code
This file contains hidden or 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
(ns presentation.views.home | |
(:require [net.cgrand.enlive-html :as html])) | |
(def template-file "templates/home/index.html") | |
;; We'd normally pull this from a data store, but for the sake of example... | |
(def learned-things | |
["to look both ways multiple times before crossing a nyc intersection" | |
"how to bargain with street vendors" | |
"about an amazing library called enlive" | |
"the Answer to the Ultimate Question of Life, The Universe, and Everything"]) | |
(html/defsnippet list-item template-file [:#learned-list :> html/first-child] | |
[item] | |
[:label] (html/content item) | |
[:.edit] (html/set-attr :value item)) | |
(html/deftemplate index-tpl template-file [items] | |
[:link] #(update-in % [:attrs :href] | |
clojure.string/replace #"(.*)/(.*\.css)" "/css/$2") | |
[:#learned-list] (html/content (map list-item items)) | |
[:#learned-count :> html/first-child] (html/content (str (count items)))) | |
(defn index [] | |
(index-tpl learned-things)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment