summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacob <jacob@panda>2010-06-07 16:09:19 -0500
committerjacob <jacob@panda>2010-06-07 16:09:19 -0500
commit8e8fd9ca98c7335fab76797c6428d1b8769b33b9 (patch)
treedc1e5a853b11c91bca221d81c1356435708771ff
parentb1f39eac033517bbb5bc56f2d022d1eb298a466c (diff)
downloadsphinx-git-8e8fd9ca98c7335fab76797c6428d1b8769b33b9.tar.gz
Now serves static body.
-rw-r--r--doc/web/api.rst2
-rw-r--r--sphinx/builders/websupport.py25
-rw-r--r--sphinx/locale/__init__.py3
-rw-r--r--sphinx/writers/websupport.py38
4 files changed, 21 insertions, 47 deletions
diff --git a/doc/web/api.rst b/doc/web/api.rst
index a371fe3fc..66e89af3e 100644
--- a/doc/web/api.rst
+++ b/doc/web/api.rst
@@ -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='')
diff --git a/sphinx/builders/websupport.py b/sphinx/builders/websupport.py
index 48e895db5..8bc94174b 100644
--- a/sphinx/builders/websupport.py
+++ b/sphinx/builders/websupport.py
@@ -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
diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py
index badcca1cd..43e0942cd 100644
--- a/sphinx/locale/__init__.py
+++ b/sphinx/locale/__init__.py
@@ -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
diff --git a/sphinx/writers/websupport.py b/sphinx/writers/websupport.py
index 6d255e64c..d99d7dc91 100644
--- a/sphinx/writers/websupport.py
+++ b/sphinx/writers/websupport.py
@@ -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)