1
"""Badly named module that contains the driving code for the rendering."""
3
from pydoctor.templatewriter.util import link, templatefile
4
from pydoctor.templatewriter import DOCTYPE, pages, summary
5
from pydoctor import model
7
from twisted.web.template import flattenString
12
def flattenToFile(fobj, page):
17
flattenString(None, page).addCallback(fobj.write).addErrback(e)
23
def __init__(self, filebase):
25
self.written_pages = 0
29
def prepOutputDirectory(self):
30
if not os.path.exists(self.base):
32
shutil.copyfile(templatefile('apidocs.css'),
33
os.path.join(self.base, 'apidocs.css'))
34
if self.system.options.htmlusesorttable:
35
shutil.copyfile(templatefile('sorttable.js'),
36
os.path.join(self.base, 'sorttable.js'))
37
if self.system.options.htmlusesplitlinks or self.system.options.htmlshortenlists:
38
shutil.copyfile(templatefile('pydoctor.js'),
39
os.path.join(self.base, 'pydoctor.js'))
41
def writeIndividualFiles(self, obs, functionpages=False):
44
self.writeDocsFor(ob, functionpages=functionpages)
47
self.writeDocsFor(ob, functionpages=functionpages)
49
def writeModuleIndex(self, system):
51
for i, pclass in enumerate(summary.summarypages):
52
system.msg('html', 'starting ' + pclass.__name__ + ' ...', nonl=True)
55
f = open(os.path.join(self.base, pclass.filename), 'w')
56
flattenToFile(f, page)
58
system.msg('html', "took %fs"%(time.time() - T), wantsnl=False)
60
def writeDocsFor(self, ob, functionpages):
63
isfunc = ob.documentation_location == model.DocLocation.PARENT_PAGE
64
if (isfunc and functionpages) or not isfunc:
68
f = open(os.path.join(self.base, link(ob)), 'w')
69
self.writeDocsForOne(ob, f)
71
for o in ob.orderedcontents:
72
self.writeDocsFor(o, functionpages)
74
def writeDocsForOne(self, ob, fobj):
79
for c in ob.__class__.__mro__:
80
n = c.__name__ + 'Page'
85
pclass = pages.CommonPage
86
self.system.msg('html', str(ob), thresh=1)
88
self.written_pages += 1
89
self.system.progress('html', self.written_pages, self.total_pages, 'pages written')
90
flattenToFile(fobj, page)