File: processors.html

package info (click to toggle)
cubictemp 2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 264 kB
  • ctags: 139
  • sloc: python: 682; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 3,574 bytes parent folder | download
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta  content="text/html; charset=utf-8" http-equiv="Content-Type"/><link  href="static/yui/fonts/fonts.css" type="text/css" rel="StyleSheet"/>
<link  href="static/yui/reset/reset.css" type="text/css" rel="StyleSheet"/>
<link  href="static/yui/grids/grids.css" type="text/css" rel="StyleSheet"/>
<link  href="static/style.css" type="text/css" rel="StyleSheet"/>
<link  href="static/yui/base/base.css" type="text/css" rel="StyleSheet"/>
<link  href="docstyle.css" type="text/css" rel="StyleSheet"/>
<link  href="syntax.css" type="text/css" rel="StyleSheet"/>


<title>Cubictemp Manual - Processors</title></head><body><div class="yui-t2" id="doc3"><div style="" id="hd"><h1> Cubictemp - Processors </h1></div><div id="bd"><div id="yui-main"><div style="" class="yui-b"><h1>Processors</h1><p>One common use for blocks is to declare a named block, and then perform some
transformation on it when it is inserted back into the document. One way to do
this is to write a transformation function that takes a string and returns a
string, and pass it straight in the template namespace for use: </p><div class="highlight"><pre><span class="c">&lt;!--(block codesnippet)--&gt;</span>
    for i in range(10):
        print i
<span class="c">&lt;!--(end)--&gt;</span>
@!syntaxHighlight(codesnippet)!@
</pre></div><p>Cubictemp has a special <strong>processor</strong> syntax to facilitate this use pattern.</p><div class="highlight"><pre><span class="c">&lt;!--(block codesnippet|syntaxHighlight)--&gt;</span>
    for i in range(10):
        print i
<span class="c">&lt;!--(end)--&gt;</span>
@!codesnippet!@
</pre></div><p>Using processors is similar to using pipes in Unix shells. Any callable that
takes a string and returns a string can be used as a processor. Processors can
be chained together:</p><div class="highlight"><pre><span class="c">&lt;!--(block codesnippet|trimWhitespace|syntaxHighlight)--&gt;</span>
    for i in range(10):
        print i
<span class="c">&lt;!--(end)--&gt;</span>
@!codesnippet!@
</pre></div><p>In this case, <strong>trimWhitespace</strong> would be run first, then <strong>syntaxHighlight</strong>.
The processor declarations are just expressions evaluated in the namespace of
the block declaration. Processors should be passed in to a template namespace
for use.</p><h1>Anonymous Blocks</h1><p>There is one further refinement to the block syntax. In the examples above,
naming the block is redundant - it is created, and then immediately substituted
into the template. Anonymous blocks remove this redundancy. An anonymous block
is immediately inserted into he template at its place of definition. The
following template is equivalent to the last definition above:</p><div class="highlight"><pre><span class="c">&lt;!--(block|trimWhitespace|syntaxHighlight)--&gt;</span>
    for i in range(10):
        print i
<span class="c">&lt;!--(end)--&gt;</span>
</pre></div></div></div><div style="" class="yui-b"><div class="pageindex"><ul><li class="inactive"><a href="index.html">Introduction</a></li><li class="inactive"><a href="subs.html">Tags</a></li><li class="inactive"><a href="blocks.html">Blocks</a></li><li class="active"><a href="processors.html">Processors</a></li><li class="inactive"><a href="api.html">API</a></li><li class="inactive"><a href="admin.html">Administrivia</a></li></ul></div></div></div><div style="" id="ft"><p>Copyright Nullcube 2008</p></div></div></body></html>