dojango
dojango copied to clipboard
30 - Implemented dojo_type tag
Hi! I had a need for the tag mentioned in the TODO comment in templatetags/dojango_base.py, so I implemented it. I have never written a template tag before, so I just followed the example in the django docs. I was not sure whether to put the add_module call in the tag function or in the render method. However I think the tag should be named the same as the python function (add_module). Than it would be more clear what it does. Anyway, here is the code: from dojango.util.dojo_collector import add_module ... class AddModuleNode(template.Node): def **init**(self, module): self.module = module def render(self, context): add_module(self.module) return '' @register.tag def dojo_type(parser, token): '''This template tag informs the collector about new modules {% dojo_type "dijit.layout.TabContainer" %}''' try: (tag_name, module) = token.split_contents() except ValueError: raise template.TemplateSyntaxError, "%r tag requires a single string as" % token.contents.split()[0] if not (module[0] == module[-1] and module[0] in ('"', "'")): raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name return AddModuleNode(module[1:-1])Original link: http://code.google.com/p/dojango/issues/detail?id=30