Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the eco Reference Manual, version 0.1, generated automatically by Declt version 3.0 "Montgomery Scott" on Thu Mar 11 13:10:42 2021 GMT+0.
• Introduction | What eco is all about | |
• Systems | The systems documentation | |
• Modules | The modules documentation | |
• Files | The files documentation | |
• Packages | The packages documentation | |
• Definitions | The symbols documentation | |
• Indexes | Concepts, functions, variables and data types |
A basic template (.eco
extension) looks like this:
<% deftemplate index (title &optional posts) () %>
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body>
<% if posts %>
<h1>Recent Posts</h1>
<ul id="post-list">
<% loop for (title . snippet) in posts do %>
<li><%= title %> - <%= snippet %></li>
<% end %>
</ul>
<% else %>
<span>No recent posts.</span>
<% end %>
</body>
</html>
<% end %>
To load this template, put this in your system definition file:
(:eco-template "filename")
For interactive or quick tests on the REPL, templates can be loaded using ECO:COMPILE-STRING,
(eco:compile-string "<% deftemplate inline-test () () %>This is a test.<% end %>")
All templates are eventually compiled into Lisp functions. To get their outputs, call the templates like any Lisp function:
(eco-template:index "My Blog" nil)
Eco is designed to be output-agnostic, however, by default it will autoescape HTML for convenience. Specify :ESCAPE-HTML NIL when defining each template to disable this behaviour individually for each template.
<% deftemplate output-js-logger (module) (:escape-html nil) %>
function logDebug (message) {
console.log("<%= module %>: " + message);
}
<% end %>
There are three types of tags in Eco:
<%= <expr> %>
becomes <expr>
.<% <code> <arg1> <arg2> %><body><% end %>
becomes (<code> <arg1> <arg2> <body>)
.<%- <fun> <arg1> <arg2> %><body><% end %>
becomes (<fun> <arg1> <arg2> <body>)
.Blocks are used to specify Lisp code "inline" in the template, and tend to contain imperative code, their return values are ignored. Expressions and calls are more functional as they return values to be interpolated into their templates. The function called by the CALL construct may be another templates, or any arbitrary Lisp function.
The if
tag is a special case: it supports using an else
tag to separate the true and
false branches. For example:
<% if posts %>
<h1>Recent Posts</h1>
... loop over posts ...
<% else %>
No recent posts.
<% end %>
*template-package*
: The package the templates will be defined it. Defaults
to :eco-template
.deftemplate
Syntax:
<% deftemplate name (&rest args) (&rest options) %>
<body>
<% end %>
Defines a template. The only option that is currently defined is :ESCAPE-HTML (default T)
if
Syntax:
<% if cond %>
true branch
<% else %>
false branch
<% end %>
Eco uses esrap to parse templates, which it then compiles down to Common Lisp code.
Copyright (c) 2014-2019 Fernando Borretti (fernando@borretti.me)
Licensed under the MIT License.
Next: Modules, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The eco system |
Fernando Borretti
MIT
Fast, flexible, designer-friendly templates.
# Eco - Fast, flexible, designer-friendly templates.
[](https://travis-ci.org/eudoxia0/eco)
# Goals
- **Simple:** Eco is essentially just a string concatenator. It introduces no
constructs of its own: Every tag is pure Common Lisp code, plain and simple.
- **Easy to Use:** Proper use of Eco should not require more than a
cursory read of this README from time to time.
- **Designer-friendly:** Lispers have written template engine after template
engine that turns S-expressions into HTML. Which is great, if you’re a
lisper. Eco is meant to be used for more than HTML and also to be usable to
the many designers and programmers who don’t know the language and should not
be expected to learn an obscure template syntax to be able to contribute.
- **Performance:** Eco uses the many performance advantages of Common
Lisp. Templates are not interpreted or run in a VM, but compiled to Common
Lisp, which is then compiled down to efficient machine code. By making each
template a function that takes an (Optionally typed) argument list rather than
passing an environment hash table like most other template engines, one can
leverage the type inference features of modern Common Lisp implementations to
create performant templates.
# Usage
A basic template (‘.eco‘ extension) looks like this:
“‘erb
<% deftemplate index (title &optional posts) () %>
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body>
<% if posts %>
<h1>Recent Posts</h1>
<ul id="post-list">
<% loop for (title . snippet) in posts do %>
<li><%= title %> - <%= snippet %></li>
<% end %>
</ul>
<% else %>
<span>No recent posts.</span>
<% end %>
</body>
</html>
<% end %>
“‘
To load this template, put this in your system definition file:
“‘lisp
(:eco-template "filename")
“‘
For interactive or quick tests on the REPL, templates can be loaded
using ECO:COMPILE-STRING,
“‘lisp
(eco:compile-string "<% deftemplate inline-test () () %>This is a test.<% end %>")
“‘
All templates are eventually compiled into Lisp functions. To get
their outputs, call the templates like any Lisp function:
“‘lisp
(eco-template:index "My Blog" nil)
“‘
Eco is designed to be output-agnostic, however, by default it will
autoescape HTML for convenience. Specify :ESCAPE-HTML NIL when
defining each template to disable this behaviour individually for each
template.
“‘erb
<% deftemplate output-js-logger (module) (:escape-html nil) %>
function logDebug (message) {
console.log("<%= module %>: " + message);
}
<% end %>
“‘
# Tags
There are three types of tags in Eco:
- Expressions: ‘<%= <expr> %>‘ becomes ‘<expr>‘.
- Blocks: ‘<% <code> <arg1> <arg2> %><body><% end %>‘ becomes ‘(<code> <arg1> <arg2> <body>)‘.
- Calls: ‘<%- <fun> <arg1> <arg2> %><body><% end %>‘ becomes ‘(<fun> <arg1> <arg2> <body>)‘.
Blocks are used to specify Lisp code "inline" in the template, and
tend to contain imperative code, their return values are ignored.
Expressions and calls are more functional as they return values to be
interpolated into their templates. The function called by the CALL
construct may be another templates, or any arbitrary Lisp function.
The ‘if‘ tag is a special case: it supports using an ‘else‘ tag to separate the true and
false branches. For example:
“‘lisp
<% if posts %>
<h1>Recent Posts</h1>
... loop over posts ...
<% else %>
No recent posts.
<% end %>
“‘
# Options
- ‘*template-package*‘: The package the templates will be defined it. Defaults
to ‘:eco-template‘.
# Reference
## ‘deftemplate‘
**Syntax:**
“‘erb
<% deftemplate name (&rest args) (&rest options) %>
<body>
<% end %>
“‘
Defines a template. The only option that is currently defined is
:ESCAPE-HTML (default T)
# Examples
## ‘if‘
**Syntax:**
“‘erb
<% if cond %>
true branch
<% else %>
false branch
<% end %>
“‘
# Implementation
Eco uses esrap to parse templates, which it then compiles down to Common Lisp
code.
# License
Copyright (c) 2014-2019 Fernando Borretti (fernando@borretti.me)
Licensed under the MIT License.
0.1
eco.asd (file)
src (module)
Modules are listed depth-first from the system components tree.
• The eco/src module |
eco (system)
src/
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files |
• The eco.asd file | ||
• The eco/src/parser.lisp file | ||
• The eco/src/compiler.lisp file | ||
• The eco/src/asdf.lisp file | ||
• The eco/src/eco.lisp file |
Next: The eco/src/parser․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
eco.asd
eco (system)
Next: The eco/src/compiler․lisp file, Previous: The eco․asd file, Up: Lisp files [Contents][Index]
src (module)
src/parser.lisp
Next: The eco/src/asdf․lisp file, Previous: The eco/src/parser․lisp file, Up: Lisp files [Contents][Index]
parser.lisp (file)
src (module)
src/compiler.lisp
Next: The eco/src/eco․lisp file, Previous: The eco/src/compiler․lisp file, Up: Lisp files [Contents][Index]
compiler.lisp (file)
src (module)
src/asdf.lisp
Previous: The eco/src/asdf․lisp file, Up: Lisp files [Contents][Index]
asdf.lisp (file)
src (module)
src/eco.lisp
generic-compile (function)
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The eco.parser package | ||
• The eco-template package | ||
• The eco.compiler package | ||
• The eco package |
Next: The eco-template package, Previous: Packages, Up: Packages [Contents][Index]
parser.lisp (file)
Next: The eco․compiler package, Previous: The eco․parser package, Up: Packages [Contents][Index]
compiler.lisp (file)
common-lisp
Next: The eco package, Previous: The eco-template package, Up: Packages [Contents][Index]
compiler.lisp (file)
compile-template (function)
Previous: The eco․compiler package, Up: Packages [Contents][Index]
eco.lisp (file)
common-lisp
generic-compile (function)
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 macros | ||
• Exported functions | ||
• Exported generic functions | ||
• Exported classes |
Next: Exported functions, Previous: Exported definitions, Up: Exported definitions [Contents][Index]
compiler.lisp (file)
Next: Exported generic functions, Previous: Exported macros, Up: Exported definitions [Contents][Index]
compiler.lisp (file)
Escape a string.
compiler.lisp (file)
parser.lisp (file)
parser.lisp (file)
Next: Exported classes, Previous: Exported functions, Up: Exported definitions [Contents][Index]
automatically generated reader method
parser.lisp (file)
automatically generated reader method
parser.lisp (file)
automatically generated reader method
parser.lisp (file)
automatically generated reader method
parser.lisp (file)
Previous: Exported generic functions, Up: Exported definitions [Contents][Index]
parser.lisp (file)
standard-object (class)
<call> (class)
:code
code (generic function)
:body
body (generic function)
parser.lisp (file)
<block> (class)
emit (method)
parser.lisp (file)
<tag> (class)
parser.lisp (file)
<tag> (class)
:code
code (generic function)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal special variables | ||
• Internal functions | ||
• Internal generic functions | ||
• Internal classes |
Next: Internal functions, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
compiler.lisp (file)
parser.lisp (file)
Next: Internal generic functions, Previous: Internal special variables, Up: Internal definitions [Contents][Index]
compiler.lisp (file)
compiler.lisp (file)
parser.lisp (file)
compiler.lisp (file)
parser.lisp (file)
compiler.lisp (file)
parser.lisp (file)
parser.lisp (file)
Next: Internal classes, Previous: Internal functions, Up: Internal definitions [Contents][Index]
compiler.lisp (file)
compiler.lisp (file)
compiler.lisp (file)
compiler.lisp (file)
compiler.lisp (file)
Previous: Internal generic functions, Up: Internal definitions [Contents][Index]
parser.lisp (file)
<tag> (class)
<call-tag> (class)
code (method)
:code
code (generic function)
parser.lisp (file)
<block-tag> (class)
parser.lisp (file)
<tag> (class)
parser.lisp (file)
standard-object (class)
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: | E F L M |
---|
Jump to: | E F L M |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | B C D E F G M P R S T W |
---|
Jump to: | B C D E F G M P R S T W |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | *
+
B C S |
---|
Jump to: | *
+
B C S |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | <
C E P S |
---|
Jump to: | <
C E P S |
---|