"""
Dummy testing template tags and filters.
"""


from analytical.templatetags.analytical import TAG_LOCATIONS
from django.template import Library, Node, TemplateSyntaxError

register = Library()


def _location_node(location):
    class DummyNode(Node):
        def render(self, context):
            return f"<!-- dummy_{location} -->"
    return DummyNode


_location_nodes = {loc: _location_node(loc) for loc in TAG_LOCATIONS}


def _location_tag(location):
    def dummy_tag(parser, token):
        bits = token.split_contents()
        if len(bits) > 1:
            raise TemplateSyntaxError(f"'{bits[0]}' tag takes no arguments")
        return _location_nodes[location]
    return dummy_tag


for loc in TAG_LOCATIONS:
    register.tag(f'dummy_{loc}', _location_tag(loc))


def contribute_to_analytical(add_node_cls):
    for location in TAG_LOCATIONS:
        add_node_cls(location, _location_nodes[location])
