def setup(self): try: from jsjinja import JsJinja env = self.config.get("jsjinja", {}).get("env", None) self.jsjinja = JsJinja(env) except ImportError: raise EnvironmentError('The "jsjinja" package is not installed.')
def __init__(self, environment): super(JsJinjaExtension, self).__init__(environment) # add the defaults to the environment environment.extend( jsjinja=JsJinja(self.environment) # generate_js=self.generate_js, # generate_all_templates=self.generate_all_templates, )
class JsJinja(Processor): def setup(self): try: from jsjinja import JsJinja env = self.config.get("jsjinja", {}).get("env", None) self.jsjinja = JsJinja(env) except ImportError: raise EnvironmentError('The "jsjinja" package is not installed.') def process(self, asset, lib=False, minified=True): processed = super(JsJinja, self).process(asset) if lib: lib_content = self.jsjinja.lib(minified) if asset.single: processed.content = lib_content + processed.content else: processed._assets = [StringAsset(lib_content)] + processed._assets return processed def process_single(self, asset): # print '***********', asset, asset.content, '***********' asset.content = self.jsjinja.generate_source(asset.content, name=asset.source) + ";" return asset