def render_page(self, page): '''Render a single page from the notebook @param page: a L{Page} object @returns: html as a list of lines ''' lines = [] context = ExportTemplateContext( self.notebook, self.linker_factory, self.dumper_factory, title=page.get_title(), content=[page], home=self.notebook.get_home_page(), up=page.parent if page.parent and not page.parent.isroot else None, prevpage=self.notebook.pages.get_previous(page) if not page.isroot else None, nextpage=self.notebook.pages.get_next(page) if not page.isroot else None, links={'index': '/'}, index_generator=self.notebook.pages.walk, index_page=page, ) self.template.process(lines, context) return lines
def export_page(self, notebook, page, pages, prevpage=None, nextpage=None): # XXX FIXME remove need for notebook here file=self.layout.page_file(page) linker_factory = partial(ExportLinker, notebook=notebook, layout=self.layout, output=file, usebase=self.format.info['usebase'], document_root_url=self.document_root_url ) dumper_factory = self.format.Dumper # XXX context = ExportTemplateContext( notebook, linker_factory, dumper_factory, title=page.get_title(), content=[page], home=None, up=None, # TODO prevpage=prevpage, nextpage=nextpage, links={'index': self.index_page}, index_generator=pages.index, index_page=page, ) lines = [] self.template.process(lines, context) file.writelines(lines)
def export_iter(self, pages): self.export_resources() linker_factory = partial(ExportLinker, notebook=pages.notebook, layout=self.layout, output=self.layout.file, usebase=self.format.info['usebase'], document_root_url=self.document_root_url ) dumper_factory = self.format.Dumper # XXX context = ExportTemplateContext( pages.notebook, linker_factory, dumper_factory, title=pages.title, # XXX content=pages, special=None, # TODO home=None, # TODO links=None, index_generator=pages.index, index_page=None, ) lines = [] self.template.process(lines, context) self.layout.file.writelines(lines) # TODO incremental write to save memory on large notebooks... # TODO also yield while exporting main page for page in pages: self.export_attachments(pages.notebook, page) yield page
def print_to_file(self, notebook, page): file = TmpFile('print-to-browser.html', persistent=True, unique=False) template = zim.templates.get_template('html', 'Print') linker_factory = partial(StaticExportLinker, notebook, template.resources_dir) dumper_factory = zim.formats.get_format('html').Dumper # XXX context = ExportTemplateContext(notebook, linker_factory, dumper_factory, page.basename, [page]) lines = [] template.process(lines, context) file.writelines(lines) return file