summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sphinx/builders/websupport.py37
-rw-r--r--sphinx/websupport/__init__.py17
2 files changed, 39 insertions, 15 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()
diff --git a/sphinx/websupport/__init__.py b/sphinx/websupport/__init__.py
index e04e6899b..29a0b0eee 100644
--- a/sphinx/websupport/__init__.py
+++ b/sphinx/websupport/__init__.py
@@ -24,6 +24,7 @@ from sphinx.websupport.errors import *
class WebSupportApp(Sphinx):
def __init__(self, *args, **kwargs):
+ self.staticdir = kwargs.pop('staticdir', None)
self.search = kwargs.pop('search', None)
self.storage = kwargs.pop('storage', None)
Sphinx.__init__(self, *args, **kwargs)
@@ -34,18 +35,15 @@ class WebSupport(object):
"""
def __init__(self, srcdir='', outdir='', datadir='', search=None,
storage=None, status=sys.stdout, warning=sys.stderr,
- moderation_callback=None):
+ moderation_callback=None, staticdir='static'):
self.srcdir = srcdir
- self.outdir = outdir or path.join(self.srcdir, '_build',
- 'websupport')
- self.moderation_callback = moderation_callback
- self._init_templating()
-
self.outdir = outdir or datadir
-
+ self.staticdir = staticdir.strip('/')
self.status = status
self.warning = warning
+ self.moderation_callback = moderation_callback
+ self._init_templating()
self._init_search(search)
self._init_storage(storage)
@@ -101,7 +99,8 @@ class WebSupport(object):
app = WebSupportApp(self.srcdir, self.srcdir,
self.outdir, doctreedir, 'websupport',
search=self.search, status=self.status,
- warning=self.warning, storage=self.storage)
+ warning=self.warning, storage=self.storage,
+ staticdir=self.staticdir)
self.storage.pre_build()
app.build()
@@ -129,7 +128,7 @@ class WebSupport(object):
:param docname: the name of the document to load.
"""
- infilename = path.join(self.outdir, docname + '.fpickle')
+ infilename = path.join(self.outdir, 'pickles', docname + '.fpickle')
try:
f = open(infilename, 'rb')