# Path: native_tags/nodes.py
# def do_function(parser, token):
#     """
#     Performs a defined function on the passed arguments.
#     Normally this returns the output of the function into the template.
#     If the second to last argument is ``as``, the result of the function is stored in the context and is named whatever the last argument is.
# 
#     Syntax::
# 
#         {% [function] [var args...] [name=value kwargs...] [as varname] %}
# 
#     Examples::
# 
#         {% search '^(\d{3})$' 800 as match %}
# 
#         {% map sha1 hello world %}
# 
#     """
#     name, args, kwargs = get_signature(token, True, True)
#     return FunctionNode(parser, name, *args, **kwargs)
# 
# def do_comparison(parser, token):
#     """
#     Compares passed arguments. 
#     Attached functions should return boolean ``True`` or ``False``.
#     If the attached function returns ``True``, the first node list is rendered.
#     If the attached function returns ``False``, the second optional node list is rendered (part after the ``{% else %}`` statement). 
#     If the last argument in the tag is ``negate``, then the opposite node list is rendered (like an ``ifnot`` tag).
#     
#     Syntax::
# 
#         {% if_[comparison] [var args...] [name=value kwargs...] [negate] %}
#             {# first node list in here #}
#         {% else %}
#             {# second optional node list in here #}
#         {% endif_[comparison] %}
# 
# 
#     Supported comparisons are ``match``, ``find``, ``startswith``, ``endswith``,
#     ``less``, ``less_or_equal``, ``greater`` and ``greater_or_equal`` and many more.
#     Checkout the :ref:`contrib-index` for more examples
# 
#     Examples::
# 
#         {% if_less some_object.id 3 %}
#         {{ some_object }} has an id less than 3.
#         {% endif_less %}
# 
#         {% if_match request.path '^/$' %}
#         Welcome home
#         {% endif_match %}
# 
#     """
#     name, args, kwargs = get_signature(token, comparison=True)
#     name = name.replace('if_if', 'if')
#     end_tag = 'end' + name
#     kwargs['nodelist_true'] = parser.parse(('else', end_tag))
#     token = parser.next_token()
#     if token.contents == 'else':
#         kwargs['nodelist_false'] = parser.parse((end_tag,))
#         parser.delete_first_token()
#     else:
#         kwargs['nodelist_false'] = template.NodeList()
#     if name.startswith('if_'):
#         name = name.split('if_')[1]
#     return ComparisonNode(parser, name, *args, **kwargs)
# 
# def do_block(parser, token):
#     """
#     Process several nodes inside a single block
#     Block functions take ``context``, ``nodelist`` as first arguments
#     If the second to last argument is ``as``, the rendered result is stored in the context and is named whatever the last argument is.
# 
#     Syntax::
# 
#         {% [block] [var args...] [name=value kwargs...] [as varname] %}
#             ... nodelist ...
#         {% end[block] %}
# 
#     Examples::
# 
#         {% render_block as rendered_output %}
#             {{ request.path }}/blog/{{ blog.slug }}
#         {% endrender_block %}
# 
#         {% highlight_block python %}
#             import this
#         {% endhighlight_block %}
# 
#     """
#     name, args, kwargs = get_signature(token, contextable=True)
#     kwargs['nodelist'] = parser.parse(('end%s' % name,))
#     parser.delete_first_token()
#     return BlockNode(parser, name, *args, **kwargs)
# 
# Path: native_tags/registry.py
# def register(self, bucket, name_or_func, func=None):
#     """
#     Add a function to the registry by name
#     """
#     assert bucket in self, 'Bucket %s is unknown' % bucket
#     if func is None and hasattr(name_or_func, '__name__'):
#         name = name_or_func.__name__
#         func = name_or_func
#     elif func:
#         name = name_or_func
#     if name in self[bucket]:
#         raise AlreadyRegistered('The function %s is already registered' % name)
# 
#     self[bucket][name] = func


from django.template import Library
from native_tags.nodes import do_function, do_comparison, do_block
from native_tags.registry import register as native_register



register = Library()

for tag_name in native_register['comparison']:
    if not tag_name.startswith('if'):
        tag_name = 'if_%s' % tag_name 
    register.tags[tag_name] = do_comparison
    
for tag_name in native_register['function']:
    register.tags[tag_name] = do_function

for tag_name in native_register['block']:
    register.tags[tag_name] = do_block


