Exemple #1
0
                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
Exemple #2
0
    # 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
Exemple #3
0
            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
Exemple #4
0
            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
Exemple #5
0
    # 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
Exemple #6
0
    # 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