This file is indexed.

/usr/share/doc/python-kajiki-doc/html/runtime.html is in python-kajiki-doc 0.5.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Kajiki Runtime Transformations &mdash; Kajiki 0.5.3 documentation</title>
    
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '0.5.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="shortcut icon" href="_static/favicon.ico"/>
    <link rel="top" title="Kajiki 0.5.3 documentation" href="index.html" />
    <link rel="prev" title="Internationalization" href="i18n.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="i18n.html" title="Internationalization"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Kajiki 0.5.3 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="kajiki-runtime-transformations">
<h1>Kajiki Runtime Transformations<a class="headerlink" href="#kajiki-runtime-transformations" title="Permalink to this headline"></a></h1>
<p>It&#8217;s sometimes good to have a mental model of the Python code that Kajiki
creates in order to generate your templates.  This document uses several
examples taken from the text templating language to illustrate the semantics of
Kajiki templates.  If in doubt, you can always view the Python text generated for
a template by examining the py_text attribute of the generated Template class.</p>
<div class="section" id="basic-expressions">
<h2>Basic Expressions<a class="headerlink" href="#basic-expressions" title="Permalink to this headline"></a></h2>
<p>Let&#8217;s start with a hello world template:</p>
<div class="highlight-none"><div class="highlight"><pre>Hello, World!
</pre></div>
</div>
<p>This converts to the equivalent Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
    <span class="k">yield</span> <span class="s1">&#39;Hello, World!</span><span class="se">\n</span><span class="s1">&#39;</span>
</pre></div>
</div>
<p>Slightly more verbose &#8220;hello_name.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>Hello, $name!
</pre></div>
</div>
<p>This converts to the equivalent Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
     <span class="k">yield</span> <span class="s1">&#39;Hello, &#39;</span>
     <span class="k">yield</span> <span class="n">name</span>
     <span class="k">yield</span> <span class="s1">&#39;!</span><span class="se">\n</span><span class="s1">&#39;</span>
</pre></div>
</div>
<p>By default, the $-syntax picks up any identifiers following it, as well as any
periods.  If you want something more explicit, use the extended expression form
as in &#8220;hello_arithmetic.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>Hello, 2 + 2 is ${2+2}!
</pre></div>
</div>
<p>This converts to:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
    <span class="k">yield</span> <span class="s1">&#39;Hello, 2 + 2 is &#39;</span>
    <span class="k">yield</span> <span class="mi">2</span><span class="o">+</span><span class="mi">2</span>
    <span class="k">yield</span> <span class="s1">&#39;!&#39;</span>
</pre></div>
</div>
<p>If you wish to include a literal $, simply prefix it with a backslash.</p>
</div>
<div class="section" id="control-flow">
<h2>Control Flow<a class="headerlink" href="#control-flow" title="Permalink to this headline"></a></h2>
<p>Kajiki provides several tags that affect the rendering of a template.  The
following template &#8220;control_flow.txt&#8221; illustrates:</p>
<div class="highlight-none"><div class="highlight"><pre>A{%for i in range(5)%}
    {%if i &lt; 2%}Low{%elif i &lt; 4%}Mid{%else%}High{%end%}$i
    {%switch i % 2%}
        {%case 0%}
            even
        {%default%}
            odd
        {%end%}{%end%}{%end%}
</pre></div>
</div>
<p>This yields the following Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
    <span class="k">yield</span> <span class="s1">&#39;A</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="c1"># from the {%for... line</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
        <span class="k">yield</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">        &#39;</span> <span class="c1"># from the newline and initial indent of next line</span>
        <span class="k">if</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">:</span>
            <span class="k">yield</span> <span class="s1">&#39;Low&#39;</span>
        <span class="k">elif</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">4</span><span class="p">:</span>
            <span class="k">yield</span> <span class="s1">&#39;Mid&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">yield</span> <span class="s1">&#39;High&#39;</span>
        <span class="k">yield</span> <span class="n">i</span>
        <span class="k">yield</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">        &#39;</span> <span class="c1"># from the {%if... newline and next indent</span>
        <span class="n">local</span><span class="o">.</span><span class="n">__kj__</span><span class="o">.</span><span class="n">push_switch</span><span class="p">(</span><span class="n">i</span><span class="o">%</span><span class="mi">2</span><span class="p">)</span>
        <span class="c1"># whitespace after {%switch is always stripped</span>
        <span class="k">if</span> <span class="n">local</span><span class="o">.</span><span class="n">__kj__</span><span class="o">.</span><span class="n">case</span><span class="p">(</span><span class="mi">0</span><span class="p">):</span>
            <span class="k">yield</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">            even</span><span class="se">\n</span><span class="s1">        &#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">yield</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">            odd</span><span class="se">\n</span><span class="s1">        &#39;</span>
        <span class="n">local</span><span class="o">.</span><span class="n">__kj__</span><span class="o">.</span><span class="n">pop_switch</span><span class="p">()</span>
