Created
July 17, 2012 05:46
-
-
Save DavidLGoldberg/3127455 to your computer and use it in GitHub Desktop.
Not sure this is useful. Turns directories that start with _m_ and contain mustache templates into a module. Meant to be used at build time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pystache | |
import os, glob | |
#TODO: use argparse or some config vars | |
ACTIONS_DIR_PREFIX = '_m_' | |
MAIN_TEMPLATE_NAME = 'main.mustache' | |
START_WALK = os.getcwd() | |
ENV = {} | |
for root, directories, files in os.walk(START_WALK): | |
for directory in directories: | |
if directory.startswith(ACTIONS_DIR_PREFIX): | |
actions = '' | |
mustache_module = open( | |
os.path.join(root, directory.split(ACTIONS_DIR_PREFIX)[1] + '.py'), 'w+') | |
main_file_name = os.path.join(directory, MAIN_TEMPLATE_NAME) | |
main_template = open(main_file_name, 'r').read() | |
compiled_actions = ''; | |
for f in os.listdir(directory): | |
if f.endswith('.mustache') and f != MAIN_TEMPLATE_NAME: | |
action_template = open(os.path.join(directory, f), 'r').read() | |
compiled_actions += pystache.render(action_template, ENV) + '\n' | |
mustache_module.write(pystache.render(main_template, {'actions': compiled_actions})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment