def load_from_templates(self): # Using the Django loader bundles = DjangoLoader().load_bundles() # Using the Jinja loader, if available try: import jinja2 except ImportError: pass else: from webassets.ext.jinja2 import Jinja2Loader, AssetsExtension jinja2_envs = [] # Prepare a Jinja2 environment we can later use for parsing. # If not specified by the user, put in there at least our own # extension, which we will need most definitely to achieve anything. _jinja2_extensions = getattr(settings, 'ASSETS_JINJA2_EXTENSIONS', False) if not _jinja2_extensions: _jinja2_extensions = [AssetsExtension.identifier] jinja2_envs.append( jinja2.Environment(extensions=_jinja2_extensions)) try: from coffin.common import get_env as get_coffin_env except ImportError: pass else: jinja2_envs.append(get_coffin_env()) bundles.extend( Jinja2Loader(get_env(), get_django_template_dirs(), jinja2_envs).load_bundles()) return bundles
def load_from_templates(self, env): from webassets.ext.jinja2 import Jinja2Loader, AssetsExtension from flask import current_app as app # Use the application's Jinja environment to parse jinja2_env = app.jinja_env # Get the template directories of app and blueprints template_dirs = [path.join(app.root_path, app.template_folder)] for blueprint in app.blueprints: template_dirs.append( path.join(blueprint.root_path, blueprint.template_folder)) return Jinja2Loader(env, template_dirs, [jinja2_env]).load_bundles()
def test(self): loader = Jinja2Loader(self.env, [self.tempdir], [self.jinja_env]) bundles = loader.load_bundles() assert len(bundles) == 1 assert bundles[0].output == "output.html"