102 lines
No EOL
7 KiB
HTML
102 lines
No EOL
7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<title>CLiki: yaclml</title>
|
|
<link rel="alternate" type="application/atom+xml" title="ATOM feed of edits to current article"
|
|
href="https://www.cliki.net/site/feed/article.atom?title=yaclml">
|
|
<link rel="stylesheet" href="static/css/style.css">
|
|
<link rel="stylesheet" href="static/css/colorize.css">
|
|
</head>
|
|
|
|
<body>
|
|
<span class="hidden">CLiki - yaclml</span>
|
|
<div id="content"><div id="content-area"><div id="article-title">yaclml</div><div id="article">yaclml (Yet Another Common Lisp Markup Language) is an <a href="HTML generator.html" class="category">HTML generator</a> and <a href="HTML template.html" class="category">HTML template</a> library. yaclml is used as the html templating backend for the <a href="ucw.html" class="internal">ucw</a> <a href="web framework.html" class="internal">web framework</a>.<p>License: ?<p>Homepage: <a href="http://common-lisp.net/project/bese/yaclml.html">http://common-lisp.net/project/bese/yaclml.html</a><p>According to the <a href="http://common-lisp.net/project/bese/yaclml.html">yaclml website</a>, it appears darcs is the preferred method to get current versions:<p><pre>
|
|
darcs get http://common-lisp.net/project/bese/repos/yaclml/
|
|
</pre><p><h2>Getting the output</h2>
|
|
When you use the inline-html of yaclml, the rendered HTML gets printed, not returned. If you need to have it in a string, use the following:
|
|
<pre>
|
|
(yaclml:with-yaclml-output-to-string
|
|
(<:html (<:head (<:title "Hello, world"))
|
|
(<:body (<:h1 "Hello, world")
|
|
(<:p "Hello, world!!!!!!")))
|
|
</pre>
|
|
and you'll get a string.<p><h2>Using yaclml by itself</h2>
|
|
If you want, you can use yaclml by itself (not with <a href="ucw.html" class="internal">ucw</a>, maybe with another framework, like <a href="araneida.html" class="internal">araneida</a>) but it seems nobody is doing that so the library is not very friendly by itself: it is not really robust (in the sense that it is very easy to generate an error by providing not-so-carefully contructed input) and there's no documentation whatsoever. That last item I'll try to fix here.
|
|
Including yaclml as one of the dependecies of your package or by loading it (with (asdf:oos 'asdf:load-op :yaclml)) you can start using the yaclml-in-lisp markup, something like:
|
|
<pre>
|
|
(<:html (<:head (<:title "Hello, world"))
|
|
(<:body (<:h1 "Hello, world")
|
|
(<:p "Hello, world!!!!!!")))
|
|
</pre>
|
|
That wasn't so hard, was it ?
|
|
But one of the jewels of yaclml is <a href="https://www.cliki.net/tal" class="new">tal</a>. To be able to load TAL templates you need to perform the following steps. Create a generator:
|
|
<pre>
|
|
(defparameter *gen*
|
|
(make-instance 'yaclml:file-system-generator
|
|
:cachep nil
|
|
:root-directories (list "/path/to/my/templates/")))
|
|
</pre>
|
|
root-directories is where you will have the templates. I believe a relative path should work. For the whole run of the program one generator might be enough.
|
|
When you are about to generate a page, you need to generate an environment which will have the key-value pairs that can be used inside the template:
|
|
<pre>
|
|
(defparameter *env* (yaclml:make-standard-environment))
|
|
</pre>
|
|
That builds an empty environment. The mappings should be passed as the first parameter to make-standard-environment and according to yaclml documentation: "Each binding set can be an alist, an object, a hash table, or any object for which the a method on LOOKUP-TAL-VARIABLE has been
|
|
defined."
|
|
Then, we have to pick up the template itself:
|
|
<pre>
|
|
(defparameter *tem* (yaclml:load-tal *gen* "hello.html"))
|
|
</pre>
|
|
*tem* is a closure, that is, a function, that when run will return the result of "rendering" that template. It takes two parameters, a generator and an environment. If you evaluate *tem* you may get something like:
|
|
<pre>
|
|
# < CLOSURE (LAMBDA
|
|
(IT.BESE.YACLML::ENVIRONMENT
|
|
IT.BESE.YACLML::GENERATOR)) {BEB9355} >
|
|
</pre><p> One usefull function is yaclml:template-truename which returns the name of the template being picked up (or nil if none is found). When you have various root-directories it can help you find out which template is being chosen. For example:
|
|
<pre>
|
|
(yaclml:template-truename *gen* "hello.html")
|
|
</pre>
|
|
would return
|
|
<pre>
|
|
/path/to/my/templates/hello.html
|
|
</pre><p> Now we would call *tem* like this:
|
|
<pre>(funcall *tem* *env* *gen*)</pre>
|
|
and we would get out the page.<p><hr><p>yaclml generator tutorial: <a href="http://www.3ofcoins.net/2009/02/07/yaclml-in-pictures-part-i-html-generation/">http://www.3ofcoins.net/2009/02/07/yaclml-in-pictures-part-i-html-generation/</a><p>yaclml templating tutorial: <a href="http://www.3ofcoins.net/2010/01/21/yaclml-in-pictures-part-ii-templating/">http://www.3ofcoins.net/2010/01/21/yaclml-in-pictures-part-ii-templating/</a></div></div>
|
|
<div id="footer" class="buttonbar"><ul><li><a href="yaclml.html">Current version</a></li>
|
|
<li><a href="https://www.cliki.net/site/history?article=yaclml">History</a></li>
|
|
<li><a href="https://www.cliki.net/site/backlinks?article=yaclml">Backlinks</a></li><li><a href="https://www.cliki.net/site/edit-article?title=yaclml&from-revision=3686419793">Edit</a></li><li><a href="https://www.cliki.net/site/edit-article?create=t">Create</a></li></ul></div>
|
|
</div>
|
|
<div id="header-buttons" class="buttonbar">
|
|
<ul>
|
|
<li><a href="https://www.cliki.net/">Home</a></li>
|
|
<li><a href="https://www.cliki.net/site/recent-changes">Recent Changes</a></li>
|
|
<li><a href="CLiki.html">About</a></li>
|
|
<li><a href="Text Formatting.html">Text Formatting</a></li>
|
|
<li><a href="https://www.cliki.net/site/tools">Tools</a></li>
|
|
</ul>
|
|
<div id="search">
|
|
<form action="https://www.cliki.net/site/search">
|
|
<label for="search_query" class="hidden">Search CLiki</label>
|
|
<input type="text" name="query" id="search_query" value="" />
|
|
<input type="submit" value="search" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<div id="pageheader">
|
|
<div id="header">
|
|
<span id="logo">CLiki</span>
|
|
<span id="slogan">the common lisp wiki</span>
|
|
<div id="login"><form method="post" action="https://www.cliki.net/site/login">
|
|
<label for="login_name" class="hidden">Account name</label>
|
|
<input type="text" name="name" id="login_name" class="login_input" />
|
|
<label for= "login_password" class="hidden">Password</label>
|
|
<input type="password" name="password" id="login_password" class="login_input" />
|
|
<input type="submit" name="login" value="login" id="login_submit" /><br />
|
|
<div id="register"><a href="https://www.cliki.net/site/register">register</a></div>
|
|
<input type="submit" name="reset-pw" value="reset password" id="reset_pw" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body></html> |