示例#1
0
    def make_ncx(self):
        context = simpleTALES.Context(allowPythonPath=1)
        context.addGlobal('data', self.data)
        compiled = simpleTAL.compileXMLTemplate(templates.ncx)

        fd = open(os.path.join(self.root_dir, 'toc.ncx'), 'wb')
        compiled.expand(context, fd, outputEncoding=self.encoding, docType=NCX_DOCTYPE)
        fd.close()
示例#2
0
    def make_titlepage(self):
        context = simpleTALES.Context()
        context.addGlobal('data', self.data)
        compiled = simpleTAL.compileXMLTemplate(templates.titlepage)

        fd0 = open(os.path.join(self.root_dir, 'titlepage.html'), 'wb')
        compiled.expand(context, fd0, outputEncoding=self.encoding,suppressXMLDeclaration=True)
        fd0.close()
示例#3
0
    def make_opf(self):
        context = simpleTALES.Context()
        context.addGlobal('data', self.data)
        context.addGlobal('date', datetime.date.isoformat(datetime.date.today()))
        compiled = simpleTAL.compileXMLTemplate(templates.opf)

        fd = open(os.path.join(self.root_dir, 'content.opf'), 'wb')
        compiled.expand(context, fd, outputEncoding=self.encoding)
        fd.close()
示例#4
0
def xmltemplate(s, encoding='utf8'):
    template = simpleTAL.compileXMLTemplate(s)
    def renderxml(obj):
        context = TALContext(allowPythonPath=1)
        context.addGlobal('here', obj)
        context.addGlobal('self', obj)
        context.addGlobal('container', obj.parentNode)
        context.addGlobal('config', obj.ownerDocument.config)
        context.addGlobal('context', obj.ownerDocument.context)
        context.addGlobal('template', template)
        context.addGlobal('templates', obj.renderer)
        output = StringIO()
        template.expand(context, output, encoding, docType=None, suppressXMLDeclaration=1)
        return unicode(output.getvalue(), encoding)
    return renderxml
示例#5
0
def xmltemplate(s):
    template = simpleTAL.compileXMLTemplate(s)
    def renderxml(obj):
        context = TALContext(allowPythonPath=1)
        context.addGlobal('here', obj)
        context.addGlobal('self', obj)
        context.addGlobal('container', obj.parentNode)
        context.addGlobal('config', obj.ownerDocument.config)
        context.addGlobal('context', obj.ownerDocument.context)
        context.addGlobal('template', template)
        context.addGlobal('templates', obj.renderer)
        output = StringIO()
        template.expand(context, output, docType=None, suppressXMLDeclaration=1)
        return output.getvalue()
    return renderxml