﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
276	[patch] new template tag 'strip' 	mr_little	Adrian Holovaty	"Useful extension to templatetags (idea copied from smarty)
Used when you build colored diagramms by images

If you add it to a default set it will be nice ;)

{{{
strip_re = re.compile("">\s*"")
class StripNode(template.Node):
    def __init__(self, nodelist):
        self.nodelist = nodelist
    def __iter__(self):
        for node in self.nodelist:
            yield node
    def get_nodes_by_type(self, nodetype):
        nodes = []
        if isinstance(self, nodetype):
            nodes.append(self)
        nodes.extend(self.nodelist.get_nodes_by_type(nodetype))
        return nodes
    def render(self, context):
        content = self.nodelist.render(context)
        content = strip_re.sub('>', content)
        return content

def do_strip(parser, token):
    """"""
    Strips spaces and newlines after html tags '>\s*' --> '>'
    {% strip %}
        <img />
        text
        <img />
    {% endstrip %}
    Will be:
        <img />text <img />
    """"""
    bits = token.contents.split()
    if len(bits) > 2:
        raise template.TemplateSyntaxError, ""'%s' tag don't takes arguments"" % bits[0]
    nodelist = parser.parse(('endstrip',))
    parser.delete_first_token()
    
    return StripNode(nodelist)

template.register_tag('strip', do_strip)
}}}
"		closed	Template system		normal	fixed	template tag strip		Ready for checkin	1	0	0	0	0	0
