# Path: render_utils.py
# class BetterJSONEncoder(json.JSONEncoder):
#     """
#     A JSON encoder that intelligently handles datetimes.
#     """
#     def default(self, obj):
#         if isinstance(obj, datetime):
#             encoded_object = obj.isoformat()
#         else:
#             encoded_object = json.JSONEncoder.default(self, obj)
#     
#         return encoded_object
# 
# def flatten_app_config():
#     """
#     Returns a copy of app_config containing only
#     configuration variables.
#     """
#     config = {}
# 
#     # Only all-caps [constant] vars get included
#     for k, v in app_config.__dict__.items():
#         if k.upper() == k:
#             config[k] = v
# 
#     return config


import json
import os
import subprocess
import app_config
import copytext
from mimetypes import guess_type
from re import findall
from flask import abort, make_response
from werkzeug.datastructures import Headers
from flask import Blueprint
from render_utils import BetterJSONEncoder, flatten_app_config
    from flask import Response, request
#!/usr/bin/env python




static = Blueprint('static', __name__)

# Render JST templates on-demand
@static.route('/js/templates.js')
def _templates_js():
    r = subprocess.check_output(["node_modules/universal-jst/bin/jst.js", "--template", "underscore", "jst"])

    return make_response(r, 200, { 'Content-Type': 'application/javascript' })

# Render LESS files on-demand
@static.route('/less/<string:filename>')
def _less(filename):
    if not os.path.exists('less/%s' % filename):
        abort(404)

    r = subprocess.check_output(["node_modules/less/bin/lessc", "less/%s" % filename])

    return make_response(r, 200, { 'Content-Type': 'text/css' })

# Render application configuration
@static.route('/js/app_config.js')
def _app_config_js():
    config = flatten_app_config()

# Path: render_utils.py
# class BetterJSONEncoder(json.JSONEncoder):
#     """
#     A JSON encoder that intelligently handles datetimes.
#     """
#     def default(self, obj):
#         if isinstance(obj, datetime):
#             encoded_object = obj.isoformat()
#         else:
#             encoded_object = json.JSONEncoder.default(self, obj)
#     
#         return encoded_object
# 
# def flatten_app_config():
#     """
#     Returns a copy of app_config containing only
#     configuration variables.
#     """
#     config = {}
# 
#     # Only all-caps [constant] vars get included
#     for k, v in app_config.__dict__.items():
#         if k.upper() == k:
#             config[k] = v
# 
#     return config


# Path: static.py
import json
import os
import subprocess
import app_config
import copytext
from mimetypes import guess_type
from re import findall
from flask import abort, make_response
from werkzeug.datastructures import Headers
from flask import Blueprint
from render_utils import BetterJSONEncoder, flatten_app_config
    from flask import Response, request

#!/usr/bin/env python




static = Blueprint('static', __name__)

# Render JST templates on-demand
@static.route('/js/templates.js')
def _templates_js():
    r = subprocess.check_output(["node_modules/universal-jst/bin/jst.js", "--template", "underscore", "jst"])

    return make_response(r, 200, { 'Content-Type': 'application/javascript' })

# Render LESS files on-demand
@static.route('/less/<string:filename>')
def _less(filename):
    if not os.path.exists('less/%s' % filename):
        abort(404)

    r = subprocess.check_output(["node_modules/less/bin/lessc", "less/%s" % filename])

    return make_response(r, 200, { 'Content-Type': 'text/css' })

# Render application configuration
@static.route('/js/app_config.js')
def _app_config_js():
    config = flatten_app_config()

    js = 'window.APP_CONFIG = ' + json.dumps(config, cls=BetterJSONEncoder)