def main(): ''' Render a template from the filesystem and write the result to stdout ''' opts, args = parse_args() logger.setLevel(opts.level.upper()) appdir = os.path.join(os.path.abspath(os.path.dirname(__file__)), opts.app) scripts, stylesheets = aiding.getFiles( appdir, '', # handle the prefixing in the template coffee=opts.coffee) context = { 'baseUrl': opts.base, 'mini': '.min' if not opts.devel else '', 'scripts': scripts, 'stylesheets': stylesheets, 'coffee': opts.coffee, } template = load_tmpl(opts.tmpl) if opts.create == '-': sys.stdout.write(template.render(context)) else: logger.info("Creating {0}".format(opts.create)) with open(opts.create, 'w+') as fp: fp.write(template.render(context))
def createStaticMain(kind='bottle', moldPath=MOLD_DIR_PATH, base="", devel=False, coffee=False, save=False, path=os.path.join(STATIC_APP_PATH, 'main.html')): """ Generate and return main.html using template filepath mold and optionally write to filepath path is save """ import bottle data = dict(baseUrl=base, mini=".min" if not devel else "", coffee = coffee ) #get lists of app scripts and styles filenames scripts, sheets = aiding.getFiles( top=STATIC_APP_PATH, prefix='', coffee = coffee) data['scripts'] = scripts data['sheets'] = sheets content = '' mainMoldPath = os.path.join(moldPath, 'main_{0}.html'.format(kind)) with open(mainMoldPath, "r") as fp: mold = fp.read() if kind == 'bottle': content = bottle.SimpleTemplate(mold).render(**data) #elif kind == 'mustache': #content = staching.render(mold, data) if content and save: with open(path, 'w+') as fp: fp.write(content) return content