-
Notifications
You must be signed in to change notification settings - Fork 151
Home
Enlive is an extraction and transformation library for HTML and XML documents written in Clojure. It uses CSS-like selectors.
Usual Enlive applications include screenscraping and templating.
The Enlive approach to templating is functional and decouples design and presentation logic.
Each template or template part (snippet) is a plain function thus you can easily compose templates. There is a kind of inversion of control here. In most mainstream templating systems, templates drive the presentation logic. Here the presentation logic drives templates.
Templates are backed by source files which are plain HTML (no special tags or attributes, no code). This allows for easy round-tripping with designers or easy theming of your app.
Google group or mail me if you can’t publicly discuss your issues.
Selectors are at the core of Enlive, the file syntax.html
at the root of the repository is a comprehensive syntax reference that can also be browsed online.
Enlive selectors are simply CSS selectors written in Clojure. A selector is always surrounded by square brackets: CSS div
is written [:div]
. span.bar a#foo
becomes [:span.bar :a#foo]
.
A trickiest to translate CSS selector is a[href]
which is [[:a (attr? :href)]]
with Enlive. No it’s not a typo, there are two pairs of square brackets. The outer one is the mandatory one (see above paragraph) and the inner one denotes intersection (aka and).
No support for namespaces.