mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Now serves static body.
This commit is contained in:
parent
b1f39eac03
commit
8e8fd9ca98
@ -7,7 +7,7 @@ Web Support API
|
||||
.. class:: WebSupport
|
||||
|
||||
The :class:`WebSupport` class provides a central interface for
|
||||
working with :ref:`~sphinx.websupport.document.Document's.
|
||||
working with :class:`~sphinx.websupport.document.Document`'s.
|
||||
|
||||
.. method:: init(srcdir='', outdir='')
|
||||
|
||||
|
@ -9,9 +9,6 @@
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
from os import path
|
||||
|
||||
from sphinx.util.osutil import ensuredir, os_path
|
||||
from sphinx.builders.html import PickleHTMLBuilder
|
||||
from sphinx.writers.websupport import WebSupportTranslator
|
||||
|
||||
@ -20,7 +17,6 @@ class WebSupportBuilder(PickleHTMLBuilder):
|
||||
Builds documents for the web support package.
|
||||
"""
|
||||
name = 'websupport'
|
||||
template_suffix = '.html'
|
||||
|
||||
def init_translator_class(self):
|
||||
self.translator_class = WebSupportTranslator
|
||||
@ -30,26 +26,5 @@ class WebSupportBuilder(PickleHTMLBuilder):
|
||||
self.docname = docname
|
||||
PickleHTMLBuilder.write_doc(self, docname, doctree)
|
||||
|
||||
def handle_page(self, pagename, ctx, templatename='', **ignored):
|
||||
# Mostly copied from PickleHTMLBuilder.
|
||||
ctx['current_page_name'] = ctx['pagename'] = pagename
|
||||
self.add_sidebars(pagename, ctx)
|
||||
|
||||
self.app.emit('html-page-context', pagename, ctx)
|
||||
|
||||
# Instead of pickling ctx as PickleHTMLBuilder does, we
|
||||
# have created a Document object and pickle that.
|
||||
document = self.docwriter.visitor.support_document
|
||||
document.__dict__.update(ctx)
|
||||
|
||||
doc_filename = path.join(self.outdir,
|
||||
os_path(pagename) + self.out_suffix)
|
||||
ensuredir(path.dirname(doc_filename))
|
||||
f = open(doc_filename, 'wb')
|
||||
try:
|
||||
self.implementation.dump(document, f)
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def get_target_uri(self, docname, typ=None):
|
||||
return docname
|
||||
|
@ -32,6 +32,9 @@ class _TranslationProxy(UserString.UserString, object):
|
||||
return unicode(func)
|
||||
return object.__new__(cls)
|
||||
|
||||
def __getnewargs__(self):
|
||||
return (self._func,) + self._args
|
||||
|
||||
def __init__(self, func, *args):
|
||||
self._func = func
|
||||
self._args = args
|
||||
|
@ -10,7 +10,6 @@
|
||||
"""
|
||||
|
||||
from sphinx.writers.html import HTMLTranslator
|
||||
from sphinx.websupport.document import Document
|
||||
|
||||
class WebSupportTranslator(HTMLTranslator):
|
||||
"""
|
||||
@ -23,7 +22,6 @@ class WebSupportTranslator(HTMLTranslator):
|
||||
self.init_support()
|
||||
|
||||
def init_support(self):
|
||||
self.support_document = Document()
|
||||
self.in_commentable = False
|
||||
self.current_id = 0
|
||||
|
||||
@ -38,29 +36,27 @@ class WebSupportTranslator(HTMLTranslator):
|
||||
self.handle_depart_commentable(node)
|
||||
|
||||
def handle_visit_commentable(self, node):
|
||||
# If we are already recording a commentable slice we don't do
|
||||
# anything. We can't handle nesting.
|
||||
if not self.in_commentable:
|
||||
self.support_document.add_slice(''.join(self.body))
|
||||
node.commented = self.in_commentable = True
|
||||
self.body = []
|
||||
else:
|
||||
# If this node is nested inside another commentable node this
|
||||
# node will not be commented.
|
||||
if self.in_commentable:
|
||||
node.commented = False
|
||||
else:
|
||||
node.commented = self.in_commentable = True
|
||||
node.id = self.create_id(node)
|
||||
# We will place the node in the HTML id attribute. If the node
|
||||
# already has another id (for indexing purposes) put an empty
|
||||
# span with the existing id directly before this node's HTML.
|
||||
if node.attributes['ids']:
|
||||
self.body.append('<span id="%s"></span>'
|
||||
% node.attributes['ids'][0])
|
||||
node.attributes['ids'] = [node.id]
|
||||
node.attributes['classes'].append('spxcmt')
|
||||
|
||||
def handle_depart_commentable(self, node):
|
||||
assert(self.in_commentable)
|
||||
if node.commented:
|
||||
slice_id = '%s-%s' % (self.builder.docname, self.current_id)
|
||||
self.current_id += 1
|
||||
|
||||
body = ''.join(self.body)
|
||||
self.support_document.add_slice(body, slice_id, commentable=True)
|
||||
|
||||
self.in_commentable = False
|
||||
self.body = []
|
||||
|
||||
def depart_document(self, node):
|
||||
assert(not self.in_commentable)
|
||||
self.support_document.add_slice(''.join(self.body))
|
||||
|
||||
|
||||
def create_id(self, node):
|
||||
self.current_id += 1
|
||||
return '%s_%s' % (node.__class__.__name__, self.current_id)
|
||||
|
Loading…
Reference in New Issue
Block a user