BTL : The Beautiful Templating Language
<bjc> WOOT
<bjc> i was looking for something /just/ like that yesterday
<bjc> i was looking for something /just/ like that yesterday
- response from #lisp on freenode
BTL is a template language useful for html and other documents. It allows for excellent separation of code and presentation, and provides a very readable alternative to those "other" templating languages. Since it leverages the power of Common Lisp, you get these benefits:
- Compiled templates - Depending on your version of lisp, it can be compiled down to the machine language level
- Loops - Any kind you want
- Database access - with the appropriate libraries
- On-the-fly updating - just reload the file
I wrote this because I really liked the concept of BRL - the "Beautiful Report Language," but it had a few issues that prevented me from actually using it. BTL seeks to fix some of those issues, as well as provide an alternative for those who prefer Common Lisp over Scheme.
Download
The canonical BTL can be found at http://www.bitmuse.com/code/btl-0.1.0.tar.gz.
Example
Contents of the file 'test.html':
[(let ((myname "Azimuth") (my "Azimuth's"))
(btl ]
<pre>
This is [my] web page.
[myname myname
myname myname]
[my] favorite channel is [[#lisp].
[my] favorite number is [(random 10)].
</pre>
[))]
Within a common lisp environment:
* (defvar bork (btl:compile-template "test.html"))
#<FUNCTION "#'(LAMBDA (#:G2963) (LET # #))" {9D1BEAD}>
* (funcall bork *standard-output*)
<pre>
This is Azimuth's web page.
AzimuthAzimuthAzimuthAzimuth
Azimuth's favorite channel is [#lisp].
Azimuth's favorite number is 3.
</pre>
""
*
Todo
- Some error recovery might be nice - ideally it would output [ERROR: UNDEFINED-VARIABLE] or something when it hit one.
- Passing values via a "data" parameter is lame.
