def render(self, jinja_env=None): """Render the document using the render pool.""" timer = self.pod.profile.timer('RenderDocumentController.render', label='{} ({})'.format( self.doc.pod_path, self.doc.locale), meta={ 'path': self.doc.pod_path, 'locale': str(self.doc.locale) }).start_timer() # Validate the path with the config filters. self.validate_path() doc = self.doc template = jinja_env['env'].get_template(doc.view.lstrip('/')) track_dependency = doc_dependency.DocDependency(doc) local_tags = tags.create_builtin_tags( self.pod, doc, track_dependency=track_dependency) # NOTE: This should be done using get_template(... globals=...) # or passed as an argument into render but # it is not available included inside macros??? # See: https://github.com/pallets/jinja/issues/688 template.globals['g'] = local_tags # Track the message stats, including untranslated strings. if self.pod.is_enabled(self.pod.FEATURE_TRANSLATION_STATS): template.globals['_'] = tags.make_doc_gettext(doc) try: serving_path = doc.get_serving_path() if serving_path.endswith('/'): serving_path = '{}{}'.format(serving_path, self.suffix) rendered_content = template.render({ 'doc': doc, 'env': self.pod.env, 'podspec': self.pod.podspec, '_track_dependency': track_dependency, }).lstrip() rendered_content = self.pod.extensions_controller.trigger( 'post_render', doc, rendered_content) rendered_doc = rendered_document.RenderedDocument( serving_path, rendered_content) timer.stop_timer() return rendered_doc except Exception as err: text = 'Error building {}: {}' if self.pod: self.pod.logger.exception(text.format(self, err)) exception = errors.BuildError(text.format(self, err)) exception.traceback = sys.exc_info()[2] exception.controller = self exception.exception = err raise exception
def render(self, jinja_env=None): """Render the document using the render pool.""" timer = self.pod.profile.timer( 'RenderDocumentController.render', label='{} ({})'.format(self.doc.pod_path, self.doc.locale), meta={ 'path': self.doc.pod_path, 'locale': str(self.doc.locale)} ).start_timer() # Validate the path with the config filters. self.validate_path() doc = self.doc template = jinja_env['env'].get_template(doc.view.lstrip('/')) track_dependency = doc_dependency.DocDependency(doc) local_tags = tags.create_builtin_tags( self.pod, doc, track_dependency=track_dependency) # NOTE: This should be done using get_template(... globals=...) # or passed as an argument into render but # it is not available included inside macros??? # See: https://github.com/pallets/jinja/issues/688 template.globals['g'] = local_tags # Track the message stats, including untranslated strings. if self.pod.is_enabled(self.pod.FEATURE_TRANSLATION_STATS): template.globals['_'] = tags.make_doc_gettext(doc) try: doc.footnotes.reset() serving_path = doc.get_serving_path() if serving_path.endswith('/'): serving_path = '{}{}'.format(serving_path, self.suffix) content = self.pod.extensions_controller.trigger('pre_render', doc, doc.body) if content: doc.format.update(content=content.encode('utf-8')) rendered_content = template.render({ 'doc': doc, 'env': self.pod.env, 'podspec': self.pod.podspec, '_track_dependency': track_dependency, }).lstrip() rendered_content = self.pod.extensions_controller.trigger( 'post_render', doc, rendered_content) rendered_doc = rendered_document.RenderedDocument( serving_path, rendered_content) timer.stop_timer() return rendered_doc except Exception as err: exception = errors.BuildError(str(err)) exception.traceback = sys.exc_info()[2] exception.controller = self exception.exception = err raise exception
def render(self, params, inject=True): doc = self.doc preprocessor = None translator = None if inject: preprocessor = self.pod.inject_preprocessors(doc=doc) translator = self.pod.inject_translators(doc=doc) jinja_env = self.pod.get_jinja_env(self.locale) template = jinja_env.get_template(self.view.lstrip('/')) track_dependency = doc_dependency.DocDependency(doc) local_tags = tags.create_builtin_tags( self.pod, doc, track_dependency=track_dependency) # NOTE: This should be done using get_template(... globals=...) # or passed as an argument into render but # it is not available included inside macros??? # See: https://github.com/pallets/jinja/issues/688 template.globals['g'] = local_tags # Track the message stats, including untranslated strings. if self.pod.is_enabled(self.pod.FEATURE_TRANSLATION_STATS): template.globals['_'] = tags.make_doc_gettext(doc) try: kwargs = { 'doc': doc, 'env': self.pod.env, 'podspec': self.pod.podspec, '_track_dependency': track_dependency, } content = template.render(kwargs).lstrip() if self.pod.is_enabled(self.pod.FEATURE_UI): content = self._inject_ui( content, preprocessor, translator) return content except Exception as e: text = 'Error building {}: {}' exception = errors.BuildError(text.format(self, e)) exception.traceback = sys.exc_info()[2] exception.controller = self exception.exception = e if self._pod: self._pod.logger.exception(text.format(self, e)) raise exception