# Path: kikola/core/context_processors.py
# def path(request):
#     """
#     Adds current absolute URI, path and full path variables to templates.
# 
#     To enable, adds ``kikola.core.context_processors.path`` to your project's
#     ``settings`` ``TEMPLATE_CONTEXT_PROCESSORS`` var.
# 
#     **Note:** Django has ``django.core.context_processors.request`` context
#     processor that adding whole ``HttpRequest`` object to templates.
#     """
#     return {'REQUEST_ABSOLUTE_URI': request.build_absolute_uri(),
#             'REQUEST_FULL_PATH': request.get_full_path(),
#             'REQUEST_PATH': request.path}
# 
# Path: kikola/core/decorators.py
# def render_to(template_path, mimetype=None):
#     """
#     Expect the dict from view. Render returned dict with RequestContext.
#     """
#     def decorator(func):
#         @wraps(func)
#         def wrapper(request, *args, **kwargs):
#             output = func(request, *args, **kwargs)
# 
#             if not isinstance(output, dict):
#                 return output
# 
#             kwargs = {'context_instance': RequestContext(request)}
#             output['request'] = request
# 
#             if 'MIME_TYPE' in output:
#                 kwargs['mimetype'] = output.pop('MIME_TYPE')
#             elif 'MIMETYPE' in output:
#                 kwargs['mimetype'] = output.pop('MIMETYPE')
#             elif mimetype:
#                 kwargs['mimetype'] = mimetype
# 
#             if 'TEMPLATE' in output:
#                 template = output.pop('TEMPLATE')
#             else:
#                 template = template_path
# 
#             return render_to_response(template, output, **kwargs)
#         return wrapper
#     return decorator
# 
# def render_to_json(*args, **json_kwargs):
#     """
#     Render output from view function as JSON response.
#     """
#     def json_decorator(func, **json_kwargs):
#         @wraps(func)
#         def wrapper(request, *args, **kwargs):
#             # Execute view function
#             output = func(request, *args, **kwargs)
# 
#             # Prepare JSON kwargs
#             defaults = {'cls': DjangoJSONEncoder,
#                         'ensure_ascii': False}
#             defaults.update(json_kwargs)
# 
#             # Dumps view function output into JSON response
#             return HttpResponse(json.dumps(output, **defaults),
#                                 mimetype='application/json')
#         return wrapper
# 
#     if not args and not json_kwargs:
#         return json_decorator
# 
#     if args and callable(args[0]):
#         return json_decorator(args[0], **json_kwargs)
# 
#     def decorator(func):
#         return json_decorator(func, **json_kwargs)
#     return decorator


from kikola.core.context_processors import path
from kikola.core.decorators import render_to, render_to_json


@render_to_json
def context_processors_path(request):
    return path(request)


@render_to('core/render_to.html')
def decorators_render_to(request):
    return {'text': 'It works!'}


@render_to('core/render_to.txt', mimetype='text/plain')
def decorators_render_to_with_mimetype(request):
    return {'text': 'It works!'}



# Path: kikola/core/context_processors.py
# def path(request):
#     """
#     Adds current absolute URI, path and full path variables to templates.
# 
#     To enable, adds ``kikola.core.context_processors.path`` to your project's
#     ``settings`` ``TEMPLATE_CONTEXT_PROCESSORS`` var.
# 
#     **Note:** Django has ``django.core.context_processors.request`` context
#     processor that adding whole ``HttpRequest`` object to templates.
#     """
#     return {'REQUEST_ABSOLUTE_URI': request.build_absolute_uri(),
#             'REQUEST_FULL_PATH': request.get_full_path(),
#             'REQUEST_PATH': request.path}
# 
# Path: kikola/core/decorators.py
# def render_to(template_path, mimetype=None):
#     """
#     Expect the dict from view. Render returned dict with RequestContext.
#     """
#     def decorator(func):
#         @wraps(func)
#         def wrapper(request, *args, **kwargs):
#             output = func(request, *args, **kwargs)
# 
#             if not isinstance(output, dict):
#                 return output
# 
#             kwargs = {'context_instance': RequestContext(request)}
#             output['request'] = request
# 
#             if 'MIME_TYPE' in output:
#                 kwargs['mimetype'] = output.pop('MIME_TYPE')
#             elif 'MIMETYPE' in output:
#                 kwargs['mimetype'] = output.pop('MIMETYPE')
#             elif mimetype:
#                 kwargs['mimetype'] = mimetype
# 
#             if 'TEMPLATE' in output:
#                 template = output.pop('TEMPLATE')
#             else:
#                 template = template_path
# 
#             return render_to_response(template, output, **kwargs)
#         return wrapper
#     return decorator
# 
# def render_to_json(*args, **json_kwargs):
#     """
#     Render output from view function as JSON response.
#     """
#     def json_decorator(func, **json_kwargs):
#         @wraps(func)
#         def wrapper(request, *args, **kwargs):
#             # Execute view function
#             output = func(request, *args, **kwargs)
# 
#             # Prepare JSON kwargs
#             defaults = {'cls': DjangoJSONEncoder,
#                         'ensure_ascii': False}
#             defaults.update(json_kwargs)
# 
#             # Dumps view function output into JSON response
#             return HttpResponse(json.dumps(output, **defaults),
#                                 mimetype='application/json')
#         return wrapper
# 
#     if not args and not json_kwargs:
#         return json_decorator
# 
#     if args and callable(args[0]):
#         return json_decorator(args[0], **json_kwargs)
# 
#     def decorator(func):
#         return json_decorator(func, **json_kwargs)
#     return decorator


# Path: testproject/core/views.py
from kikola.core.context_processors import path
from kikola.core.decorators import render_to, render_to_json



@render_to_json
def context_processors_path(request):
    return path(request)


@render_to('core/render_to.html')
def decorators_render_to(request):
    return {'text': 'It works!'}


@render_to('core/render_to.txt', mimetype='text/plain')
def decorators_render_to_with_mimetype(request):
    return {'text': 'It works!'}



@render_to('core/render_to.html')