Render reStructuredText files
Zope3 has autorendering of '.stx', '.txt' and '.rst' files that are located inside directoryresource folders enabled by default. The Grok special 'static' folder is a directoryresource folder too, but Grok has deliberately disabled autorendering inside this foldertype.
d2m.rendersource provides a way to get reStructuredText formatted files rendered, simply by creating a grok.View class and dropping the ReST formatted file inside the associated template folder, following the usual naming rules. The file extension for reStructuredText formatted templates is registered as '.rst'.
--- app.py ---class Overview(grok.View): pass
--- app_templates/overview.rst ---
ReStructuredText ================
rst formatted text ...
The templates are rendered to full HTML pages through docutils, including the default docutils stylesheet. The stylesheet selection is now configurable - you can link to a stylesheet located inside the 'static' folder or somewhere else on the web.
To configure the stylesheet used with your template, add a method 'namespace' to your view class:
--- app.py ---
class Overview(grok.View): def namespace(self): # compute the stylesheet path to the file inside the 'static' folder, # eg. 'grok.css' stylesheet=self.static['grok.css']() # enable absolut URL handling, disable embedding return {'settings_overrides': {'stylesheet': stylesheet, 'stylesheet_path': None, 'embed_stylesheet': 0, }}
Other docutils related options can be added to the 'settings_overrides' dictionary. CF grok_overview.rst for more info on the 'namespace' method.
Comment
Update: the source distribution archive is now available at PyPi


Comment
$ sudo easy_install-2.4 --dry-run d2m.rendersource [sudo] password for peterbe: Searching for d2m.rendersource Reading http://pypi.python.org/simple/d2m.rendersource/ Reading http://blog.d2m.at/ Reading svn://svn.d2m.at/Grok/d2m.rendersource Download error: unknown url type: svn -- Some packages may not be found! Reading svn://svn.d2m.at/Grok/d2m.rendersource Download error: unknown url type: svn -- Some packages may not be found! No local packages or download links found for d2m.rendersource error: Could not find suitable distribution for Requirement.parse('d2m.rendersource')