summaryrefslogtreecommitdiff
path: root/sphinx/builder.py
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2008-06-26 09:40:42 +0000
committerArmin Ronacher <armin.ronacher@active-4.com>2008-06-26 09:40:42 +0000
commit95f7883e94fd42379d9eea8337fcf3ec93d28d5a (patch)
treef3b2519bf0909cfcbf453ba24697130cb763c005 /sphinx/builder.py
parentba99598c656dc608222b9ff68d10d45f686852bd (diff)
downloadsphinx-git-95f7883e94fd42379d9eea8337fcf3ec93d28d5a.tar.gz
Refactored pickle builder into a SerializingHTMLBuilder and PickleHTMLBuilder. Subclasses can change the serialization format easily.
Diffstat (limited to 'sphinx/builder.py')
-rw-r--r--sphinx/builder.py41
1 files changed, 29 insertions, 12 deletions
diff --git a/sphinx/builder.py b/sphinx/builder.py
index 851eea783..cd8c40311 100644
--- a/sphinx/builder.py
+++ b/sphinx/builder.py
@@ -297,6 +297,7 @@ class StandaloneHTMLBuilder(Builder):
indexer_format = 'json'
supported_image_types = ['image/svg+xml', 'image/png', 'image/gif',
'image/jpeg']
+ searchindex_filename = 'searchindex.json'
def init(self):
"""Load templates."""
@@ -623,7 +624,7 @@ class StandaloneHTMLBuilder(Builder):
def load_indexer(self, docnames):
try:
- f = open(path.join(self.outdir, 'searchindex.'+self.indexer_format), 'r')
+ f = open(path.join(self.outdir, self.searchindex_filename), 'r')
try:
self.indexer.load(f, self.indexer_format)
finally:
@@ -638,7 +639,7 @@ class StandaloneHTMLBuilder(Builder):
if self.indexer is not None and title:
self.indexer.feed(pagename, title, doctree)
- # --------- these are overwritten by the Pickle builder
+ # --------- these are overwritten by the serialization builder
def get_target_uri(self, docname, typ=None):
return docname + self.out_suffix
@@ -689,13 +690,21 @@ class StandaloneHTMLBuilder(Builder):
f.close()
-class PickleHTMLBuilder(StandaloneHTMLBuilder):
+class SerializingHTMLBuilder(StandaloneHTMLBuilder):
"""
- Builds HTML docs without rendering templates.
+ An abstract builder that serializes the HTML generated.
"""
- name = 'pickle'
- out_suffix = '.fpickle'
- indexer_format = 'pickle'
+ #: the serializing implementation to use. Set this to a module that
+ #: implements a `dump`, `load`, `dumps` and `loads` functions
+ #: (pickle, simplejson etc.)
+ implementation = None
+
+ #: the filename for the global context file
+ globalcontext_filename = None
+
+ #: If set to `None` the indexer uses the serialization implementation
+ indexer_format = None
+
supported_image_types = ('image/svg+xml', 'image/png', 'image/gif',
'image/jpeg')
@@ -724,7 +733,7 @@ class PickleHTMLBuilder(StandaloneHTMLBuilder):
ensuredir(path.dirname(outfilename))
f = open(outfilename, 'wb')
try:
- pickle.dump(ctx, f, 2)
+ self.implementation.dump(ctx, f, 2)
finally:
f.close()
@@ -738,18 +747,18 @@ class PickleHTMLBuilder(StandaloneHTMLBuilder):
def handle_finish(self):
# dump the global context
- outfilename = path.join(self.outdir, 'globalcontext.pickle')
+ outfilename = path.join(self.outdir, self.globalcontext_filename)
f = open(outfilename, 'wb')
try:
- pickle.dump(self.globalcontext, f, 2)
+ self.implementation.dump(self.globalcontext, f, 2)
finally:
f.close()
self.info(bold('dumping search index...'))
self.indexer.prune(self.env.all_docs)
- f = open(path.join(self.outdir, 'searchindex.pickle'), 'wb')
+ f = open(path.join(self.outdir, self.searchindex_filename), 'wb')
try:
- self.indexer.dump(f, 'pickle')
+ self.indexer.dump(f, self.indexer_format or self.implementation)
finally:
f.close()
@@ -763,6 +772,14 @@ class PickleHTMLBuilder(StandaloneHTMLBuilder):
open(path.join(self.outdir, LAST_BUILD_FILENAME), 'w').close()
+class PickleHTMLBuilder(SerializingHTMLBuilder):
+ implementation = pickle
+ name = 'pickle'
+ out_suffix = '.fpickle'
+ globalcontext_filename = 'globalcontext.pickle'
+ searchindex_filename = 'searchindex.pickle'
+
+
class HTMLHelpBuilder(StandaloneHTMLBuilder):
"""
Builder that also outputs Windows HTML help project, contents and index files.