Decoding Clojure
jacquesmattheij.com
jacquesmattheij.com
The problem (to me) is that s-exprs just make sense for representing HTML. Every time I've tried to think of how a "perfect" templating language would look for Clojure, all options have seemed silly next to just using Lisp. I guess that's part of its charm (and its curse).
[Enlive: http://github.com/cgrand/enlive]
I can just imagine the look the average designer would give if you passed them a chunk of lisp and asked them to style this according the house style manual.
There is definitely something attractive about transforming HTML as code, but yeah, I really wouldn't want to hand a designer a chunk of lisp to work with.
It's just matter of convention - designer should know what he can change, and what he cannot - lisp-encoded html is almost like normal html, and has the adventage of being compiled - some static checking can be done.
When you extract data producing into functions only called b name in code that is emiting html it will lokk just like html template, and it has all the clojure power when it's needed.
http://www.stringtemplate.org/
Example of using StringTemplate with Clojure: http://www.reddit.com/r/Clojure/comments/ablcc/string_interp...
If you write your own html then compojure is, without question, the way to go. S-expressions require less typing than html and you can write functions or define snippets that build webpages up without the need to repeat yourself. Its an end to copy and paste. Also, stylesheets are your friend and can do most of the work of presentation.
If you work with designers who require full access to the HTML then Enlive is a good option -- as you said there is no template code in with the html! Surely this is a step forwards from custom comment fields or custom tags?
I like the concept of Enlive, but I have concerns about troubleshooting it. I feel like you're asking for trouble any time you have to look at multiple files just to figure out what's going on in one page. Troubleshooting a page that's been modified with Enlive would require you to have the HTML open, and then mentally translate all the operations so that you can see what changes what. I'm just not smart enough to be able to hold entire documents in my head when things approach even moderate complexity, and I want to be able to scan a document to see what's going on; not read the HTML document and then go through the list of operations to see how that document is being modified.
P.S. I see clojure uses // for a comment, a la C++; See if it accepts semi-colons as well. That's quicker to type and easier on the eye.
(He has a bunch more content here: http://java.ociweb.com/mark/clojure/ )
There is only one book out there currently, but it's pretty good: "Programming Clojure" by Stuart Sierra (there are 3 more coming, see below)
http://pragprog.com/titles/shcloj/programming-clojure
--------------------------
Upcoming books:
○ Clojure in Action - http://manning.com/rathore/
○ The Joy of Clojure - http://manning.com/fogus/
○ Practical Clojure - http://apress.com/book/view/1430272317
This one is free and well worth the look: http://www.bestinclass.dk/index.php/2009/12/clojure-101-gett...
It would save me a ton of time when looking at code I do not yet understand.