Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the cl-template Reference Manual, version 0.0.1, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Dec 22 12:52:32 2020 GMT+0.
• Introduction | What cl-template is all about | |
• Systems | The systems documentation | |
• Files | The files documentation | |
• Packages | The packages documentation | |
• Definitions | The symbols documentation | |
• Indexes | Concepts, functions, variables and data types |
cl-template will be available on quicklisp sooner or later. Until then, just clone this repo and tell ASDF to find it. cl-template has no dependencies.
cl-template is yet another template engine for Common Lisp, taking inspiration from Ruby's ERb module. It differs from other template engines in that:
The most distictive feature of cl-template is that it can infer the outermost set of parenthesis, to make your templates look a little cleaner. For example,
<ul class="person-list">
<% (loop for person in (@ people) do
<li><%= (name person) %>
<% ) %>
</ul>
can be written as
<ul class="person-list">
<% loop for person in (@ people) do %>
<li><%= name person %></li>
<% end %>
</ul>
The only deviations from pure Common Lisp are:
end
can function as a close parenthesisprogn
is automatically inserted into if
expressionselse
separates clauses of an if
expressionAll of these are optional - you can choose not to use them at all. However, they tend to make templates easier to read and are recommended.
The rules for paren inference are:
@
is the macro to get a variable from the data provided at runtime.
Some more examples:
{"articles": [
<% loop for article in (@ articles) do %>
{"id": <%= id article %>, "title": <%= title article %>, "body": <%= body article %>}
<% end %>
]}
<!-- Don't use any optional features, just plain Lisp. Be sure to set clt:*add-progn-to-if* to nil first. -->
<% (if (comments (@ article)) %>
<% (progn
<ul id="article-<%= (id (@ article)) %>-comments" class="comments">
<% (loop for comment in (comments (@ article)) do %>
<li id="comment-<%= (id comment) %>" class="comment">
<%= (author comment) %> said
<p><%= (body comment) %></p>
</li>
<% ) %>
</ul>
<% ) %>
<% (progn %>
No comments! <a href="<%= link :new-comment %>">Add a comment.</a>
<% ) %>
<% ) %>
All of cl-template's functionality is exposed through one function,
#'compile-template
.
(compile-template string &key (start-delimiter "<%") (start-echo-delimiter "<%=") (end-delimiter "%>"))
This returns a lambda which must be called with a plist as the sole
argument, which provides the data for the template. This is available
within the template as cl-template::__data
but it is not recommended
to use directly. (Although it is useful for things like iterating over
all data the template gets, but that sort of thing is rare.) A better
idea is to use the built-in @
macro, which looks up a keyword
version of its argument in the data plist.
Usage example:
(with-open-file (template-file "views/person.html.clt")
(let ((template (make-string (file-length template-file)))
(person (get-person-from-database-somehow)))
(read-sequence template template-file)
(funcall (cl-template:compile-template template) (list :person person))))
#'compile-template
does not yet cache the resulting function.
Additionally, to disable automatically adding a progn
to if
expressions set *add-progn-to-if*
to nil
.
cl-template is licensed under the MIT license.
Copyright (c) 2013 Peter Cannici
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The cl-template system |
Peter Cannici <turkchess123@gmail.com>
MIT
A simple output-agnostic templating system for Common Lisp.
0.0.1
cl-template.asd (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files |
• The cl-template.asd file | ||
• The cl-template/packages.lisp file | ||
• The cl-template/util.lisp file | ||
• The cl-template/cl-template.lisp file |
Next: The cl-template/packages․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
cl-template.asd
cl-template (system)
Next: The cl-template/util․lisp file, Previous: The cl-template․asd file, Up: Lisp files [Contents][Index]
cl-template (system)
packages.lisp
Next: The cl-template/cl-template․lisp file, Previous: The cl-template/packages․lisp file, Up: Lisp files [Contents][Index]
packages.lisp (file)
cl-template (system)
util.lisp
Previous: The cl-template/util․lisp file, Up: Lisp files [Contents][Index]
cl-template (system)
cl-template.lisp
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The cl-template-template-symbols package | ||
• The cl-template package |
Next: The cl-template package, Previous: Packages, Up: Packages [Contents][Index]
packages.lisp (file)
common-lisp
Previous: The cl-template-template-symbols package, Up: Packages [Contents][Index]
packages.lisp (file)
clt
common-lisp
Definitions are sorted by export status, category, package, and then by lexicographic order.
• Exported definitions | ||
• Internal definitions |
Next: Internal definitions, Previous: Definitions, Up: Definitions [Contents][Index]
• Exported special variables | ||
• Exported functions |
Next: Exported functions, Previous: Exported definitions, Up: Exported definitions [Contents][Index]
Boolean; whether or not to implicitly add a progn to IF expressions.
cl-template.lisp (file)
Previous: Exported special variables, Up: Exported definitions [Contents][Index]
Compile a string template into a lambda, which can be invoked with
a plist as the only argument and provides data to the template. The
data argument to the lambda is available in the template as
‘cl-template::__data‘, although it’s not recommended to use it
directly. See README.md for examples of the template syntax.
It caches the result of the compilation.
Examples:
(compile-template "the number is <%= (@ number) %>") ; (lambda (__data) ...)
(compile-template "{{= @ mood }} shark" :start-delimiter "{{" :start-echo-delimiter "{{=" :end-delimiter "}}") ; (lambda (__data) ...)
(funcall (compile-template "<%= format nil "~@r" (@ number) %>") ’(:number 12)) ; "XII"
cl-template.lisp (file)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal special variables | ||
• Internal functions |
Next: Internal functions, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
Hash table which compiled template functions are cached in.
cl-template.lisp (file)
Previous: Internal special variables, Up: Internal definitions [Contents][Index]
cl-template.lisp (file)
cl-template.lisp (file)
cl-template.lisp (file)
cl-template.lisp (file)
cl-template.lisp (file)
cl-template.lisp (file)
cl-template.lisp (file)
Count the occurences of a pair (e.g. []) in a string, ignoring any that occur in between pairs of ‘ignore-list‘.
Example:
(match-pairs-ignoring "(something)" ’(#( . #))) ; t
(match-pairs-ignoring "[that <thing]>" ’(#[ . #]) :ignore-list ’((#< . #>))) ; nil
util.lisp (file)
Scan a string and return a substring between the two delimiter substrings.
Example:
(scan-between-delimiters "abc <%= thingy %> def" "<%=" "%>") ; " thingy "
(scan-between-delimiters "what{{ever stuff<ignor{{ing>{{now}}xyz" :ignore-list ’((#< . #>)) :start 10) ; "now"
util.lisp (file)
Scan a string until a substring is encountered, ignoring anything
between ignore-list pairs. Probably not super-useful outside of
CLT. In CLT it is used to scan until the next end delimiter while
ignoring things in quotes.
Example:
(scan-string-until-ignoring "abc|def" "|") ; "abc"
(scan-string-until-ignoring "abc <ignor|ing> def" "|" :ignore-list ’((#< . #>))) ; "abc <ignor|ing> def"
util.lisp (file)
Previous: Definitions, Up: Top [Contents][Index]
• Concept index | ||
• Function index | ||
• Variable index | ||
• Data type index |
Next: Function index, Previous: Indexes, Up: Indexes [Contents][Index]
Jump to: | C F L |
---|
Jump to: | C F L |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | A C F H I M S |
---|
Jump to: | A C F H I M S |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | *
S |
---|
Jump to: | *
S |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | C P S |
---|
Jump to: | C P S |
---|