summaryrefslogtreecommitdiff
path: root/sphinx/builders/websupport.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/builders/websupport.py')
-rw-r--r--sphinx/builders/websupport.py37
1 files changed, 31 insertions, 6 deletions
diff --git a/sphinx/builders/websupport.py b/sphinx/builders/websupport.py
index 40901eef9..eeadfc231 100644
--- a/sphinx/builders/websupport.py
+++ b/sphinx/builders/websupport.py
@@ -11,6 +11,9 @@
import cPickle as pickle
from os import path
+import posixpath
+import shutil
+from docutils.io import StringOutput
from sphinx.util.osutil import os_path, relative_uri, ensuredir, copyfile
from sphinx.builders.html import StandaloneHTMLBuilder
@@ -29,7 +32,21 @@ class WebSupportBuilder(StandaloneHTMLBuilder):
def write_doc(self, docname, doctree):
# The translator needs the docname to generate ids.
self.cur_docname = docname
- StandaloneHTMLBuilder.write_doc(self, docname, doctree)
+ destination = StringOutput(encoding='utf-8')
+ doctree.settings = self.docsettings
+
+ self.secnumbers = self.env.toc_secnumbers.get(docname, {})
+ self.imgpath = '/' + posixpath.join(self.app.staticdir, '_images')
+ self.post_process_images(doctree)
+ self.dlpath = '/' + posixpath.join(self.app.staticdir, '_downloads')
+ self.docwriter.write(doctree, destination)
+ self.docwriter.assemble_parts()
+ body = self.docwriter.parts['fragment']
+ metatags = self.docwriter.clean_meta
+
+ ctx = self.get_doc_context(docname, body, metatags)
+ self.index_page(docname, doctree, ctx.get('title', ''))
+ self.handle_page(docname, ctx, event_arg=doctree)
def get_target_uri(self, docname, typ=None):
return docname
@@ -50,8 +67,9 @@ class WebSupportBuilder(StandaloneHTMLBuilder):
baseuri=self.get_target_uri(pagename)):
if not resource:
otheruri = self.get_target_uri(otheruri)
- uri = relative_uri(baseuri, otheruri) or '#'
- return uri
+ return relative_uri(baseuri, otheruri) or '#'
+ else:
+ return '/' + posixpath.join(self.app.staticdir, otheruri)
ctx['pathto'] = pathto
ctx['hasdoc'] = lambda name: name in self.env.all_docs
ctx['encoding'] = encoding = self.config.html_output_encoding
@@ -74,7 +92,7 @@ class WebSupportBuilder(StandaloneHTMLBuilder):
doc_ctx['relbar'] = template_module.relbar()
if not outfilename:
- outfilename = path.join(self.outdir,
+ outfilename = path.join(self.outdir, 'pickles',
os_path(pagename) + self.out_suffix)
ensuredir(path.dirname(outfilename))
@@ -87,10 +105,17 @@ class WebSupportBuilder(StandaloneHTMLBuilder):
# 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']))
+ source_name = path.join(self.outdir, self.app.staticdir,
+ '_sources', os_path(ctx['sourcename']))
ensuredir(path.dirname(source_name))
copyfile(self.env.doc2path(pagename), source_name)
+ def handle_finish(self):
+ StandaloneHTMLBuilder.handle_finish(self)
+ shutil.move(path.join(self.outdir, '_images'),
+ path.join(self.outdir, self.app.staticdir, '_images'))
+ shutil.move(path.join(self.outdir, '_static'),
+ path.join(self.outdir, self.app.staticdir, '_static'))
+
def dump_search_index(self):
self.indexer.finish_indexing()