/usr/share/doc/rest2web/html/functions.html is in rest2web-doc 0.5.2~alpha+svn-r248-2.
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 | <!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" lang="en" xml:lang="en">
<head>
<title>The Standard Functions</title>
<link rel="stylesheet" href="stylesheets/rest2web.css" type="text/css" />
<link rel="stylesheet" href="stylesheets/voidspace_docutils2.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="rest2web - build websites with Python and docutils." />
<meta name="author" content="Michael Foord" />
<meta name="copyright" content="© 2003-2006 Michael Foord, subject to BSD License" />
<meta name="keywords" content="rest2web - build websites with Python and docutils,
rest, restructured text, text, website, internet, web, net, web builder, site,
site builder, docutils, i18n, internationalization, templates, templating,
python, " />
</head>
<body style="background: url(images/logos/img_background.gif) top center repeat-y;">
<div id="wrap">
<div id="header-section">
<a href="http://www.voidspace.org.uk/python/index.shtml" title="Voidspace"><img src="images/logos/header760.gif" alt="Voidspace"/></a>
<p align="center" class="headertitle"><span style="font-size:130%">rest2web:</span> Building Websites Across the Known Universe</p>
</div>
<div id="header">
<ul>
<li><a href="index.html">rest2web</a></li>
<li>></li>
<li>Functions</li>
</ul>
</div>
<table>
<tr>
<td><img src="images/logos/1.gif" width="1" height="1" alt="" /></td>
<!-- main content cell first, with rowspan=2 -->
<td valign="top" align="left" rowspan="2">
<div id="middle-column">
<a name="startcontent" id="startcontent"></a>
<div id="gallery">
<div class="document" id="the-standard-functions">
<h1 class="title">The Standard Functions</h1>
<h2 class="subtitle" id="the-functions-in-rest2web">The Functions in rest2web</h2>
<div class="contents topic" id="functions">
<p class="topic-title first">Functions</p>
<ul class="simple">
<li><a class="reference internal" href="#introduction" id="id3">Introduction</a></li>
<li><a class="reference internal" href="#the-functions" id="id4">The Functions</a><ul>
<li><a class="reference internal" href="#print-details" id="id5">print_details</a></li>
<li><a class="reference internal" href="#section-contents" id="id6">section_contents</a></li>
<li><a class="reference internal" href="#print-crumbs" id="id7">print_crumbs</a></li>
<li><a class="reference internal" href="#minibar" id="id8">minibar</a></li>
<li><a class="reference internal" href="#sidebar" id="id9">sidebar</a></li>
<li><a class="reference internal" href="#include" id="id10">include</a></li>
<li><a class="reference internal" href="#formattime" id="id11">formattime</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h1><a class="toc-backref" href="#id3">Introduction</a></h1>
<p><img src="images/python.gif" alt="emoticon:python" /> <strong>rest2web</strong> provides varous data structures for use in your templates. These can be used to create navigation trails and simple or complex sidebars. It is probable that most people using <strong>rest2web</strong> will want to create similarly constructed results - even if the visual appearance differs.</p>
<p>Included in the namespace the templates are rendered in, are several standard functions that do just this.</p>
</div>
<div class="section" id="the-functions">
<h1><a class="toc-backref" href="#id4">The Functions</a></h1>
<p>The standard functions are defined in the file <em>functions.py</em>, in the rest2web directory. They are also good examples of how to use the data structures.</p>
<p>If you find yourself regularly defining and using <em>different</em> functions then <a class="reference external" href="mailto:fuzzyman%40voidspace.org.uk">let me know</a>. I can include them in this file. <a class="footnote-reference" href="#id2" id="id1">[1]</a></p>
<p>See the <a class="reference external" href="templating.html">templating</a> and <a class="reference external" href="reference/indextree.html">indextree</a> page for more details of the values used by the standard functions.</p>
<p>These functions all have sensible defaults - but can be controlled by passing in keyword arguments. This means you only have to pass in arguments that you need to change from the default.</p>
<p>You include them in the template between <tt class="docutils literal"><span class="pre"><#</span> <span class="pre">....</span> <span class="pre">#></span></tt> style tags.</p>
<p>For example, you can print the standard <em>breadcrumbs</em> trail for a page using :</p>
<pre class="literal-block">
<# print_crumbs(breadcrumbs) #>
</pre>
<p>If you wanted all the elements to be in bold you could change the <tt class="docutils literal"><span class="pre">item</span></tt> keyword :</p>
<pre class="literal-block">
<# print_crumbs(breadcrumbs, item='<li><strong>%s</strong></li>') #>
</pre>
<p>Abetter way of doing that would be through <acronym title="Cascading Style Sheets">CSS</acronym> of course, but you get the idea. <img src="images/smilies/razz.gif" alt="Razz" /> </p>
<div class="section" id="print-details">
<h2><a class="toc-backref" href="#id5">print_details</a></h2>
<p>This function provides an ultra easy way of printing index pages. It will print a list of all the pages in a section - with a link and the description. You can configure the <acronym title="HyperText Markup Language">HTML</acronym> used - and whether or not the description is included.</p>
<div class="pysrc"><span class="pytext">print_details</span><span class="pyoperator">(</span><span class="pytext">section</span><span class="pyoperator">,</span><br />
<span class="pytext">page_title</span><span class="pyoperator">=</span><span class="pystring">'<h3>Pages</h3>'</span><span class="pyoperator">,</span><br />
<span class="pytext">subsection_title</span><span class="pyoperator">=</span><span class="pystring">'<h3>Sub Sections</h3>'</span><span class="pyoperator">,</span><br />
<span class="pytext">item_wrapper</span> <span class="pyoperator">=</span> <span class="pystring">'<ul>%s</ul>'</span><span class="pyoperator">,</span><br />
<span class="pytext">item</span><span class="pyoperator">=</span><span class="pystring">'<li>%s</li>'</span><span class="pyoperator">,</span><br />
<span class="pytext">link</span><span class="pyoperator">=</span><span class="pystring">'<a href="%s">%s</a>'</span><span class="pyoperator">,</span><br />
<span class="pytext">description</span><span class="pyoperator">=</span><span class="pystring">'%s'</span><span class="pyoperator">,</span><br />
<span class="pytext">do_description</span><span class="pyoperator">=</span><span class="pytext">True</span><span class="pyoperator">,</span><br />
<span class="pytext">split</span><span class="pyoperator">=</span><span class="pytext">True</span><span class="pyoperator">,</span><br />
<span class="pytext">do_pages</span><span class="pyoperator">=</span><span class="pytext">True</span><span class="pyoperator">,</span><br />
<span class="pytext">do_subsections</span><span class="pyoperator">=</span><span class="pytext">True</span><br />
<span class="pyoperator">)</span><span class="pyoperator">:</span><span class="pytext"></span></div><p>This function is a quick way of printing all the pages and sub-sections in
a section. You can use it without having to understand the <tt class="docutils literal"><span class="pre">sections</span></tt>
data structure.</p>
<p>It prints a menu of all pages (links and descriptions) and sub-sections.</p>
<p>It has sensible defaults - and is configurable in terms of the HTML used.</p>
<p>Including the description of each page is optional.</p>
<p>You can also elect to do pages and subsections combined, separately, or
just one or the other.</p>
<p>Like the other function it needs "%s" in some of the values - which are
filled in automatically.</p>
<p>The default layout looks like :</p>
<pre class="literal-block">
<h3>Page Title</h3> ---> ``page_title``
<ul> ---> ``item_wrapper`` along with the corresponding ``</ul>``.
This wraps all the links.
<li> ---> ``item`` along with the corresponding ``</li>``. This
wraps each item - whether or not it includes the
description.
<a href="url">Link Title</a> ---> ``link``. This contains the URL
*and* the link title.
Page description. ---> ``description`` . Optional,
controlled by ``do_description``
</li>
</ul>
</pre>
<p>This is then repeated for the subsections. If <tt class="docutils literal"><span class="pre">split</span></tt> is <tt class="docutils literal"><span class="pre">False</span></tt> then
all the pages and subsections are combined as the pages.</p>
<p>The options are :</p>
<ul>
<li><p class="first"><tt class="docutils literal"><span class="pre">page_title</span> <span class="pre">=</span> <span class="pre">'<h3>Pages</h3>'</span></tt></p>
<blockquote>
<p>This is the title line printed before the pages.</p>
</blockquote>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">subsection_title</span> <span class="pre">=</span> <span class="pre">'<h3>Sub</span> <span class="pre">Sections</h3>'</span></tt></p>
<blockquote>
<p>This is the title line printed before the Sub Sections.</p>
</blockquote>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">item_wrapper</span> <span class="pre">=</span> <span class="pre">'<ul>%s</ul>'</span></tt></p>
<blockquote>
<p>This is the wrapper around all the links. It needs one "%s" in it.</p>
</blockquote>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">item</span> <span class="pre">=</span> <span class="pre">'<li>%s</li>'</span></tt></p>
<blockquote>
<p>This is the wrapper around each link. It needs one "%s" in it.</p>
</blockquote>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">link</span> <span class="pre">=</span> <span class="pre">'<a</span> <span class="pre">href="%s">%s</a>'</span></tt></p>
<blockquote>
<p>This is the link. It needs two "%s" in it.</p>
</blockquote>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">description</span> <span class="pre">=</span> <span class="pre">'%s'</span></tt></p>
<blockquote>
<p>This is for the description and is put immediately after the link.
It needs one "%s" in it. (You could put a tags around the
description to style them separately. E.g.
<tt class="docutils literal"><span class="pre">description</span> <span class="pre">=</span> <span class="pre">'<div</span> <span class="pre">class="description>%s</div>'</span></tt>).</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p>It's not necessary to explicitly put paragraph tags around the
description.</p>
<p class="last"><strong>rest2web</strong> renders descriptions using <a class="reference external" href="http://docutils.sf.net">docutils</a>
which does this automatically.</p>
</div>
</blockquote>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">do_description</span> <span class="pre">=</span> <span class="pre">True</span></tt></p>
<blockquote>
<p>If <tt class="docutils literal"><span class="pre">True</span></tt>, the description is added to each link.</p>
</blockquote>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">split</span> <span class="pre">=</span> <span class="pre">True</span></tt></p>
<blockquote>
<p>If <tt class="docutils literal"><span class="pre">True</span></tt>, the pages are done separately from the sub-sections.</p>
</blockquote>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">do_pages</span> <span class="pre">=</span> <span class="pre">True</span></tt></p>
<blockquote>
<p>If <tt class="docutils literal"><span class="pre">False</span></tt>, the pages are not printed.</p>
</blockquote>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">do_subsections</span> <span class="pre">=</span> <span class="pre">True</span></tt></p>
<blockquote>
<p>If <tt class="docutils literal"><span class="pre">False</span></tt>, the subsections are not printed.</p>
</blockquote>
</li>
</ul>
<p>So you can print a basic index page for a section with a single function call. Shown below is the call for printing all the pages and subsections in the default section :</p>
<pre class="literal-block">
<# print_details(default_section) #>
</pre>
<p> <img src="images/smilies/smile.gif" alt="Smile" /> Easy hey.</p>
<p>If you have several sections in your index page, here is some example code that does all of them (including section descriptions) :</p>
<div class="pysrc"><span class="pykeyword">for</span> <span class="pytext">section</span> <span class="pykeyword">in</span> <span class="pytext">sections</span><span class="pyoperator">.</span><span class="pytext">values</span><span class="pyoperator">(</span><span class="pyoperator">)</span><span class="pyoperator">:</span><br />
<span class="pykeyword">print</span> <span class="pystring">'<div class="indexblock">'</span><br />
<span class="pytext">title</span> <span class="pyoperator">=</span> <span class="pystring">'''<br />
<h2>%s</h2><br />
%s'''</span> <span class="pyoperator">%</span> <span class="pyoperator">(</span><span class="pytext">section</span><span class="pyoperator">[</span><span class="pystring">'title'</span><span class="pyoperator">]</span><span class="pyoperator">,</span> <span class="pytext">section</span><span class="pyoperator">[</span><span class="pystring">'description'</span><span class="pyoperator">]</span><span class="pyoperator">)</span><br />
<span class="pytext">print_details</span><span class="pyoperator">(</span><span class="pytext">section</span><span class="pyoperator">,</span> <span class="pytext">split</span><span class="pyoperator">=</span><span class="pytext">False</span><span class="pyoperator">,</span> <span class="pytext">page_title</span><span class="pyoperator">=</span><span class="pytext">title</span><span class="pyoperator">)</span><br />
<span class="pykeyword">print</span> <span class="pystring">'</div>'</span><span class="pytext"></span></div><p>The above code prints the pages and subsections for every section. Each section is in it's own <tt class="docutils literal"><span class="pre">div</span></tt> with the section name as a title.</p>
<p>If you want to wrap pages and subsections in their own <tt class="docutils literal"><span class="pre">div</span></tt> (so you need them outputting separately), you could do :</p>
<pre class="literal-block">
<div class="pages">
<# print_details(default_section, do_subsections=False) #>
</div>
<div class="subsections">
<# print_details(sections[None], do_pages=False) #>
</div>
</pre>
</div>
<div class="section" id="section-contents">
<h2><a class="toc-backref" href="#id6">section_contents</a></h2>
<p><tt class="docutils literal"><span class="pre">section_contents</span></tt> makes it easier to access the information in the <tt class="docutils literal"><span class="pre">sections</span></tt> data structure. You pass it an individual section (i.e. <tt class="docutils literal"><span class="pre">sections['section_name']</span></tt>) and it returns a list of the pages and subsections. Usually it is only this information that you want.</p>
<pre class="literal-block">
section_contents(section, split=True):
</pre>
<p>Passed in a section - this function returns the pages and subsections.</p>
<p>Each page (or subsection) is returned as a tuple :
<tt class="docutils literal"><span class="pre">(url,</span> <span class="pre">link</span> <span class="pre">title,</span> <span class="pre">description)</span></tt></p>
<p>The urllib is escaped for putting straight into the link.</p>
<p>If split is <tt class="docutils literal"><span class="pre">True</span></tt> (the default) this function returns a list of pages and a
list of subsections.</p>
<p>If split is <tt class="docutils literal"><span class="pre">False</span></tt> it just returns a single list.</p>
<p>An example use of this function might be :</p>
<div class="pysrc"><span class="pytext">pageblock</span> <span class="pyoperator">=</span> <span class="pystring">'''\<br />
<li><a href="%s">%s</a><br />
<p>%s</p><br />
</li><br />
'''</span><br />
<span class="pycomment"># just use the default section<br />
</span><span class="pytext">pages</span><span class="pyoperator">,</span> <span class="pytext">subsections</span> <span class="pyoperator">=</span> <span class="pytext">section_contents</span><span class="pyoperator">(</span><span class="pytext">sections</span><span class="pyoperator">[</span><span class="pytext">None</span><span class="pyoperator">]</span><span class="pyoperator">)</span><br />
<span class="pycomment"># first print the pages<br />
</span><span class="pykeyword">if</span> <span class="pytext">pages</span><span class="pyoperator">:</span><br />
<span class="pykeyword">print</span> <span class="pystring">'<h3>Pages</h3>'</span><br />
<span class="pykeyword">print</span> <span class="pystring">'<ul>'</span><br />
<span class="pykeyword">for</span> <span class="pytext">page</span> <span class="pykeyword">in</span> <span class="pytext">pages</span><span class="pyoperator">:</span><br />
<span class="pykeyword">print</span> <span class="pytext">pageblock</span> <span class="pyoperator">%</span> <span class="pytext">page</span><br />
<span class="pykeyword">print</span> <span class="pystring">'</ul>'</span><br />
<span class="pycomment"># next - the subsections<br />
</span><span class="pykeyword">if</span> <span class="pytext">subsections</span><span class="pyoperator">:</span><br />
<span class="pykeyword">print</span> <span class="pystring">'<h3>Subsections</h3>'</span><br />
<span class="pykeyword">print</span> <span class="pystring">'<ul>'</span><br />
<span class="pykeyword">for</span> <span class="pytext">page</span> <span class="pykeyword">in</span> <span class="pytext">subsections</span><span class="pyoperator">:</span><br />
<span class="pykeyword">print</span> <span class="pytext">pageblock</span> <span class="pyoperator">%</span> <span class="pytext">page</span><br />
<span class="pykeyword">print</span> <span class="pystring">'</ul>'</span><span class="pytext"></span></div><p>Another example that only uses the link and link title for each page :</p>
<div class="pysrc"><span class="pycomment"># Get all the pages in the default section<br />
</span><span class="pycomment"># as a single list<br />
</span><span class="pytext">pages</span> <span class="pyoperator">=</span> <span class="pytext">section_contents</span><span class="pyoperator">(</span><span class="pytext">sections</span><span class="pyoperator">[</span><span class="pytext">None</span><span class="pyoperator">]</span><span class="pyoperator">,</span> <span class="pytext">split</span><span class="pyoperator">=</span><span class="pytext">False</span><span class="pyoperator">)</span><br />
<br />
<span class="pytext">link</span> <span class="pyoperator">=</span> <span class="pystring">'<a href="%s">%s</a>'</span><br />
<span class="pykeyword">for</span> <span class="pytext">page</span> <span class="pykeyword">in</span> <span class="pytext">pages</span><span class="pyoperator">:</span><br />
<span class="pytext">url</span> <span class="pyoperator">=</span> <span class="pytext">page</span><span class="pyoperator">[</span><span class="pynumber">0</span><span class="pyoperator">]</span><br />
<span class="pytext">title</span> <span class="pyoperator">=</span> <span class="pytext">page</span><span class="pyoperator">[</span><span class="pynumber">1</span><span class="pyoperator">]</span><br />
<span class="pycomment"># we don't use page[2] which is the description<br />
</span> <span class="pykeyword">print</span> <span class="pytext">link</span> <span class="pyoperator">%</span> <span class="pyoperator">(</span><span class="pytext">url</span><span class="pyoperator">,</span> <span class="pytext">title</span><span class="pyoperator">)</span><br />
<span class="pykeyword">print</span> <span class="pystring">'<br />'</span><span class="pytext"></span></div><p>You can actually achieve the same as the above examples by using the <a class="reference internal" href="#print-details">print_details</a> function.</p>
</div>
<div class="section" id="print-crumbs">
<h2><a class="toc-backref" href="#id7">print_crumbs</a></h2>
<p>The <tt class="docutils literal"><span class="pre">print_crumbs</span></tt> function provides a way of easily adding a navigation trail to your website. It uses the <tt class="docutils literal"><span class="pre">breadcrumbs</span></tt> value. In it's simplest form you put <tt class="docutils literal"><span class="pre"><#</span> <span class="pre">print_crumbs(breadcrumbs)</span> <span class="pre">#></span></tt> in your template.</p>
<p>It also takes other values which define how it prints the trail, and the dividers between the links. Here is the function description, which explains how to use it :</p>
<div class="pysrc"><span class="pykeyword">def</span> <span class="pytext">print_crumbs</span><span class="pyoperator">(</span><br />
<span class="pytext">breadcrumbs</span><span class="pyoperator">,</span><br />
<span class="pytext">item</span> <span class="pyoperator">=</span> <span class="pystring">'<li>%s</li>'</span><span class="pyoperator">,</span><br />
<span class="pytext">anchor</span> <span class="pyoperator">=</span> <span class="pystring">'<a href="%s">%s</a>'</span><span class="pyoperator">,</span><br />
<span class="pytext">divider</span> <span class="pyoperator">=</span> <span class="pystring">'&gt;'</span><span class="pyoperator">,</span><br />
<span class="pyoperator">)</span><span class="pyoperator">:</span><span class="pytext"></span></div><p>A function to print the breadcrumbs (navigation) trail for a page.</p>
<p>The idea is that all the index pages above the current page are shown as
links. There are dividers in between, and the crumb of the current page is
shown (but not as a link).</p>
<p>You pass in the breadcrumbs values. It needs an item value with one <tt class="docutils literal"><span class="pre">'%s'</span></tt>
place holder. Every link and divider (and the last value) is put into this item.
The default value is <tt class="docutils literal"><span class="pre">'<li>%s</li>'</span></tt>.</p>
<p>It needs an anchor value with two <tt class="docutils literal"><span class="pre">'%s'</span></tt> placeholders. Into this are inserted
the link and the 'crumb'. The default value is <tt class="docutils literal"><span class="pre">'<a</span> <span class="pre">href="%s">%s</a>'</span></tt>
The last crumb is printed without the use of the <tt class="docutils literal"><span class="pre">'anchor'</span></tt> value.</p>
<p>It also needs a divider which is printed between the crumbs.
The default value is <tt class="docutils literal"><span class="pre">'>'</span></tt></p>
<p>By default this function uses list items to display the crumbs.</p>
<p>You should surround it using something like :</p>
<pre class="literal-block">
'<div id="crumbs"><ul>...</ul></div>'
</pre>
<p>Then use css rules like the following to format the display of the crumbs :</p>
<pre class="literal-block">
#crumbs {
background-color:#c99;
padding:5px;
text-align:center;
font-size:15pt;
font-weight:bold;
}
#crumbs ul {
margin:0;
padding:0
}
#crumbs li {
display:inline;
list-style:none;
margin:0;
padding:5px;
}
</pre>
<p>So to display the breadcrumbs trail without using list items, you could put the
following in your template :</p>
<pre class="literal-block">
<#
# item no longer uses ``<li>``
item = '%s'
print_crumbs(breadcrumbs, item=item)
#>
</pre>
<p>If you specify <tt class="docutils literal"><span class="pre">dividers=None</span></tt>, then no dividers at all will be printed.</p>
</div>
<div class="section" id="minibar">
<h2><a class="toc-backref" href="#id8">minibar</a></h2>
<p>This function prints a simple sidebar that shows links to all the pages in the current directory. It uses the <tt class="docutils literal"><span class="pre">sections</span></tt> value to get it's information. It <em>doesn't</em> print a link to the index page in a directory. Here is the function definition :</p>
<div class="pysrc"><span class="pytext">minibar</span><span class="pyoperator">(</span><span class="pytext">sections</span><span class="pyoperator">,</span><br />
<span class="pytext">item</span> <span class="pyoperator">=</span> <span class="pystring">'<li><a href="%s">%s</a></li>'</span><span class="pyoperator">,</span><br />
<span class="pytext">intro</span> <span class="pyoperator">=</span> <span class="pystring">'<h3>Pages</h3>'</span><span class="pyoperator">,</span><br />
<span class="pytext">subsect</span><span class="pyoperator">=</span><span class="pytext">True</span><span class="pyoperator">,</span><br />
<span class="pytext">subintro</span> <span class="pyoperator">=</span> <span class="pystring">'<h3>Sub Sections</h3>'</span><span class="pyoperator">,</span><br />
<span class="pytext">liststart</span> <span class="pyoperator">=</span> <span class="pystring">'<ul>'</span><span class="pyoperator">,</span><br />
<span class="pytext">listend</span> <span class="pyoperator">=</span> <span class="pystring">'</ul>'</span><span class="pyoperator">,</span><br />
<span class="pytext">displayval</span> <span class="pyoperator">=</span> <span class="pystring">'link-title'</span><br />
<span class="pyoperator">)</span><span class="pyoperator">:</span><span class="pytext"></span></div><p>This function prints an alternative sidebar to the 'sidebar' function.</p>
<p>It uses the <tt class="docutils literal"><span class="pre">'sections'</span></tt> value rather than indextree and only goes
through the pages in the current directory.</p>
<p>It can optionally differentiate between pages that are themselves
'subsections' (index pages for sections below) and ordinary pages.</p>
<p>You need to pass in the 'sections' value, as well as any of the following
optional keyword arguments :</p>
<p>If <tt class="docutils literal"><span class="pre">'subsect'</span></tt> is <tt class="docutils literal"><span class="pre">True</span></tt> (the default) then minibar divides pages
into ordinary pages and 'subsections'. Otherwise they're all pages.</p>
<p>If there are any pages then the value 'intro' is printed. Default is <tt class="docutils literal"><span class="pre">'<h3>Pages</h3>'</span></tt>.</p>
<p>Then liststart is printed. Default is <tt class="docutils literal"><span class="pre">'<ul>'</span></tt>.</p>
<p>The for each page the following is printed :</p>
<pre class="literal-block">
item % (page['target'], page[displayval])
</pre>
<p>The default for item is <tt class="docutils literal"><span class="pre">'<li><a</span> <span class="pre">href="%s">%s</a></li>'</span></tt></p>
<p>The default for displayval is <tt class="docutils literal"><span class="pre">'link-title'</span></tt>. (It should be one of the values
stored in each page. An alternative value would be <tt class="docutils literal"><span class="pre">'crumb'</span></tt>).</p>
<p>Then listend is printed. Default is <tt class="docutils literal"><span class="pre">'</ul>'</span></tt>.</p>
<p>If there are any subsections (and <tt class="docutils literal"><span class="pre">'subsect'</span></tt> is <tt class="docutils literal"><span class="pre">True</span></tt>) then value
<tt class="docutils literal"><span class="pre">'subintro'</span></tt> is printed. Default is <tt class="docutils literal"><span class="pre">'<h3>Sub</span> <span class="pre">Sections</h3>'</span></tt></p>
<p>Then the same sequence as for pages is printed :</p>
<pre class="literal-block">
list start, the page links, listend
</pre>
<p>Note: it doesn't include a link to the index page in a section. You will need
to include this yourself separately.</p>
<p>To print a link to the index page <em>and</em> all the pages in the section you can use something like the following in your template :</p>
<pre class="literal-block">
<#
print '<h3><a href="%s">Main Page</a></h3>' % indexpage['target']
minibar(sections)
#>
</pre>
<p>It uses the <tt class="docutils literal"><span class="pre">indexpage</span></tt> value as well as the <tt class="docutils literal"><span class="pre">minibar</span></tt> function.</p>
</div>
<div class="section" id="sidebar">
<h2><a class="toc-backref" href="#id9">sidebar</a></h2>
<p>This is slightly different to the other functions. It can be used to produce sidebars with links to all the pages in the sections above the current page. It is actually a 'generator' rather than a function. This means you iterate over it and it yields pages one at a time. It works from the top level down, and it wraps each section in a 'div' block. This allows you to visually display the nested nature of the sections. <tt class="docutils literal"><span class="pre">sidebar</span></tt> in it's defualt behaviour does this by indenting the sections 10 pixels each time :</p>
<div class="pysrc"><span class="pytext">sidebar</span><span class="pyoperator">(</span><span class="pytext">thetree</span><span class="pyoperator">,</span> <span class="pytext">div</span><span class="pyoperator">=</span><span class="pystring">'<div style="margin:10px">'</span><span class="pyoperator">,</span> <span class="pytext">undiv</span><span class="pyoperator">=</span><span class="pystring">'</div>'</span><span class="pyoperator">,</span> <span class="pytext">cmp</span><span class="pyoperator">=</span><span class="pytext">None</span><span class="pyoperator">)</span><span class="pyoperator">:</span><span class="pytext"></span></div><p>A generator for dealing with the <tt class="docutils literal"><span class="pre">'indextree'</span></tt> of pages and indexes.</p>
<p>It is recursive for handling the nested 'branches' of the tree.</p>
<p>It goes through all the pages from the top level of the tree
provided.</p>
<p>It yields pages one at a time - index page first. (It sets <tt class="docutils literal"><span class="pre">page['title']</span> <span class="pre">=</span> <span class="pre">True</span></tt>
on index pages - otherwise <tt class="docutils literal"><span class="pre">page['title']</span> <span class="pre">=</span> <span class="pre">False</span></tt>. This allows you to
display them differently).</p>
<p>Before moving down the tree it prints a value called <tt class="docutils literal"><span class="pre">'div'</span></tt> after finishing
a branch it prints 'undiv'.</p>
<p>Default value for div is <tt class="docutils literal"><span class="pre">'<div</span> <span class="pre">style="margin:10px">'</span></tt>.</p>
<p>Default value for undiv is <tt class="docutils literal"><span class="pre">'</div>'</span></tt>.</p>
<p>You would typically use this in a template with something like :</p>
<div class="pysrc"><span class="pykeyword">for</span> <span class="pytext">page</span> <span class="pykeyword">in</span> <span class="pytext">sidebar</span><span class="pyoperator">(</span><span class="pytext">indextree</span><span class="pyoperator">)</span><span class="pyoperator">:</span><br />
<span class="pytext">val</span> <span class="pyoperator">=</span> <span class="pytext">page</span><span class="pyoperator">[</span><span class="pystring">'crumb'</span><span class="pyoperator">]</span><br />
<span class="pytext">link</span> <span class="pyoperator">=</span> <span class="pytext">page</span><span class="pyoperator">[</span><span class="pystring">'target'</span><span class="pyoperator">]</span><br />
<span class="pykeyword">if</span> <span class="pytext">page</span><span class="pyoperator">[</span><span class="pystring">'title'</span><span class="pyoperator">]</span><span class="pyoperator">:</span><br />
<span class="pykeyword">print</span> <span class="pystring">'<br /><strong><a href="%s">%s</a></strong>'</span> \<br />
<span class="pyoperator">%</span> <span class="pyoperator">(</span><span class="pytext">link</span><span class="pyoperator">,</span> <span class="pytext">val</span><span class="pyoperator">)</span><br />
<span class="pykeyword">else</span><span class="pyoperator">:</span><br />
<span class="pykeyword">print</span> <span class="pystring">'<br /><a href="%s">%s</a>'</span> <span class="pyoperator">%</span> <span class="pyoperator">(</span><span class="pytext">link</span><span class="pyoperator">,</span> <span class="pytext">val</span><span class="pyoperator">)</span><span class="pytext"></span></div><p>It might be more sensible to pass in a div with a named class. This makes it
easier to control the style through CSS. For example
<tt class="docutils literal"><span class="pre">for</span> <span class="pre">page</span> <span class="pre">in</span> <span class="pre">sidebar(indextree,</span> <span class="pre">'<div</span> <span class="pre">class="sidebar-links">'):</span></tt>.</p>
<p>You can pass in an optional compare function to sort the pages. An example sort function,
sorting by crumb:</p>
<blockquote>
<tt class="docutils literal"><span class="pre">cmp_page</span> <span class="pre">=</span> <span class="pre">lambda</span> <span class="pre">page1,</span> <span class="pre">page2</span> <span class="pre">:</span> <span class="pre">cmp(page1['crumb'],</span> <span class="pre">page2['crumb'])</span></tt></blockquote>
<p>You could also have (for example) a date uservalue in each page and sort on the date.</p>
</div>
<div class="section" id="include">
<h2><a class="toc-backref" href="#id10">include</a></h2>
<p>This function allows you to include other files within pages or templates. If
the file is not found in the current directory (and is not supplied as a
relative or absolute path), then the file will be looked for in the parent
directories.</p>
<blockquote>
<p><tt class="docutils literal"><span class="pre"><%</span> <span class="pre">include('filename.txt')</span> <span class="pre">%></span></tt></p>
<p><tt class="docutils literal"><span class="pre"><#</span> <span class="pre">print</span> <span class="pre">include('filename.txt')</span> <span class="pre">#></span></tt></p>
</blockquote>
<p>This means you can do things like :</p>
<blockquote>
<tt class="docutils literal"><span class="pre"><%</span> <span class="pre">include('footer.txt')</span> <span class="pre">%></span></tt></blockquote>
<p>in your template. This will include 'footer.txt' in your template. The files you
include can use all the normal template values.</p>
<p>In sub-directories you can provide a different 'footer.txt' which will be used
instead. This allows you to customise <em>parts</em> of the templates in different
parts of the website.</p>
<p>You can also provide an optional argument to 'include', which is to be used
if the file does not exist :</p>
<blockquote>
<p><tt class="docutils literal"><span class="pre"><%</span> <span class="pre">include('body.txt',</span> <span class="pre">body)</span> <span class="pre">%></span></tt></p>
<p><tt class="docutils literal"><span class="pre"><%</span> <span class="pre">include('body.txt',</span> <span class="pre">alternative=body)</span> <span class="pre">%></span></tt></p>
</blockquote>
<p>If at the top level you don't provide a 'body.txt', then the body is used as it
is.</p>
<p>In a sub-directory, you could provide a body text something like :</p>
<pre class="literal-block">
<div class="different_style">
<% body %>
</div>
</pre>
<p>So the body of the page would be wrapped in that sub-directory.</p>
</div>
<div class="section" id="formattime">
<h2><a class="toc-backref" href="#id11">formattime</a></h2>
<p>This is a function to output times in nicely formatted ways. It uses
format strings from the <a class="reference external" href="http://docs.python.org/lib/module-time.html">Python Time Module</a>.</p>
<blockquote>
<tt class="docutils literal"><span class="pre">formattime(t=None,</span> <span class="pre">format="%a,</span> <span class="pre">%d</span> <span class="pre">%b</span> <span class="pre">%Y</span> <span class="pre">%H:%M:%S")</span></tt></blockquote>
<p>Given a time in seconds since the epoch (e.g. the <tt class="docutils literal"><span class="pre">modified</span></tt> value),
convert it into a time formatted using the <tt class="docutils literal"><span class="pre">time.strftime</span></tt> function.</p>
<p>The default format string is <tt class="docutils literal"><span class="pre">"%a,</span> <span class="pre">%d</span> <span class="pre">%b</span> <span class="pre">%Y</span> <span class="pre">%H:%M:%S"</span></tt>. This produces
dates that look like :</p>
<blockquote>
<tt class="docutils literal"><span class="pre">'Fri,</span> <span class="pre">27</span> <span class="pre">Jan</span> <span class="pre">2006</span> <span class="pre">09:53:52'</span></tt></blockquote>
<p>If you don't supply a time, then the current time is used. The time is
always understood as a <em>local time</em>.</p>
<hr class="docutils" />
<table class="docutils footnote" frame="void" id="id2" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>You can keep your own functions in a separate file by putting it somewhere in <tt class="docutils literal"><span class="pre">sys.path</span></tt> and using normal import statements in your template.</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div id="end">
<p><a href="#startcontent">Return to Top</a><br />
<small>Part of the <a href="http://www.voidspace.org.uk/python/rest2web/">rest2web Docs</a></small><br />
<small>Page last modified <strong>Wed Apr 4 15:48:50 2007</strong>.</small>
</p>
</div>
</div></td>
</tr>
<tr>
<td valign="top" align="left" width="25%">
<div id="left-column">
<div id="sidie">
<ul>
<li class="left-navheader-first">
<a href="index.html" class="left-navheader">Index Page</a>
</li>
<li class="left-navheader">Pages</li>
<li><a href="introduction.html">Introduction</a></li>
<li><a href="quickstart.html">Quickstart</a></li>
<li><a href="config_file.html">Config File</a></li>
<li><a href="tutorial.html">Tutorial</a></li>
<li><a href="command_line.html">Command Line</a></li>
<li><a href="force_mode.html">Force Mode</a></li>
<li><a href="templating.html">Templates</a></li>
<li><a href="restindex.html">restindex</a></li>
<li><a href="functions.html">Functions</a></li>
<li><a href="macros.html">Macros</a></li>
<li><a href="special_files.html">Special Files</a></li>
<li class="left-navheader">Sub Sections</li>
<li><a href="reference/index.html">Reference</a></li>
<li><a href="test_site/index.html">Test Site</a></li>
<li><a href="translation/index.html">Translation</a></li>
<li><a href="gallery_test/index.html">Gallery</a></li>
</ul>
</div>
<p class="sidieimg">
<a href="http://www.python.org">
<img src="images/logos/new_python.gif" width="88"
height="103" border="0" alt="Powered by Python" />
</a>
</p>
<p class="sidieimg">
<a href="http://sourceforge.net/donate/index.php?group_id=138579">
<img src="http://images.sourceforge.net/images/project-support.jpg" width="100"
height="32" border="0" alt="Support This Project" />
</a>
</p>
<p class="sidieimg">
<a href="http://www.voidspace.org.uk/python/rest2web/"><img
src="images/logos/rest2web140x62.gif" width="142" height="62"
alt="Site Built with rest2web" /></a><br />
</p>
</div>
</td>
</tr>
</table>
<hr />
<p class="sidieimg">
<a href="http://www.voidspace.org.uk/python/rest2web/"><img src="images/logos/rest2web200x80.gif" width="200" height="80" alt="Site Built with rest2web" /></a>
<a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=138579&type=5" width="210" height="62" alt="SourceForge.net Logo" /></a>
<a href="http://www.opensource.org"><img src="images/logos/osi-certified-120x100.gif" width="120" height="100" alt="Certified Open Source" border="1" /></a>
</p>
<p class="sidieimg">
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-203625-1";
urchinTracker();
</script>
</p>
<p class="sidieimg">
<a href="http://www.voidspace.org.uk/python/index.shtml"><img
src="images/logos/pythonbanner.gif" width="468" height="60"
alt="Python on Voidspace" /></a>
</p>
<div id="footer">
Copyright © Voidspace<br />Design by <a href="http://www.fuchsiashockz.co.uk">Fuchsiashockz</a> | <a href="http://validator.w3.org/check?uri=referer" title="Validate code as W3C XHTML 1.1 Strict Compliant">W3C XHTML 1.1</a> | <a href="http://jigsaw.w3.org/css-validator/check?uri=referer" title="Validate Style Sheet as W3C CSS 2.0 Compliant">W3C CSS 2.0</a>
</div>
</div>
</body>
</html>
|