Skip to content

Instantly share code, notes, and snippets.

@dgrnbrg
Created October 18, 2012 02:38
Show Gist options
  • Save dgrnbrg/3909566 to your computer and use it in GitHub Desktop.
Save dgrnbrg/3909566 to your computer and use it in GitHub Desktop.
Enlive - Code
(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