def __init__(self, *args, **kw): self.GTW = GTW = JNJ.GTW(self) self.env = env = JNJ.Environment.HTML(*args, GTW=GTW, **kw) self.Template_Type = T = Template_E.New \ ( "x" , By_Path = {} , Map = {} , Media_Map = {} , css_href_map = {} , etag = None ) self.Template_Map = T.Map for t in sorted(pyk.itervalues(Template.Map), key=TFL.Getter.id): T.copy(env, t)
def HTML \ ( version = "html/5.jnj" , load_path = () , loader = None , globals = {} , encoding = "utf-8" , i18n = False , Media_Parameters = None , GTW = None , prefixes = {} , ** kw ) : jnj_loader = FileSystemLoader (sos.path.dirname (__file__), "utf-8") loaders = [] if loader : loaders.append (loader) if load_path : loaders.append (FileSystemLoader (load_path, encoding)) loaders.append (jnj_loader) if prefixes : sk = lambda x : (- len (x [1]), x [1]) for prefix, lp in sorted (pyk.iteritems (prefixes), key = sk) : loaders.append \ ( PrefixLoader ({prefix : FileSystemLoader (lp, encoding)}, delimiter='::') ) loaders.append (PrefixLoader (dict (STD = jnj_loader), delimiter='::')) loader = ChoiceLoader (loaders) extensions = (kw.pop ("extensions", []) + Default_Extensions) if i18n : extensions.append ("jinja2.ext.i18n") result = Environment \ ( extensions = uniq (extensions), loader = loader, ** kw) if GTW is None : GTW = JNJ.GTW (result) result.globals.update \ ( globals , GTW = GTW , html_version = version ) result.Media_Parameters = Media_Parameters result.encoding = encoding result.static_handler = None if i18n : result.install_gettext_translations (TFL.I18N) return result
""" from __future__ import division, print_function from __future__ import absolute_import, unicode_literals from _JNJ import JNJ from _JNJ.Templateer import Template Template \ ( "ETR_table_regatta", "html/ETR/regatta.m.jnj" , parent_name = "ETR_table" ) Template \ ( "ETR_table_regatta_register", "html/ETR/regatta_register.m.jnj" , parent_name = "ETR_table_regatta" ) Template \ ( "ETR_table_regatta_result", "html/ETR/regatta_result.m.jnj" , parent_name = "ETR_table_regatta" ) Template("regatta_calendar", "html/regatta_calendar.jnj") Template("regatta_page", "html/regatta_page.jnj") Template("regatta_page_r", "html/regatta_page_r.jnj") Template("regatta_ranking", "html/regatta_ranking.jnj") Template("regatta_register_email", "email/regatta_register.jnj") if __name__ != "__main__": JNJ._Export_Module() ### __END__ JNJ.SRM
t_else = parser.parse_statements (["name:endonion"]) else : t_else = None result.append (self._if_node (cond, t_then, t_else)) next (parser.stream) return result # end def parse _nodes_if_field_no = len (nodes.If.fields) if _nodes_if_field_no == 3 : def _if_node (self, cond, then_block, else_block) : return nodes.If (cond, then_block, else_block) # end def _if_node elif _nodes_if_field_no == 4 : def _if_node (self, cond, then_block, else_block) : return nodes.If (cond, then_block, [], else_block) # end def _if_node else : raise NotImplementedError \ ( "Cannot deal with jinja2.nodes.If with number of fields " "other than 3 or 4" ) del _nodes_if_field_no # end class Onion if __name__ != "__main__" : JNJ._Export ("Onion") ### __END__ JNJ.Onion
<BLANKLINE> <option value="0">red</option> <option value="1" selected="selected">green</option> <BLANKLINE> <option value="">---</option> </select> </html> >>> et = env5.get_template ("email/email.jnj") >>> print (et.render (email_from = "*****@*****.**", email_to = "*****@*****.**", email_body = "Nih!", NAV = None)) From: [email protected] To: [email protected] Content-type: text/plain; charset=iso-8859-15 <BLANKLINE> <BLANKLINE> Nih! >>> print (et.render (email_from = "*****@*****.**", email_to = "*****@*****.**", email_body = "Nih!", NAV = None)) From: [email protected] To: [email protected] Content-type: text/plain; charset=iso-8859-15 <BLANKLINE> <BLANKLINE> Nih! """ if __name__ != "__main__" : JNJ._Export_Module () ### __END__ JNJ.Environment
# end def uuid vimeo_video = staticmethod (TFL.HTML.vimeo_video) youtube_video = staticmethod (TFL.HTML.youtube_video) def xmlattr (self, * ds, ** kw) : """Convert (sorted) items of dict `d` to SGML/XML attribute string. This is similar to jinja's `xmlattr` filter but ensures deterministic output by sorting by attribute name. """ from jinja2.utils import escape d = self.filtered_dict (* ds, ** kw) result = " ".join \ ( '%s="%s"' % (escape (k), escape (v)) for k, v in sorted (pyk.iteritems (d), key = TFL.Getter [0]) ) return (" " + result) if result else "" # end def xmlattr zip = staticmethod (zip) _T = staticmethod (_T) _ = staticmethod (_) _Tn = staticmethod (_Tn) # end class GTW if __name__ != "__main__" : JNJ._Export ("GTW") ### __END__ JNJ.GTW
if name_i in T.Map: result = T.Map[name_i] else: path = result.path ### avoid lookup `T.By_Path [result.path]` args = result.args[2:] result = T(self.env, name_i, None, *args, injected=injected) result.path = path return result # end def get_template def render(self, template_or_name, context): template = template_or_name if isinstance(template_or_name, pyk.string_types): template = self.get_template(template_or_name) return template.render(context) # end def render def render_string(self, template_string, context): return self.env.from_string(template_string).render(context) # end def render_string # end class Templateer if __name__ != "__main__": JNJ._Export("*") ### __END__ JNJ.Templateer
name_i = "%s|%s" % \ ( result.name , "|".join (pyk.decoded (t.name) for t in sorted (injected)) ) if name_i in T.Map : result = T.Map [name_i] else : path = result.path ### avoid lookup `T.By_Path [result.path]` args = result.args [2:] result = T (self.env, name_i, None, * args, injected = injected) result.path = path return result # end def get_template def render (self, template_or_name, context) : template = template_or_name if isinstance (template_or_name, pyk.string_types) : template = self.get_template (template_or_name) return template.render (context) # end def render def render_string (self, template_string, context) : return self.env.from_string (template_string).render (context) # end def render_string # end class Templateer if __name__ != "__main__" : JNJ._Export ("*") ### __END__ JNJ.Templateer
# end def parse _nodes_if_field_no = len(nodes.If.fields) if _nodes_if_field_no == 3: def _if_node(self, cond, then_block, else_block): return nodes.If(cond, then_block, else_block) # end def _if_node elif _nodes_if_field_no == 4: def _if_node(self, cond, then_block, else_block): return nodes.If(cond, then_block, [], else_block) # end def _if_node else: raise NotImplementedError \ ( "Cannot deal with jinja2.nodes.If with number of fields " "other than 3 or 4" ) del _nodes_if_field_no # end class Onion if __name__ != "__main__": JNJ._Export("Onion") ### __END__ JNJ.Onion