1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
<html>
<head>
<title>Templayer 1.4 Reference</title>
<style type="text/css">
h1 { text-align: center; }
h2 { margin: 40px 0 0 0; padding: 10px; background: #6d96e8;}
h3 { margin: 0 0 3px 0; padding: 12px 6px 6px 6px; background: #efef96;}
.l1 { margin: 12px 0 0 0; }
.l2 { margin-left: 20px; }
</style>
<body>
<a name="top"></a>
<h1>Templayer 1.4 Reference</h1>
<div style="text-align: center;">
<a href="http://excess.org/templayer/">Templayer Home Page</a> /
<a href="tutorial.html">Tutorial</a> /
Reference
</div>
<br>
<table width="100%"><tr><td width="50%" valign="top"><div class="l1">Template classes</div><div class="l2"><a href="#Template">Template</a></div><div class="l2"><a href="#HTMLTemplate">HTMLTemplate</a></div><div class="l1">Layer classes</div><div class="l2"><a href="#FileLayer">FileLayer</a></div><div class="l2"><a href="#Layer">Layer</a></div><div class="l1">HTML Markup</div><div class="l2"><a href="#expand_html_markup">expand_html_markup</a></div><div class="l2"><a href="#RawHTML">RawHTML</a></div></td><td width="50%" valign="top"><div class="l1">Utility functions</div><div class="l2"><a href="#html_url_encode">html_url_encode</a></div><div class="l2"><a href="#html_href">html_href</a></div><div class="l2"><a href="#html_target">html_target</a></div><div class="l2"><a href="#html_escape">html_escape</a></div><div class="l2"><a href="#django_form">django_form</a></div></td></tr></table>
<br>
<h2>Template classes</h2><h3><a name="Template">class <strong>Template</strong></a> <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3>Methods defined here:<br>
<dl><dt><a name="Template-__init__"><strong>__init__</strong></a>(self, name, from_string<font color="#909090">=False</font>, auto_reload<font color="#909090">=None</font>, allow_degenerate<font color="#909090">=False</font>)</dt><dd><tt>name -- template file name or file-like object<br>
from_string -- if True treat name as a string containing the<br>
template data instead of a file to read from<br>
auto_reload -- if the template has not been checked in this<br>
many seconds then check it and reload if there<br>
are any changes. If None only load the <br>
template file once.<br>
<br>
Checking and reloading is done by the <br>
start_file() function.<br>
<br>
Ignored if from_string is True or if name is a <br>
file-like object.<br>
allow_degenerate -- If True then template is allowed to not<br>
have a {contents}...{/contents} block. In this<br>
case the entire file is available as a layer<br>
called '*'. eg. l = tmpl.format('*', ...)</tt></dd></dl>
<dl><dt><a name="Template-finalize"><strong>finalize</strong></a>(self, value)</dt><dd><tt>Return unwrapped value as a string.<br>
<br>
Override this function to reverse wrapping applied before<br>
sending to the output file.</tt></dd></dl>
<dl><dt><a name="Template-format"><strong>format</strong></a>(self, layer_name, **args)</dt><dd><tt>Return a layer with slots filled by args.</tt></dd></dl>
<dl><dt><a name="Template-format_header_footer"><strong>format_header_footer</strong></a>(self, **args)</dt><dd><tt>Returns header and footer with slots filled by args.</tt></dd></dl>
<dl><dt><a name="Template-layer"><strong>layer</strong></a>(self, name)</dt><dd><tt>Return the complete layer named name as a string.</tt></dd></dl>
<dl><dt><a name="Template-layer_split"><strong>layer_split</strong></a>(self, name)</dt><dd><tt>Return the layer named name split on SLOT_MARKs.</tt></dd></dl>
<dl><dt><a name="Template-missing_slot"><strong>missing_slot</strong></a>(self, names, layer)</dt><dd><tt>Called when one or more slots are not found in a layer.</tt></dd></dl>
<dl><dt><a name="Template-post_process"><strong>post_process</strong></a>(self, value)</dt><dd><tt>Returns wrapped value.<br>
<br>
Override to wrap processed text in order to mark it as <br>
having been processed.</tt></dd></dl>
<dl><dt><a name="Template-pre_process"><strong>pre_process</strong></a>(self, key, value)</dt><dd><tt>Returns key, filtered/escaped value.<br>
<br>
Override this function to provide escaping or filtering of<br>
text sent from the module user.</tt></dd></dl>
<dl><dt><a name="Template-reload_template"><strong>reload_template</strong></a>(self)</dt><dd><tt>Reload the template data from the template file.</tt></dd></dl>
<dl><dt><a name="Template-set_template_data"><strong>set_template_data</strong></a>(self, tmpl)</dt><dd><tt>Parse and store the template data passed.</tt></dd></dl>
<dl><dt><a name="Template-start_file"><strong>start_file</strong></a>(self, file<font color="#909090">=None</font>)</dt><dd><tt>Return a FileLayer object that uses this template.<br>
<br>
file -- file object or None to use sys.stdout.<br>
<br>
If self.<strong>auto_reload</strong> is not None this function will first <br>
check and reload the template file if it has changed.</tt></dd></dl>
<dl><dt><a name="Template-template_file_changed"><strong>template_file_changed</strong></a>(self)</dt><dd><tt>Return True if the template file has been modified since<br>
the last time it was loaded.</tt></dd></dl>
<h3><a name="HTMLTemplate">class <strong>HTMLTemplate</strong></a>(Template) <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3>Methods defined here:<br>
<dl><dt><a name="HTMLTemplate-finalize"><strong>finalize</strong></a>(self, value)</dt><dd><tt>Unwrap RawHTML object value for output.</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-post_process"><strong>post_process</strong></a>(self, value)</dt><dd><tt>Wrap value in RawHTML object.</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-pre_process"><strong>pre_process</strong></a>(self, key, value)</dt><dd><tt>Use expand_html_markup to process value.</tt></dd></dl>
<hr>
Methods inherited from Template:<br>
<dl><dt><a name="HTMLTemplate-__init__"><strong>__init__</strong></a>(self, name, from_string<font color="#909090">=False</font>, auto_reload<font color="#909090">=None</font>, allow_degenerate<font color="#909090">=False</font>)</dt><dd><tt>name -- template file name or file-like object<br>
from_string -- if True treat name as a string containing the<br>
template data instead of a file to read from<br>
auto_reload -- if the template has not been checked in this<br>
many seconds then check it and reload if there<br>
are any changes. If None only load the <br>
template file once.<br>
<br>
Checking and reloading is done by the <br>
start_file() function.<br>
<br>
Ignored if from_string is True or if name is a <br>
file-like object.<br>
allow_degenerate -- If True then template is allowed to not<br>
have a {contents}...{/contents} block. In this<br>
case the entire file is available as a layer<br>
called '*'. eg. l = tmpl.format('*', ...)</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-format"><strong>format</strong></a>(self, layer_name, **args)</dt><dd><tt>Return a layer with slots filled by args.</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-format_header_footer"><strong>format_header_footer</strong></a>(self, **args)</dt><dd><tt>Returns header and footer with slots filled by args.</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-layer"><strong>layer</strong></a>(self, name)</dt><dd><tt>Return the complete layer named name as a string.</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-layer_split"><strong>layer_split</strong></a>(self, name)</dt><dd><tt>Return the layer named name split on SLOT_MARKs.</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-missing_slot"><strong>missing_slot</strong></a>(self, names, layer)</dt><dd><tt>Called when one or more slots are not found in a layer.</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-reload_template"><strong>reload_template</strong></a>(self)</dt><dd><tt>Reload the template data from the template file.</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-set_template_data"><strong>set_template_data</strong></a>(self, tmpl)</dt><dd><tt>Parse and store the template data passed.</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-start_file"><strong>start_file</strong></a>(self, file<font color="#909090">=None</font>)</dt><dd><tt>Return a FileLayer object that uses this template.<br>
<br>
file -- file object or None to use sys.stdout.<br>
<br>
If self.<strong>auto_reload</strong> is not None this function will first <br>
check and reload the template file if it has changed.</tt></dd></dl>
<dl><dt><a name="HTMLTemplate-template_file_changed"><strong>template_file_changed</strong></a>(self)</dt><dd><tt>Return True if the template file has been modified since<br>
the last time it was loaded.</tt></dd></dl>
<h2>Layer classes</h2><h3><a name="FileLayer">class <strong>FileLayer</strong></a> <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3>Methods defined here:<br>
<dl><dt><a name="FileLayer-__init__"><strong>__init__</strong></a>(self, file, template)</dt><dd><tt>file -- output stream or None to use sys.stdout<br>
template -- template object for generating this file<br>
<br>
This constructor is usually not called directly. Use<br>
template.start_file() to create a FileLayer instead.</tt></dd></dl>
<dl><dt><a name="FileLayer-close"><strong>close</strong></a>(self)</dt><dd><tt>Close all child layers and flush the output to the output <br>
stream. This function must be called to generate a complete<br>
file.<br>
<br>
Returns the file object where output was sent.</tt></dd></dl>
<dl><dt><a name="FileLayer-flush"><strong>flush</strong></a>(self)</dt><dd><tt>Flush as much output as possible to the output stream.</tt></dd></dl>
<dl><dt><a name="FileLayer-open"><strong>open</strong></a>(self, **args)</dt><dd><tt>Return a new layer representing the content between the<br>
header and footer. Use keyword arguments to fill the<br>
slots in the header and footer.</tt></dd></dl>
<h3><a name="Layer">class <strong>Layer</strong></a> <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3>Methods defined here:<br>
<dl><dt><a name="Layer-__init__"><strong>__init__</strong></a>(self, template, header, footer)</dt><dd><tt>template -- template object for generating this layer<br>
header -- text before the content of this layer<br>
footer -- text after the content of this layer<br>
<br>
This constructor should not be called directly. Use<br>
the open() function in a FileLayer or the open_layer()<br>
function in another Layer object to create a new Layer.</tt></dd></dl>
<dl><dt><a name="Layer-close"><strong>close</strong></a>(self)</dt><dd><tt>Close this layer and return its output.<br>
<br>
This function should not be called directly. Use the<br>
close() function in the FileLayer object instead.</tt></dd></dl>
<dl><dt><a name="Layer-close_child"><strong>close_child</strong></a>(self)</dt><dd><tt>If we have an open child layer close it and add its<br>
output to our own.</tt></dd></dl>
<dl><dt><a name="Layer-flush"><strong>flush</strong></a>(self)</dt><dd><tt>Flush as much output as possible and return it.<br>
<br>
This function should not be called directly. Use the<br>
flush() function in the FileLayer object instead.</tt></dd></dl>
<dl><dt><a name="Layer-open_layer"><strong>open_layer</strong></a>(self, layer, **args)</dt><dd><tt>layer -- name of layer in the template to open<br>
Use keyword arguments to fill this layer's slots.<br>
<br>
open_layer( layer name, ** args ) -> child Layer object<br>
<br>
open a layer as a child of this one, filling its slots with<br>
values from args</tt></dd></dl>
<dl><dt><a name="Layer-write"><strong>write</strong></a>(self, text)</dt><dd><tt>text -- text or markup as interpreted by the template</tt></dd></dl>
<dl><dt><a name="Layer-write_layer"><strong>write_layer</strong></a>(self, layer, **args)</dt><dd><tt>layer -- name of layer in the template to write<br>
Use keyword arguments to fill this layer's slots.</tt></dd></dl>
<h2>HTML Markup</h2><a name="expand_html_markup"></a><h3>function expand_html_markup <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3><dl><dt><a name="-expand_html_markup"><strong>expand_html_markup</strong></a>(v)</dt><dd><tt>Return an HTML string based on markup v.<br>
<br>
HTML markup is expanded recursively. Each of the content<br>
values below are passed to expand_html_markup again before <br>
applying the operation on the right:<br>
<br>
string or unicode string -> HTML-escaped version of string<br>
[content1, content2, ...] -> concatenate content1, content2, ...<br>
('join',list,sep) -> join items in list with seperator sep<br>
('pluralize',count,singular_content,plural_content)<br>
-> if count == 1 use singular_content,<br>
otherwise use plural_content<br>
('urljoin',head,tail) -> join safe url head with unsafe url-ending tail<br>
('href',link,content) -> HTML href to link wrapped around content<br>
('target',name) -> HTML target name<br>
('br',) -> HTML line break<br>
('br',count) -> HTML line break * count<br>
('p',) -> HTML paragraph break<br>
('p',content) -> HTML paragraph<br>
('i',content) -> italics<br>
('b',content) -> bold<br>
('u',content) -> underline<br>
('&',entity) -> HTML entity (entity has no & or ;)<br>
RawHTML(value) -> value unmodified</tt></dd></dl>
<h3><a name="RawHTML">class <strong>RawHTML</strong></a> <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3>Methods defined here:<br>
<dl><dt><a name="RawHTML-__init__"><strong>__init__</strong></a>(self, value)</dt><dd><tt>value -- segment of HTML as a string</tt></dd></dl>
<dl><dt><a name="RawHTML-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
<h2>Utility functions</h2><a name="html_url_encode"></a><h3>function html_url_encode <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3><dl><dt><a name="-html_url_encode"><strong>html_url_encode</strong></a>(text, query<font color="#909090">=False</font>)</dt><dd><tt>text -- text to be included as part of a URL<br>
query -- if True use "+" instead ot "%20" for spaces</tt></dd></dl>
<a name="html_href"></a><h3>function html_href <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3><dl><dt><a name="-html_href"><strong>html_href</strong></a>(link, value)</dt><dd><tt>Return '<a href="link">value</a>'.<br>
<br>
Neither link nor value is escaped by this function.</tt></dd></dl>
<a name="html_target"></a><h3>function html_target <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3><dl><dt><a name="-html_target"><strong>html_target</strong></a>(target, caption)</dt><dd><tt>Return '<a name="target">caption</a>'.<br>
<br>
Neither target nor caption is escaped by this function.</tt></dd></dl>
<a name="html_escape"></a><h3>function html_escape <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3><dl><dt><a name="-html_escape"><strong>html_escape</strong></a>(text)</dt><dd><tt>text -- text to be escaped for inclusion within HTML.</tt></dd></dl>
<a name="django_form"></a><h3>function django_form <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3><dl><dt><a name="-django_form"><strong>django_form</strong></a>(form, errors<font color="#909090">=True</font>, join_errors<font color="#909090">=<function <lambda>></font>)</dt><dd><tt>Converts a django FormWrapper object to a dictionary that<br>
can be used by Templayer. Each field is rendered into a<br>
%form.NAME% slot.<br>
<br>
If errors is True then this function will also render<br>
errors into %form.NAME.errors% slots.<br>
<br>
When there is more than one error on a single field the<br>
errors will be joined with the join_errors function.<br>
The default join_errors function puts a newline between each<br>
error.<br>
<br>
eg:<br>
If tmpl is an HTMLTemplate object with a {form_layer} layer<br>
and form is a FormWrapper object with username and password<br>
fields, then this code will fill the {form_layer} layer's <br>
%title%, %form.username%, %form.password%, <br>
%form.username.errors% and %form.password.errors% slots:<br>
<br>
tmpl.format('form_layer', title="hello", **django_form(form))</tt></dd></dl>
</body>
</html>
|