def render(self, template_name, passed_vars, response_code = 200, response_type=False, prettyPrint=False, template_set='app', template_theme=None): """Main render helper function. Wraps other rendering functions """ if not response_type: response_type = self.request.response_type() prettyPrint = bool(self.request.get('prettyPrint', False)) if hasmethod(self, 'template_wrapper'): passed_vars = self.template_wrapper(variables = passed_vars) if response_type in ['xml', 'json']: serial_f = getattr(sketch.serialize, response_type) content = serial_f(passed_vars, pretty = prettyPrint) self.response.headers['Content-Type'] = "application/%s; charset=utf-8" % (response_type) else: sketch.jinja.setup(self.config.paths.templates) passed_vars = self.get_template_vars(passed_vars) passed_vars = self.get_plugin_vars(passed_vars) # fixing.. if hasattr(self, 'template_folder'): template_theme = getmethattr(self, 'template_folder') content = sketch.jinja.render(template_name, passed_vars, template_theme=template_theme, template_set=template_set) self.render_content(content, response_code)
def get_template_theme(self, template_set=None): if template_set in self.config.template_themes: return self.config.template_themes[template_set] if hasattr(self, 'template_theme'): return getmethattr(self, 'template_theme') if (self.config.default_template_theme): return self.config.default_template_theme raise Exception('no template theme specified')
def get_styles(self, template_vars): if not hasattr(self, 'styles'): return template_vars styles_dict = getmethattr(self, 'styles') styles_tmp = "" for style_path in styles_dict: style_name = "" styles_tmp = styles_tmp + "<link id=\"%s\" rel=\"stylesheet\" href=\"%s\" type=\"text/css\">" % (style_name, style_path) template_vars['styles'] = styles_tmp return template_vars
def get_javascripts(self, template_vars): """Will read the javascripts to be included, create the tags and include them as part of the template variables :param template_vars: Template variable dict """ if not hasattr(self, 'javascripts'): return template_vars scripts_dict = getmethattr(self, 'javascripts') js_tmp = "" for script_d in scripts_dict: for script_src in scripts_dict[script_d]['src']: js_tmp = js_tmp + "<script type=\"text/javascript\" src=\"%s\"></script>\n" % script_src template_vars['javascripts'] = js_tmp return template_vars
def get_javascripts(self, template_vars): """Will read the javascripts to be included, create the tags and include them as part of the template variables :param template_vars: Template variable dict """ if not hasattr(self, 'javascripts'): return template_vars scripts_dict = getmethattr(self, 'javascripts') js_tmp = "" for script_name, script_val in scripts_dict.iteritems(): script_src = "" if 'base_dir' in script_val: script_src = script_val['base_dir'] for script_uri in script_val['src']: if 'version' in script_val: script_uri = script_uri + "?%s" % script_val['version'] js_tmp = js_tmp + "\t<script type=\"text/javascript\" src=\"%s\"></script>\n" % (script_src + script_uri) template_vars['javascripts'] = js_tmp return template_vars
def get_template_set(self): if hasattr(self, 'template_set'): return getmethattr(self, 'template_set') if (self.config.default_template_set): return self.config.default_template_set raise Exception('no template set specified')