diff options
author | jacob <jacob@panda> | 2010-06-23 14:37:07 -0500 |
---|---|---|
committer | jacob <jacob@panda> | 2010-06-23 14:37:07 -0500 |
commit | 00f841be2ab3bb44766a1cff18924f6e65a98207 (patch) | |
tree | a2be9063252cb6c8ab13c358aedd659e21407f50 /sphinx/builders/websupport.py | |
parent | 95d95edacc09715b1e4834b9ae8b787832d7efcf (diff) | |
download | sphinx-git-00f841be2ab3bb44766a1cff18924f6e65a98207.tar.gz |
Added relbar and sidebar to documents
Diffstat (limited to 'sphinx/builders/websupport.py')
-rw-r--r-- | sphinx/builders/websupport.py | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/sphinx/builders/websupport.py b/sphinx/builders/websupport.py index 8bc94174b..55b90e683 100644 --- a/sphinx/builders/websupport.py +++ b/sphinx/builders/websupport.py @@ -9,22 +9,81 @@ :license: BSD, see LICENSE for details. """ -from sphinx.builders.html import PickleHTMLBuilder +import cPickle as pickle +from os import path + +from sphinx.util.osutil import os_path, relative_uri, ensuredir, copyfile +from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.writers.websupport import WebSupportTranslator -class WebSupportBuilder(PickleHTMLBuilder): +class WebSupportBuilder(StandaloneHTMLBuilder): """ Builds documents for the web support package. """ name = 'websupport' - + out_suffix = '.fpickle' + def init_translator_class(self): self.translator_class = WebSupportTranslator def write_doc(self, docname, doctree): # The translator needs the docname to generate ids. self.docname = docname - PickleHTMLBuilder.write_doc(self, docname, doctree) + StandaloneHTMLBuilder.write_doc(self, docname, doctree) def get_target_uri(self, docname, typ=None): return docname + + def handle_page(self, pagename, addctx, templatename='page.html', + outfilename=None, event_arg=None): + # This is mostly copied from StandaloneHTMLBuilder. However, instead + # of rendering the template and saving the html, create a context + # dict and pickle it. + ctx = self.globalcontext.copy() + ctx['pagename'] = pagename + + def pathto(otheruri, resource=False, + baseuri=self.get_target_uri(pagename)): + if not resource: + otheruri = self.get_target_uri(otheruri) + uri = relative_uri(baseuri, otheruri) or '#' + return uri + ctx['pathto'] = pathto + ctx['hasdoc'] = lambda name: name in self.env.all_docs + ctx['encoding'] = encoding = self.config.html_output_encoding + ctx['toctree'] = lambda **kw: self._get_local_toctree(pagename, **kw) + self.add_sidebars(pagename, ctx) + ctx.update(addctx) + + self.app.emit('html-page-context', pagename, templatename, + ctx, event_arg) + + # Create a dict that will be pickled and used by webapps. + doc_ctx = {'body': ctx.get('body', '')} + # Partially render the html template to proved a more useful ctx. + template = self.templates.environment.get_template(templatename) + template_module = template.make_module(ctx) + if hasattr(template_module, 'sidebar'): + doc_ctx['sidebar'] = template_module.sidebar() + if hasattr(template_module, 'relbar'): + doc_ctx['relbar'] = template_module.relbar() + + if not outfilename: + outfilename = path.join(self.outdir, + os_path(pagename) + self.out_suffix) + + ensuredir(path.dirname(outfilename)) + f = open(outfilename, 'wb') + try: + pickle.dump(doc_ctx, f, 2) + finally: + f.close() + + # if there is a source file, copy the source file for the + # "show source" link + if ctx.get('sourcename'): + source_name = path.join(self.outdir, '_sources', + os_path(ctx['sourcename'])) + ensuredir(path.dirname(source_name)) + copyfile(self.env.doc2path(pagename), source_name) + |