Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

30 - Implemented dojo_type tag #30

Open
klipstein opened this issue Nov 6, 2011 · 0 comments
Open

30 - Implemented dojo_type tag #30

klipstein opened this issue Nov 6, 2011 · 0 comments

Comments

@klipstein
Copy link
Owner

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant