# Path: knights/escape.py

# 
# Path: knights/library.py
# class Library:
#     '''
#     Container for registering tags and helpers
#     '''
#     def __init__(self):
#         self.tags = {}
#         self.helpers = {}
# 
#     def tag(self, func=None, name=None):
#         if func is None:
#             return partial(self.tag, name=name)
# 
#         if name is None:
#             name = func.__name__
# 
#         self.tags[name] = func
#         return func
# 
#     def helper(self, func=None, name=None):
#         if func is None:
#             return partial(self.helper, name=name)
# 
#         if name is None:
#             name = func.__name__
# 
#         self.helpers[name] = func
#         return func


from .escape import escape_html, escape_js
from .library import Library
'''
Default helper functions
'''

register = Library()


@register.helper
def addslashes(value):
    return value.replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'")


@register.helper
def capfirst(value):
    return value and value[0].upper() + value[1:]


ESCAPES = {
    'html': escape_html,
    'js': escape_js,
}


@register.helper
def escape(value, mode='html'):
    return ESCAPES[mode](value)


# Lambda's have no names

# Path: knights/escape.py

# 
# Path: knights/library.py
# class Library:
#     '''
#     Container for registering tags and helpers
#     '''
#     def __init__(self):
#         self.tags = {}
#         self.helpers = {}
# 
#     def tag(self, func=None, name=None):
#         if func is None:
#             return partial(self.tag, name=name)
# 
#         if name is None:
#             name = func.__name__
# 
#         self.tags[name] = func
#         return func
# 
#     def helper(self, func=None, name=None):
#         if func is None:
#             return partial(self.helper, name=name)
# 
#         if name is None:
#             name = func.__name__
# 
#         self.helpers[name] = func
#         return func


# Path: knights/helpers.py
from .escape import escape_html, escape_js
from .library import Library

'''
Default helper functions
'''

register = Library()


@register.helper
def addslashes(value):
    return value.replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'")


@register.helper
def capfirst(value):
    return value and value[0].upper() + value[1:]


ESCAPES = {
    'html': escape_html,
    'js': escape_js,
}


@register.helper
def escape(value, mode='html'):
    return ESCAPES[mode](value)


# Lambda's have no names

register.helper(escape_html, name='escape_html')