# Path: native_tags/nodes.py
# def do_function(parser, token):
#     """
#     Performs a defined function on the passed arguments.
#     Normally this returns the output of the function into the template.
#     If the second to last argument is ``as``, the result of the function is stored in the context and is named whatever the last argument is.
# 
#     Syntax::
# 
#         {% [function] [var args...] [name=value kwargs...] [as varname] %}
# 
#     Examples::
# 
#         {% search '^(\d{3})$' 800 as match %}
# 
#         {% map sha1 hello world %}
# 
#     """
#     name, args, kwargs = get_signature(token, True, True)
#     return FunctionNode(parser, name, *args, **kwargs)
# 
# def do_comparison(parser, token):
#     """
#     Compares passed arguments. 
#     Attached functions should return boolean ``True`` or ``False``.
#     If the attached function returns ``True``, the first node list is rendered.
#     If the attached function returns ``False``, the second optional node list is rendered (part after the ``{% else %}`` statement). 
#     If the last argument in the tag is ``negate``, then the opposite node list is rendered (like an ``ifnot`` tag).
#     
#     Syntax::
# 
#         {% if_[comparison] [var args...] [name=value kwargs...] [negate] %}
#             {# first node list in here #}
#         {% else %}
#             {# second optional node list in here #}
#         {% endif_[comparison] %}
# 
# 
#     Supported comparisons are ``match``, ``find``, ``startswith``, ``endswith``,
#     ``less``, ``less_or_equal``, ``greater`` and ``greater_or_equal`` and many more.
#     Checkout the :ref:`contrib-index` for more examples
# 
#     Examples::
# 
#         {% if_less some_object.id 3 %}
#         {{ some_object }} has an id less than 3.
#         {% endif_less %}
# 
#         {% if_match request.path '^/$' %}
#         Welcome home
#         {% endif_match %}
# 
#     """
#     name, args, kwargs = get_signature(token, comparison=True)
#     name = name.replace('if_if', 'if')
#     end_tag = 'end' + name
#     kwargs['nodelist_true'] = parser.parse(('else', end_tag))
#     token = parser.next_token()
#     if token.contents == 'else':
#         kwargs['nodelist_false'] = parser.parse((end_tag,))
#         parser.delete_first_token()
#     else:
#         kwargs['nodelist_false'] = template.NodeList()
#     if name.startswith('if_'):
#         name = name.split('if_')[1]
#     return ComparisonNode(parser, name, *args, **kwargs)
# 
# def do_block(parser, token):
#     """
#     Process several nodes inside a single block
#     Block functions take ``context``, ``nodelist`` as first arguments
#     If the second to last argument is ``as``, the rendered result is stored in the context and is named whatever the last argument is.
# 
#     Syntax::
# 
#         {% [block] [var args...] [name=value kwargs...] [as varname] %}
#             ... nodelist ...
#         {% end[block] %}
# 
#     Examples::
# 
#         {% render_block as rendered_output %}
#             {{ request.path }}/blog/{{ blog.slug }}
#         {% endrender_block %}
# 
#         {% highlight_block python %}
#             import this
#         {% endhighlight_block %}
# 
#     """
#     name, args, kwargs = get_signature(token, contextable=True)
#     kwargs['nodelist'] = parser.parse(('end%s' % name,))
#     parser.delete_first_token()
#     return BlockNode(parser, name, *args, **kwargs)
# 
# Path: native_tags/registry.py
# def register(self, bucket, name_or_func, func=None):
#     """
#     Add a function to the registry by name
#     """
#     assert bucket in self, 'Bucket %s is unknown' % bucket
#     if func is None and hasattr(name_or_func, '__name__'):
#         name = name_or_func.__name__
#         func = name_or_func
#     elif func:
#         name = name_or_func
#     if name in self[bucket]:
#         raise AlreadyRegistered('The function %s is already registered' % name)
# 
#     self[bucket][name] = func


# Path: native_tags/templatetags/native.py
from django.template import Library
from native_tags.nodes import do_function, do_comparison, do_block
from native_tags.registry import register as native_register




register = Library()

for tag_name in native_register['comparison']:
    if not tag_name.startswith('if'):
        tag_name = 'if_%s' % tag_name 
    register.tags[tag_name] = do_comparison
    
for tag_name in native_register['function']:
    register.tags[tag_name] = do_function

for tag_name in native_register['block']:
    register.tags[tag_name] = do_block


register.filters.update(native_register['filter'])