Create a gist now

Instantly share code, notes, and snippets.

def _simple_processor(processor, ext_private, ext_public):
if not request.path.endswith(ext_public):
public_file = request.path[len( + 1:]
public_file_path = os.path.join(, public_file)
private_file_path = public_file_path[:-len(ext_public)] + ext_private
# File does not exist in app static - check blueprints.
if not os.path.isfile(private_file_path):
for blueprint_name, blueprint in
if request.path.startswith(blueprint.static_url_path):
public_file = request.path[len(blueprint.static_url_path) + 1:]
public_file_path = os.path.join(blueprint.static_folder, public_file)
private_file_path = public_file_path[:-len(ext_public)] + ext_private
# If file doesn't exist in the blueprints as well, let flask handle it.
if not os.path.isfile(private_file_path):
if not os.path.isfile(public_file_path) or (os.path.getmtime(private_file_path) >=
processor(private_file_path, public_file_path)
def less_to_css():
processor = lambda in_file, out_file: subprocess.check_output(['lessc',
in_file, out_file], shell=False)
return _simple_processor(processor, '.less', '.css')
def coffee_to_js():
processor = lambda in_file, out_file: subprocess.check_output(['coffee',
'-c', in_file], shell=False)
return _simple_processor(processor, '.coffee', '.js')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment