[Pieforms-commit] SF.net SVN: pieforms: [196] pieforms-php5/branches/0.2.0/doc/makedocs.py
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2007-03-18 12:37:36
|
Revision: 196 http://svn.sourceforge.net/pieforms/?rev=196&view=rev Author: oracleshinoda Date: 2007-03-18 01:59:16 -0700 (Sun, 18 Mar 2007) Log Message: ----------- Added script to build documentation Added Paths: ----------- pieforms-php5/branches/0.2.0/doc/makedocs.py Added: pieforms-php5/branches/0.2.0/doc/makedocs.py =================================================================== --- pieforms-php5/branches/0.2.0/doc/makedocs.py (rev 0) +++ pieforms-php5/branches/0.2.0/doc/makedocs.py 2007-03-18 08:59:16 UTC (rev 196) @@ -0,0 +1,111 @@ +#!/usr/bin/env python +# +# @todo: script that uses docutils to build documentation +# +# This script should somehow do magical geshi processing too... +# See the MochiKit make_docs.py script +# +import os +import subprocess +try: + from pg_resources import require + require("docutils>0.3.9") +except ImportError: + pass +from docutils import nodes, utils +from docutils.core import publish_parts +from docutils.parsers import rst +from docutils.parsers.rst import roles +from docutils.parsers.rst import directives +from docutils.parsers.rst.directives import body + +TEMPLATE = u"""%(html_prolog)s +<html xmlns=http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +%(html_head)s +<link rel="stylesheet" type="text/css" href="%(css_path)s" /> +</head> +<body> +%(html_body)s +<div id="footer">Pieforms by <a href="http://nigel.mcnie.name/">Nigel McNie</a> and <a href="http://pieforms.sourceforge.net/about#authors">others</a>, +© 2006 Catalyst IT Ltd. Pieforms is released under the <a href="http://gnu.org/licences/gpl.html">GNU GPL</a></div> +</body> +</html> +""" + +def role_breadcrumbs(role, rawtext, text, lineno, inliner, options=None, content=[]): + if options is None: + options = {} + + links = [] + parts = text.split(' > ') + dirs = '../' * len(parts) + for title in parts: + dirs = dirs[:-3] + links.append("<a href=\"" + dirs + "\">" + title + "</a>") + + html = '<div id="breadcrumbs"><a href="http://pieforms.sourceforge.net/">Pieforms Home</a> » ' + ' » '.join(links) + '</div>' + + return [nodes.raw('', html, format='html')], [] + +roles.register_canonical_role('breadcrumbs', role_breadcrumbs) + +def highlighter(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): + # block_text contains the full text + language = arguments[0] + program = [r"php", "highlighter.php", block_text, language] + + call = subprocess.Popen(program, 0, None, None, subprocess.PIPE) + result = call.stdout.read() + return [nodes.raw('', result, format='html')] + +highlighter.content = True +highlighter.arguments = (1, 0, False) + +directives.register_directive('highlight', highlighter) + +def main(): + basepath = 'rst' + destpath = 'html' + for root, dirs, files in os.walk(basepath): + if '.svn' in dirs: + dirs.remove('.svn') + + # Work out the directory the file is to be placed in. Remove the + # trailing slash also, since it interferes with CSS path + # generation + destdirname = os.path.join(destpath, root[len(basepath)+1:]) + if destdirname.endswith('/'): + destdirname = destdirname[:-1] + + if not os.path.exists(destdirname): + os.mkdir(destdirname) + csspath = '../' * (len(destdirname.split('/')) - 1) + 'style.css' + + for fn in files: + basefn, ext = os.path.splitext(fn) + if ext == '.rst': + srcfn = os.path.join(root, fn) + dest = os.path.join(destdirname, basefn + '.html') + # caching here + print srcfn + parts = publish_parts( + source_path=srcfn, + source=file(srcfn, 'rb').read().decode('utf8'), + destination_path=dest, + writer_name='html', + settings_overrides=dict( + embed_stylesheet=False + ) + ) + parts['html_head'] = parts['html_head'] % ('utf-8') + parts['html_prolog'] = parts['html_prolog'] % ('utf-8') + parts['css_path'] = csspath + doc = (TEMPLATE % parts).encode('utf8') + out = file(dest, 'wb') + out.write(doc) + out.close() + + +if __name__ == '__main__': + main() Property changes on: pieforms-php5/branches/0.2.0/doc/makedocs.py ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |