/usr/share/doc/rest2web/html/reference/plugins.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 | <!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 rest2web plugin System</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><a href="index.html">Reference</a></li>
<li>></li>
<li>Plugins</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-rest2web-plugin-system">
<h1 class="title">The rest2web plugin System</h1>
<h2 class="subtitle" id="roll-your-own-features">Roll Your Own Features</h2>
<div class="section" id="plugins">
<h1>Plugins</h1>
<div class="note">
<p class="first admonition-title">Note</p>
<p>The plugin system is not yet production ready.</p>
<p>The main problem is that plugins currently have to return encoded byte
strings in the same encoding as the content. This is fine so long as you
can gurantee that the output of your plugin can always be expressed in the
encoding of your content !</p>
<p class="last">I also haven't implemented support for global plugins.</p>
</div>
<ul class="simple">
<li>XXXX __init__ should call start !</li>
<li>XXXX document that changes to uservalues will have inconsistent results - don't do it !</li>
</ul>
<p>The plugin system allows you to integrate your own functionality into rest2web. You can use this to implement plugins that process pages or generate their output in ways too complex for the templates.</p>
<p>Plugins can either be global, or just applied to individual pages.</p>
<p>You create plugins by writing a class that inherits from <tt class="docutils literal"><span class="pre">rest2web.PluginClass.PluginClass</span></tt>, place it in a module in the plugins directory, and configure your pages/site to use it.</p>
<p>An example of a plugin that works for individual pages would be a <a class="reference external" href="http://www.voidspace.org.uk/python/rest2web/reference/gallery.html">gallery</a> - creating pages from directories of images.</p>
<p>An example of a global plugin could be a sitemap generator or a search engine that indexes every page.</p>
<div class="section" id="the-basic-principle">
<h2>The Basic Principle</h2>
<p>Your plugin name is the module name. So <tt class="docutils literal"><span class="pre">gallery.py</span></tt> is the <tt class="docutils literal"><span class="pre">gallery</span></tt> plugin. You module must contain a class called <tt class="docutils literal"><span class="pre">Plugin</span></tt> - this will be imported when it is first used.</p>
<p>Your plugin class only needs to implement the relevant methods. For a global plugin this will include the <tt class="docutils literal"><span class="pre">start</span></tt> and <tt class="docutils literal"><span class="pre">end</span></tt> methods. For a normal plugin you might only need to implement the <tt class="docutils literal"><span class="pre">page</span></tt> method.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">You shouldn't override the <tt class="docutils literal"><span class="pre">__init__</span></tt> method. Use <tt class="docutils literal"><span class="pre">start</span></tt> instead.</p>
</div>
<p>Each page specifies which normal plugins are being used (in the restindex). Each of the plugins (which may not be any of course), plus all the global ones, are called for every page.</p>
<p>What this means is that the <tt class="docutils literal"><span class="pre">page</span></tt> method of your <tt class="docutils literal"><span class="pre">Plugin</span></tt> class is called - and passed the parameters :</p>
<pre class="literal-block">
page(self, content, encoding, filepath, targetr, estindex, uservalues)
</pre>
<p>This means that if you want to pass values or settings from the page to the plugin, they can be specified in the <em>uservalues</em>.</p>
<p>The page method (when it has done it's work) should return a tuple of :</p>
<pre class="literal-block">
(content, encoding, newvalues)
</pre>
<p><em>newvalues</em> is a dictionary that is used to update the uservalues. The values you return here can be used as variables in your page.</p>
<p>When it is first initialised, <em>every</em> plugin is given a reference to the processor object and the original config file. You can access this from within your plugin methods using :</p>
<div class="pysrc"><span class="pytext">processor</span> <span class="pyoperator">=</span> <span class="pytext">self</span><span class="pyoperator">.</span><span class="pytext">processor</span><br />
<span class="pytext">config</span> <span class="pyoperator">=</span> <span class="pytext">self</span><span class="pyoperator">.</span><span class="pytext">config</span><br />
<span class="pycomment">#<br />
</span><span class="pycomment"># config is a dictionary like object<br />
</span><span class="pytext">value</span> <span class="pyoperator">=</span> <span class="pytext">config</span><span class="pyoperator">[</span><span class="pystring">'value'</span><span class="pyoperator">]</span><span class="pytext"></span></div><p>This means two things :</p>
<ol class="arabic">
<li><p class="first">Global plugins can have universal settings in the site config file.</p>
</li>
<li><p class="first">You can access the processor attributes like <tt class="docutils literal"><span class="pre">dir</span></tt>, <tt class="docutils literal"><span class="pre">dir_as_url</span></tt>, etc.</p>
<pre class="literal-block">
dir = self.processor.dir
</pre>
</li>
</ol>
</div>
<div class="section" id="global-plugins">
<h2>Global Plugins</h2>
<p>When you run rest2web, global plugins are initialised (and their <tt class="docutils literal"><span class="pre">start</span></tt> method is called). They are then called for every page.</p>
<p>A global plugin can implement any of the <tt class="docutils literal"><span class="pre">start</span></tt>, <tt class="docutils literal"><span class="pre">page</span></tt>, and <tt class="docutils literal"><span class="pre">end</span></tt> methods. You only need to implement the methods you are using.</p>
<div class="pysrc"><span class="pykeyword">from</span> <span class="pytext">rest2web</span><span class="pyoperator">.</span><span class="pytext">PluginClass</span> <span class="pykeyword">import</span> <span class="pytext">PluginClass</span><br />
<br />
<span class="pykeyword">class</span> <span class="pytext">Plugin</span><span class="pyoperator">(</span><span class="pytext">PluginClass</span><span class="pyoperator">)</span><span class="pyoperator">:</span><br />
<br />
<span class="pykeyword">def</span> <span class="pytext">start</span><span class="pyoperator">(</span><span class="pytext">self</span><span class="pyoperator">)</span><span class="pyoperator">:</span><br />
<span class="pystring">"""<br />
Called when the plugin is initialised.<br />
For global plugins, this is when rest2web starts up.<br />
"""</span><br />
<span class="pykeyword">pass</span><br />
<br />
<span class="pykeyword">def</span> <span class="pytext">end</span><span class="pyoperator">(</span><span class="pytext">self</span><span class="pyoperator">)</span><span class="pyoperator">:</span><br />
<span class="pystring">"""<br />
Called after the last page has been rendered.<br />
Only for global plugins.<br />
"""</span><br />
<span class="pykeyword">pass</span><br />
<br />
<span class="pykeyword">def</span> <span class="pytext">page</span><span class="pyoperator">(</span><span class="pytext">self</span><span class="pyoperator">,</span> <span class="pytext">content</span><span class="pyoperator">,</span> <span class="pytext">filepath</span><span class="pyoperator">,</span> <span class="pytext">target</span><span class="pyoperator">,</span> <span class="pytext">encoding</span><span class="pyoperator">,</span> <span class="pytext">restindex</span><span class="pyoperator">,</span> <span class="pytext">uservalues</span><span class="pyoperator">)</span><span class="pyoperator">:</span><br />
<span class="pystring">"""<br />
Called for every page with globals.<br />
"""</span><br />
<span class="pytext">newvalues</span> <span class="pyoperator">=</span> <span class="pyoperator">{</span><span class="pyoperator">}</span><br />
<span class="pykeyword">return</span> <span class="pyoperator">(</span><span class="pytext">content</span><span class="pyoperator">,</span> <span class="pytext">encoding</span><span class="pyoperator">,</span> <span class="pytext">newvalues</span><span class="pyoperator">)</span><span class="pytext"></span></div></div>
<div class="section" id="normal-plugins">
<h2>Normal Plugins</h2>
<p>A normal plugin will only be used for individual pages. You specify plugins to use on a page with the <tt class="docutils literal"><span class="pre">plugins</span></tt> keyword in the restindex :</p>
<pre class="literal-block">
plugins: gallery, plugin2
</pre>
<p>Normal plugins can implement the <tt class="docutils literal"><span class="pre">start</span></tt> and <tt class="docutils literal"><span class="pre">page</span></tt> methods.</p>
<div class="pysrc"><span class="pykeyword">from</span> <span class="pytext">rest2web</span><span class="pyoperator">.</span><span class="pytext">PluginClass</span> <span class="pykeyword">import</span> <span class="pytext">PluginClass</span><br />
<br />
<span class="pykeyword">class</span> <span class="pytext">Plugin</span><span class="pyoperator">(</span><span class="pytext">PluginClass</span><span class="pyoperator">)</span><span class="pyoperator">:</span><br />
<br />
<span class="pykeyword">def</span> <span class="pytext">start</span><span class="pyoperator">(</span><span class="pytext">self</span><span class="pyoperator">)</span><span class="pyoperator">:</span><br />
<span class="pystring">"""<br />
Called when the plugin is initialised.<br />
For normal plugins, this is when they are first used.<br />
"""</span><br />
<span class="pykeyword">pass</span><br />
<br />
<span class="pykeyword">def</span> <span class="pytext">page</span><span class="pyoperator">(</span><span class="pytext">self</span><span class="pyoperator">,</span> <span class="pytext">content</span><span class="pyoperator">,</span> <span class="pytext">encoding</span><span class="pyoperator">,</span> <span class="pytext">filepath</span><span class="pyoperator">,</span> <span class="pytext">target</span><span class="pyoperator">,</span> <span class="pytext">restindex</span><span class="pyoperator">,</span> <span class="pytext">uservalues</span><span class="pyoperator">)</span><span class="pyoperator">:</span><br />
<span class="pystring">"""<br />
Called only for pages using the plugin.<br />
"""</span><br />
<span class="pytext">newvalues</span> <span class="pyoperator">=</span> <span class="pyoperator">{</span><span class="pyoperator">}</span><br />
<span class="pykeyword">return</span> <span class="pyoperator">(</span><span class="pytext">content</span><span class="pyoperator">,</span> <span class="pytext">encoding</span><span class="pyoperator">,</span> <span class="pytext">newvalues</span><span class="pyoperator">)</span><span class="pytext"></span></div><p>For an example of this kind of plugin, have a look at the <a class="reference external" href="http://www.voidspace.org.uk/python/rest2web/reference/gallery.html">gallery</a> plugin.</p>
</div>
</div>
<div class="section" id="the-page-method">
<h1>The Page Method</h1>
<p>Todo....</p>
</div>
<div class="section" id="encoding-issues">
<h1>Encoding Issues</h1>
<p>Todo...</p>
</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>Mon Apr 3 19:30:38 2006</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="todo.html">TODO/ISSUES</a></li>
<li><a href="uservalues.html">uservalues</a></li>
<li><a href="encodings.html">Encodings</a></li>
<li><a href="indextree.html">indextree</a></li>
<li><a href="changelog.html">changelog</a></li>
<li><a href="smilies.html">Smilies</a></li>
<li><a href="plugins.html">Plugins</a></li>
<li><a href="gallery.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>
|