On Thu, Oct 29, 2009 at 12:26 AM, Saul <sha...@gmail.com> wrote:
>
> Hello,
> I was looking through the source of Enlive and it seems to me that
> it is possible to read in templates at compile time:
>
> (defmacro template
> "A template returns a seq of string."
> ([source args & forms]
> `(comp emit* (snippet* (html-resource ~source) ~args ~@forms))))
>
> Could become something like:
>
> (defmacro template
> "A template returns a seq of string."
> ([source args & forms]
> (let [ html (html-resource ~source) ]
> `(comp emit* (snippet* ~html ~args ~@forms))))
In earlier revisions, Enlive was less dynamic than now. I was trying
to do too much at compile time, including reading templates... at the
cost of flexibility.
One obvious gain is the one stated by Meikel: you can have a compiled
clojure app and "theme" it by replacing/customizing html files.
Generally, reading templates at compile-time precludes dynamic
sources. (eg removing unnecessary nodes, using a dynamic selector to
select a widget, etc.).
On perfs: the source backing the template is read when the template is
initialized, not at each invocation so it's not really compile-time vs
run-time but compile-time vs init-time.
Using the current (dynamic) building bricks provided by Enlive, it may
well be possible, and even interesting, to construct a more static
system like the one you envision but I won't change the current
template and snippet since it would reduce their applicability.
Christophe
--
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (en)