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