| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
""" |
|---|
| 5 |
Default processing factory plugin. |
|---|
| 6 |
""" |
|---|
| 7 |
|
|---|
| 8 |
from xml.dom import minidom as dom |
|---|
| 9 |
|
|---|
| 10 |
from twisted.lore import tree, latex, lint, process |
|---|
| 11 |
from twisted.web import sux |
|---|
| 12 |
|
|---|
| 13 |
htmlDefault = {'template': 'template.tpl', 'baseurl': '%s', 'ext': '.html'} |
|---|
| 14 |
|
|---|
| 15 |
class ProcessingFunctionFactory: |
|---|
| 16 |
|
|---|
| 17 |
def getDoFile(self): |
|---|
| 18 |
return tree.doFile |
|---|
| 19 |
|
|---|
| 20 |
def generate_html(self, options, filenameGenerator=tree.getOutputFileName): |
|---|
| 21 |
n = htmlDefault.copy() |
|---|
| 22 |
n.update(options) |
|---|
| 23 |
options = n |
|---|
| 24 |
try: |
|---|
| 25 |
fp = open(options['template']) |
|---|
| 26 |
templ = dom.parse(fp) |
|---|
| 27 |
except IOError, e: |
|---|
| 28 |
raise process.NoProcessorError(e.filename+": "+e.strerror) |
|---|
| 29 |
except sux.ParseError, e: |
|---|
| 30 |
raise process.NoProcessorError(str(e)) |
|---|
| 31 |
df = lambda file, linkrel: self.getDoFile()(file, linkrel, options['ext'], |
|---|
| 32 |
options['baseurl'], templ, options, filenameGenerator) |
|---|
| 33 |
return df |
|---|
| 34 |
|
|---|
| 35 |
latexSpitters = {None: latex.LatexSpitter, |
|---|
| 36 |
'section': latex.SectionLatexSpitter, |
|---|
| 37 |
'chapter': latex.ChapterLatexSpitter, |
|---|
| 38 |
'book': latex.BookLatexSpitter, |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
def generate_latex(self, options, filenameGenerator=None): |
|---|
| 42 |
spitter = self.latexSpitters[None] |
|---|
| 43 |
for (key, value) in self.latexSpitters.items(): |
|---|
| 44 |
if key and options.get(key): |
|---|
| 45 |
spitter = value |
|---|
| 46 |
df = lambda file, linkrel: latex.convertFile(file, spitter) |
|---|
| 47 |
return df |
|---|
| 48 |
|
|---|
| 49 |
def getLintChecker(self): |
|---|
| 50 |
return lint.getDefaultChecker() |
|---|
| 51 |
|
|---|
| 52 |
def generate_lint(self, options, filenameGenerator=None): |
|---|
| 53 |
checker = self.getLintChecker() |
|---|
| 54 |
return lambda file, linkrel: lint.doFile(file, checker) |
|---|
| 55 |
|
|---|
| 56 |
factory = ProcessingFunctionFactory() |
|---|