</pre></div>
</div>
<p>Which would in turn generate the following text:</p>
<div class="highlight-none"><div class="highlight"><pre>A
    Low0

        even

    Low1

        odd

    Mid2

        even

    Mid3

        odd

    High4

        even
</pre></div>
</div>
<p>If you want to strip whitespace before or after a tag, just replace
<code class="docutils literal"><span class="pre">{%</span></code> with <code class="docutils literal"><span class="pre">{%-</span></code> (for stripping leading whitespace) or <code class="docutils literal"><span class="pre">%}</span></code> with
<code class="docutils literal"><span class="pre">-%}</span></code> (for stripping trailing whitespace).  If you would like to remove
newlines, just end a line with a backslash.  Here is the equivalent template
with whitespace removed, &#8220;control_flow_ws.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>A{%-for i in range(5) -%}\
    {%-if i &lt; 2%}Low{%elif i &lt; 4%}Mid{%else%}High{%end%}$i
    {%-switch i % 2%}\
        {%-case 0%}\
            even
        {%-default%}\
            odd
        {%-end%}\
    {%-end%}\
{%-end%}\
</pre></div>
</div>
<p>This would generate the following Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
    <span class="k">yield</span> <span class="s1">&#39;A&#39;</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">:</span>
            <span class="k">yield</span> <span class="s1">&#39;Low&#39;</span>
        <span class="k">elif</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">4</span><span class="p">:</span>
            <span class="k">yield</span> <span class="s1">&#39;Mid&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">yield</span> <span class="s1">&#39;High&#39;</span>
        <span class="k">yield</span> <span class="n">i</span>
        <span class="k">yield</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="n">local</span><span class="o">.</span><span class="n">__kj__</span><span class="o">.</span><span class="n">push_switch</span><span class="p">(</span><span class="n">i</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">local</span><span class="o">.</span><span class="n">__kj__</span><span class="o">.</span><span class="n">case</span><span class="p">(</span><span class="mi">0</span><span class="p">):</span>
            <span class="k">yield</span> <span class="s1">&#39;even</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">yield</span> <span class="s1">&#39;odd</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="n">local</span><span class="o">.</span><span class="n">__kj__</span><span class="o">.</span><span class="n">pop_switch</span><span class="p">()</span>
</pre></div>
</div>
<p>Which would generate the following text:</p>
<div class="highlight-none"><div class="highlight"><pre>ALow0
even
Low1
odd
Mid2
even
Mid3
odd
High4
even
</pre></div>
</div>
<p>which is probably closer to what you wanted.  There is also a shorthand syntax
that allows for line-oriented control flow as seen in
&#8220;control_flow_ws_short.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>A\
%for i in range(5)
    %if i &lt; 2
        Low\
    %elif i &lt; 4
        Mid\
    %else
        High\
    {%-end%}$i
    %switch i % 2
        %case 0
            even
        %default
            odd
        %end
    %end
%end
</pre></div>
</div>
<p>This syntax yields exactly the same results as &#8220;control_flow_ws.txt&#8221; above.</p>
</div>
<div class="section" id="python-blocks">
<h2>Python Blocks<a class="headerlink" href="#python-blocks" title="Permalink to this headline"></a></h2>
<p>You can insert literal Python code into your template using the following syntax
in &#8220;simple_py_block.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>{%py%}\
    yield &#39;Prefix&#39;
{%end%}\
Body
</pre></div>
</div>
<p>or alternatively:</p>
<div class="highlight-none"><div class="highlight"><pre>%py
    yield &#39;Prefix&#39;
%end
Body
</pre></div>
</div>
<p>or even more succinctly:</p>
<div class="highlight-none"><div class="highlight"><pre>%py yield &#39;Prefix&#39;
Body
</pre></div>
</div>
<p>all of which will generate the following Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
    <span class="k">yield</span> <span class="s1">&#39;Prefix&#39;</span>
    <span class="k">yield</span> <span class="s1">&#39;Body&#39;</span>
</pre></div>
</div>
<dl class="docutils">
<dt>Note in particular that the Python block can have any indentation, as long as it</dt>
<dd>is consistent (the amount of leading whitespace in the first non-empty line of
the block is stripped from all lines within the block).  You can insert
module-level Python (imports, etc.) by using the %py% directive (or {%py%%} as in
&#8220;module_py_block.txt&#8221;:</dd>
</dl>
<div class="highlight-none"><div class="highlight"><pre>%py%
    import sys
    import re
%end
Hello
%py% import os
%end
</pre></div>
</div>
<p>This yields the following Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">re</span>

<span class="kn">import</span> <span class="nn">os</span>

<span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
    <span class="k">yield</span> <span class="s1">&#39;Hello&#39;</span>
</pre></div>
</div>
</div>
<div class="section" id="functions-and-imports">
<h2>Functions and Imports<a class="headerlink" href="#functions-and-imports" title="Permalink to this headline"></a></h2>
<p>Kajiki provides for code reuse via the %def and %import directives.  First, let&#8217;s
see %def in action in &#8220;simple_function.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>%def evenness(n)
    %if n % 2 == 0
        even\
    %else
        odd\
    %end
%end
%for i in range(5)
$i is ${evenness(i)}
%end
</pre></div>
</div>
<p>This compiles to the following Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">evenness</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
    <span class="k">if</span> <span class="n">n</span> <span class="o">%</span> <span class="mi">2</span><span class="p">:</span>
        <span class="k">yield</span> <span class="s1">&#39;even&#39;</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">yield</span> <span class="s1">&#39;odd&#39;</span>

<span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
        <span class="k">yield</span> <span class="n">i</span>
        <span class="k">yield</span> <span class="s1">&#39; is &#39;</span>
        <span class="k">yield</span> <span class="n">evenness</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
</pre></div>
</div>
<p>The %import directive allows you to package up your functions for reuse in
another template file (or even in a Python package).  For instance, consider the
following file &#8220;import_test.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>%import &quot;simple_function.txt&quot; as simple_function
%for i in range(5)
$i is ${simple_function.evenness(i)}
%end
</pre></div>
</div>
<p>This would then compile to the following Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
    <span class="n">simple_function</span> <span class="o">=</span> <span class="n">local</span><span class="o">.</span><span class="n">__kj__</span><span class="o">.</span><span class="n">import_</span><span class="p">(</span><span class="s2">&quot;simple_function.txt&quot;</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
        <span class="k">yield</span> <span class="n">i</span>
        <span class="k">yield</span> <span class="s1">&#39; is &#39;</span>
        <span class="k">yield</span> <span class="n">simple_function</span><span class="o">.</span><span class="n">evenness</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that when using the %import directive, any &#8220;body&#8221; in the imported template
is ignored and only functions are imported.  If you actually wanted to insert the
body of the imported template, you would simply call the imported template as a
function itself (e.g. ${simple_function()}).</p>
<p>Sometimes it is convenient to pass the contents of a tag to a function.  In this
case, you can use the %call directive as shown in &#8220;call.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>%def quote(caller, speaker)
    %for i in range(5)
Quoth $speaker, &quot;${caller(i)}.&quot;
    %end
%end
%call(n) quote(&#39;the raven&#39;)
Nevermore $n\
%end
</pre></div>
</div>
<p>This results in the following Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">quote</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">speaker</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
        <span class="k">yield</span> <span class="s1">&#39;Quoth &#39;</span>
        <span class="k">yield</span> <span class="n">speaker</span>
        <span class="k">yield</span> <span class="s1">&#39;, &quot;&#39;</span>
        <span class="k">yield</span> <span class="n">caller</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
        <span class="k">yield</span> <span class="s1">&#39;.&quot;&#39;</span>

<span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
    <span class="nd">@kajiki.expose</span>
    <span class="k">def</span> <span class="nf">_fpt_lambda</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
        <span class="k">yield</span> <span class="s1">&#39;Nevermore &#39;</span>
        <span class="k">yield</span> <span class="n">n</span>
    <span class="k">yield</span> <span class="n">quote</span><span class="p">(</span><span class="n">_fpt_lambda</span><span class="p">,</span> <span class="s1">&#39;the raven&#39;</span><span class="p">)</span>
    <span class="k">del</span> <span class="n">_fpt_lambda</span>
</pre></div>
</div>
<p>Which in turn yields the following output:</p>
<div class="highlight-none"><div class="highlight"><pre>Quoth the raven, &quot;Nevermore 0.&quot;
Quoth the raven, &quot;Nevermore 1.&quot;
Quoth the raven, &quot;Nevermore 2.&quot;
Quoth the raven, &quot;Nevermore 3.&quot;
Quoth the raven, &quot;Nevermore 4.&quot;
</pre></div>
</div>
</div>
<div class="section" id="includes">
<h2>Includes<a class="headerlink" href="#includes" title="Permalink to this headline"></a></h2>
<p>Sometimes you just want to pull the text of another template into your template
verbatim.  For this, you use the %include directive as in &#8220;include_example.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>This is my story:
%include &quot;call.txt&quot;
Isn&#39;t it good?
</pre></div>
</div>
<p>which yields the following Python:</p>
<div class="highlight-python"><div class="highlight"><pre>@kajiki.expose
def __call__():
    yield &#39;This is my story:\n&#39;
    yield _fpt.import(&quot;simple_function.txt&quot;)()
    yield &#39;Isn&#39;t it good?\n&#39;
</pre></div>
</div>
<p>Which of course yields:</p>
<div class="highlight-none"><div class="highlight"><pre>This is my story:
Quoth the raven, &quot;Nevermore 0.&quot;
Quoth the raven, &quot;Nevermore 1.&quot;
Quoth the raven, &quot;Nevermore 2.&quot;
Quoth the raven, &quot;Nevermore 3.&quot;
Quoth the raven, &quot;Nevermore 4.&quot;
Isn&#39;t it good?
</pre></div>
</div>
</div>
<div class="section" id="inheritance">
<h2>Inheritance<a class="headerlink" href="#inheritance" title="Permalink to this headline"></a></h2>
<p>Kajiki supports a concept of inheritance whereby child templates can extend
parent templates, replacing their methods and &#8220;blocks&#8221; (to be defined below).
For instance, consider the following template &#8220;parent.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>%def greet(name)
Hello, $name!\
%end
%def sign(name)
Sincerely,
$name\
%end
${greet(to)}

%block body
It was good seeing you last Friday.  Thanks for the gift!
%end

${sign(from)}
</pre></div>
</div>
<p>This would generate the following Python:</p>
<div class="highlight-python"><div class="highlight"><pre>@kajiki.expose
def greet(name):
    yield &#39;Hello, &#39;
    yield name
    yield &#39;!&#39;

@kajiki.expose
def sign(name):
    yield &#39;Sincerely,\n&#39;
    yield name

@kajiki.expose
def _fpt_block_body():
    yield &#39;It was good seeing you last Friday! Thanks for the gift!\n&#39;

@kajiki.expose
def __call__():
    yield greet(to)
    yield &#39;\n\n&#39;
    yield self._fpt_block_body()
    yield &#39;\n\n&#39;
    yield sign(from)
</pre></div>
</div>
<p>Here is the corresponding &#8220;child.txt&#8221;:</p>
<div class="highlight-none"><div class="highlight"><pre>%extends &quot;parent.txt&quot;
%def greet(name)
Dear $name:\
%end
%block body
${parent_block()}\\

And don&#39;t forget you owe me money!
%end
</pre></div>
</div>
<p>This would then yield the following Python:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">greet</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
    <span class="k">yield</span> <span class="s1">&#39;Dear &#39;</span>
    <span class="k">yield</span> <span class="n">name</span>
    <span class="k">yield</span> <span class="s1">&#39;:&#39;</span>

<span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">_fpt_block_body</span><span class="p">():</span>
    <span class="k">yield</span> <span class="n">parent</span><span class="o">.</span><span class="n">_fpt_block_body</span><span class="p">()</span>
    <span class="k">yield</span> <span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span>
    <span class="k">yield</span> <span class="s1">&#39;And don</span><span class="se">\&#39;</span><span class="s1">t forget you owe me money!</span><span class="se">\n</span><span class="s1">&#39;</span>

<span class="nd">@kajiki.expose</span>
<span class="k">def</span> <span class="nf">__call__</span><span class="p">():</span>
    <span class="k">yield</span> <span class="n">local</span><span class="o">.</span><span class="n">__kj__</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">local</span><span class="o">.</span><span class="n">__kj__</span><span class="o">.</span><span class="n">import_</span><span class="p">(</span><span class="s1">&#39;parent.txt&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">__call__</span><span class="p">()</span>
</pre></div>
</div>
<p>The final text would be (assuming context had to=&#8217;Mark&#8217; and from=&#8217;Rick&#8217;:</p>
<div class="highlight-none"><div class="highlight"><pre>Dear Mark:

It was good seeing you last Friday! Thanks for the gift!

And don&#39;t forget you owe me money!

Sincerely,
Rick
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Kajiki Runtime Transformations</a><ul>
<li><a class="reference internal" href="#basic-expressions">Basic Expressions</a></li>
<li><a class="reference internal" href="#control-flow">Control Flow</a></li>
<li><a class="reference internal" href="#python-blocks">Python Blocks</a></li>
<li><a class="reference internal" href="#functions-and-imports">Functions and Imports</a></li>
<li><a class="reference internal" href="#includes">Includes</a></li>
<li><a class="reference internal" href="#inheritance">Inheritance</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="i18n.html"
                        title="previous chapter">Internationalization</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/runtime.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="i18n.html" title="Internationalization"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Kajiki 0.5.3 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &copy; Copyright 2010-2013, Rick Copeland.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
    </div>
  </body>
</html>