Enlive-samples is a project mainly written in Clojure, it's free.
Attempt to provide simple examples of enlive (Clojure templating library)
What's this ?
[[https://github.com/cgrand/enlive][Enlive]] is a great templating framework for Clojure, but it is also mind bending.
enlive-samples tries to provide very simple examples, to be used as a starting point in other projects
Beware
| [[https://github.com/denlab/enlive-samples/raw/master/src/doc/image/danger.png]] | Under construction! Not ready yet! | |------------------------------------------------------------------------------+---|
cd enlive-samples
** Get the dependencies:
lein deps
** Start a REPL:
lein repl
or with emacs:
lein swank
** At the REPL:
(ns user (:require [net.cgrand.enlive-html :as html]) (:use [enlivesamples.sample3] [clojure.contrib.repl-utils :only [show]] [clojure.test :only [run-tests]] [clojure.repl] [enlivesamples.utils]))
** Now point your browser at http://localhost:8080
We will just replace the content of the tag with =id= message.
Here is a diagram of the sample 1 that tries ;) to explain how the pieces work together.
[[https://github.com/denlab/enlive-samples/raw/master/src/doc/image/diagram-sample1.png]]
Sample 2: Replace the content of an attribute.
We just replace the style of the =div= with =id= = 'message', with a random background color.
Sample 3: Repeating elements
Here we simply repeat divs.
** On the REPL
(ns user (:require [net.cgrand.enlive-html :as html]) (:use [enlivesamples.sample3] [clojure.contrib.repl-utils :only [show]] [clojure.test :only [run-tests]] [clojure.repl] [enlivesamples.utils]))
** To test the selector on the REPL:
(render (html/emit* (section-model {:title "title" :sections {:sections [{:title "abc"}]}})))
Here we will repeat components inside a container.
Credits
Code heavily borrowed from [[https://github.com/swannodette/enlive-tutorial][enlive-tutorial]].
Resources