gminick / sphinx-gsoc2009
fork of sphinx
A support for per-paragraph comments and user/developer interface for submitting/committing fixes.
Clone this repository (size: 8.4 MB): HTTPS / SSH
$ hg clone http://bitbucket.org/gminick/sphinx-gsoc2009/
| commit 1605: | 83a3b527cc25 |
| parent 1604: | 86c93db9ac31 |
| branch: | default |
SinglefileHTMLBuilder as a separate module
Changed (Δ5.5 KB):
raw changeset »
sphinx/web/middleware/appserver.py (1 lines added, 79 lines removed)
sphinx/web/singlebuilder.py (73 lines added, 0 lines removed)
Up to file-list sphinx/web/middleware/appserver.py:
| … | … | @@ -29,20 +29,11 @@ from hashlib import md5 |
29 |
29 |
from jinja2 import Environment, FileSystemLoader, Template |
30 |
30 |
from webob import Request, Response |
31 |
31 |
|
32 |
from sphinx.application import TemplateBridge, Sphinx |
|
33 |
from sphinx.builders.html import StandaloneHTMLBuilder |
|
34 |
from sphinx.builders.webapp.webapp import WebappHTMLTranslator |
|
35 |
from sphinx.environment import BuildEnvironment |
|
36 |
32 |
from sphinx.errors import SphinxError |
37 |
from sphinx.highlighting import PygmentsBridge |
|
38 |
from sphinx.jinja2glue import BuiltinTemplateLoader |
|
39 |
from sphinx.theming import Theme |
|
40 |
from sphinx.util import relative_uri |
|
41 |
33 |
from sphinx.web.reposums import RepoSums |
42 |
34 |
from sphinx.web.webauth import WebAuth |
43 |
35 |
from sphinx.web.webconfig import WebConfig |
44 |
from sphinx.writers.html import HTMLTranslator |
|
45 |
||
36 |
from sphinx.web.singlebuilder import SinglefileHTMLBuilder |
|
46 |
37 |
|
47 |
38 |
tmp_template = """ |
48 |
39 |
{%% extends "basic/layout.html" %%} |
| … | … | @@ -173,75 +164,6 @@ def get_sorted_by_thread(data): |
173 |
164 |
return comments_sorted |
174 |
165 |
|
175 |
166 |
|
176 |
# this class should be moved somewhere |
|
177 |
class SinglefileHTMLBuilder(StandaloneHTMLBuilder, Sphinx): |
|
178 |
"""Render a file when requested using data from a pickled archive. |
|
179 |
Handle theming.""" |
|
180 |
def __init__(self, www_dir, repodir): |
|
181 |
self.outdir = www_dir |
|
182 |
self.srcdir = repodir |
|
183 |
self.cwd = os.getcwd() |
|
184 |
self.confdir = self.cwd |
|
185 |
self.doctreedir = path.join(self.cwd, '../doctrees') |
|
186 |
self.env = None |
|
187 |
self.freshenv = None |
|
188 |
confdir = path.join(self.cwd, '../../') # <cwd>/_build/webapp/../../ |
|
189 |
||
190 |
self.app = Sphinx(self.srcdir, confdir, self.outdir, self.doctreedir, |
|
191 |
'html', {}, None) |
|
192 |
self.info = self.app.info |
|
193 |
self.warn = self.app.warn |
|
194 |
self.config = self.app.config |
|
195 |
self.config.html_theme_path = 'themes/' + self.config.html_theme |
|
196 |
||
197 |
self.env = BuildEnvironment(self.srcdir, self.doctreedir, self.config) |
|
198 |
self.env.find_files(self.config) |
|
199 |
self.env.set_warnfunc(self.warn) |
|
200 |
||
201 |
self.load_i18n() |
|
202 |
self.load_env() |
|
203 |
||
204 |
StandaloneHTMLBuilder.init(self) |
|
205 |
||
206 |
self.app.add_javascript('jquery.form.js') |
|
207 |
self.app.add_javascript('comments.js') |
|
208 |
self.prepare_writing((None,)) |
|
209 |
self.style = self.theme.get_confstr('theme', 'stylesheet') |
|
210 |
||
211 |
self.config.html_additional_pages = {} |
|
212 |
self.images = {} |
|
213 |
||
214 |
def init_translator_class(self): |
|
215 |
self.translator_class = WebappHTMLTranslator |
|
216 |
||
217 |
def render_page(self, docname): |
|
218 |
# rst file has changed and thus we need to build new doctree file |
|
219 |
# and then build new html file |
|
220 |
self.env.read_doc(docname) |
|
221 |
doctree = self.env.get_and_resolve_doctree(docname, self) |
|
222 |
StandaloneHTMLBuilder.write_doc(self, docname, doctree) |
|
223 |
||
224 |
||
225 |
# unused |
|
226 |
def __render_file(self, filename, ctx): |
|
227 |
ctx.update(self.globalcontext.copy()) |
|
228 |
# current_page_name is backwards compatibility |
|
229 |
ctx['pagename'] = ctx['current_page_name'] = filename |
|
230 |
def pathto(otheruri, resource=False, |
|
231 |
baseuri=self.get_target_uri(filename)): |
|
232 |
if not resource: |
|
233 |
otheruri = self.get_target_uri(otheruri) |
|
234 |
return relative_uri(baseuri, otheruri) |
|
235 |
ctx['pathto'] = pathto |
|
236 |
ctx['hasdoc'] = lambda name: name in self.env.all_docs |
|
237 |
pgname = path.basename(filename).split('.')[0] |
|
238 |
ctx['customsidebar'] = self.config.html_sidebars.get(pgname) |
|
239 |
ctx['encoding'] = encoding = self.config.html_output_encoding |
|
240 |
ctx['toctree'] = lambda **kw: self._get_local_toctree(filename, **kw) |
|
241 |
ctx['style'] = self.style |
|
242 |
||
243 |
return self.templates.render_string(tmp_template % (ctx), ctx) |
|
244 |
||
245 |
167 |
class AppServer(object): |
246 |
168 |
"""This middleware is responsible for serving the docs (the docs are |
247 |
169 |
pickled files, so it has to load a file from a pickle) and for handling |
Up to file-list sphinx/web/singlebuilder.py:
1 |
#!/usr/bin/env python |
|
2 |
# -*- coding: utf-8 -*- |
|
3 |
""" |
|
4 |
sphinx.web.singlebuilder |
|
5 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
|
6 |
||
7 |
A HTML builder for a single file. |
|
8 |
||
9 |
:copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS. |
|
10 |
:license: BSD, see LICENSE for details. |
|
11 |
""" |
|
12 |
||
13 |
import os |
|
14 |
from os import path |
|
15 |
||
16 |
from sphinx.application import Sphinx |
|
17 |
from sphinx.builders.html import StandaloneHTMLBuilder |
|
18 |
from sphinx.builders.webapp.webapp import WebappHTMLTranslator |
|
19 |
from sphinx.environment import BuildEnvironment |
|
20 |
from sphinx.errors import SphinxError |
|
21 |
||
22 |
# this class should be moved somewhere |
|
23 |
class SinglefileHTMLBuilder(StandaloneHTMLBuilder, Sphinx): |
|
24 |
"""Render a file when requested using data from a pickled archive. |
|
25 |
Handle theming.""" |
|
26 |
def __init__(self, www_dir, repodir): |
|
27 |
self.outdir = www_dir |
|
28 |
self.srcdir = repodir |
|
29 |
self.cwd = os.getcwd() |
|
30 |
self.confdir = self.cwd |
|
31 |
self.doctreedir = path.join(self.cwd, '../doctrees') |
|
32 |
self.docsettings = None |
|
33 |
self.env = None |
|
34 |
self.freshenv = None |
|
35 |
confdir = path.join(self.cwd, '../../') # <cwd>/_build/webapp/../../ |
|
36 |
||
37 |
self.app = Sphinx(self.srcdir, confdir, self.outdir, self.doctreedir, |
|
38 |
'html', {}, None) |
|
39 |
self.info = self.app.info |
|
40 |
self.warn = self.app.warn |
|
41 |
self.config = self.app.config |
|
42 |
self.config.html_theme_path = 'themes/' + self.config.html_theme |
|
43 |
||
44 |
self.env = BuildEnvironment(self.srcdir, self.doctreedir, self.config) |
|
45 |
self.env.find_files(self.config) |
|
46 |
self.env.set_warnfunc(self.warn) |
|
47 |
||
48 |
# XXX got to figure out what's this |
|
49 |
self.env.domaindata = {} |
|
50 |
self.env.domaindata['py'] = {} |
|
51 |
self.env.domaindata['py']['modules'] = [] |
|
52 |
#self.load_i18n() |
|
53 |
#self.load_env() |
|
54 |
||
55 |
StandaloneHTMLBuilder.init(self) |
|
56 |
||
57 |
self.app.add_javascript('jquery.form.js') |
|
58 |
self.app.add_javascript('comments.js') |
|
59 |
self.prepare_writing((None,)) |
|
60 |
self.style = self.theme.get_confstr('theme', 'stylesheet') |
|
61 |
||
62 |
self.config.html_additional_pages = {} |
|
63 |
self.images = {} |
|
64 |
||
65 |
def init_translator_class(self): |
|
66 |
self.translator_class = WebappHTMLTranslator |
|
67 |
||
68 |
def render_page(self, docname): |
|
69 |
# rst file has changed and thus we need to build new doctree file |
|
70 |
# and then build new html file |
|
71 |
self.env.read_doc(docname) |
|
72 |
doctree = self.env.get_and_resolve_doctree(docname, self) |
|
73 |
StandaloneHTMLBuilder.write_doc(self, docname, doctree) |
