def compile(self, *args, **kw): assert 'output' in kw kw.setdefault('debug', False) bundle = Bundle(*args, **kw) for url in bundle.urls(env=self.environment): yield url
def _merge_and_apply( self, ctx, output, force, parent_debug=None, parent_filters=None, extra_filters=None, disable_cache=None, ): hunk = Bundle._merge_and_apply( self, ctx, output, force, parent_debug=parent_debug, parent_filters=parent_filters, extra_filters=extra_filters, disable_cache=disable_cache, ) return ChainedHunk( MemoryHunk(_PLUGIN_BUNDLE_WRAPPER_PREFIX.format(plugin=self.plugin)), (hunk, lambda x: x.replace("\n", "\n ")), MemoryHunk(_PLUGIN_BUNDLE_WRAPPER_SUFFIX.format(plugin=self.plugin)), )
def _get_bundle(self, data): """Return a bundle initialised by the given dict.""" kwargs = dict(filters=data.get('filters', None), output=data.get('output', None), debug=data.get('debug', None), extra=data.get('extra', {}), depends=data.get('depends', None)) return Bundle(*list(self._yield_bundle_contents(data)), **kwargs)
def test_load_bundles(self): import types module = types.ModuleType('test') module.foo = Bundle('bar') loader = PythonLoader(module) bundles = loader.load_bundles() assert len(bundles) == 1 assert list(bundles.values())[0].contents[0] == 'bar'
def _merge_and_apply(self, ctx, output, force, parent_debug=None, parent_filters=None, extra_filters=None, disable_cache=None): hunk = Bundle._merge_and_apply(self, ctx, output, force, parent_debug=parent_debug, parent_filters=parent_filters, extra_filters=extra_filters, disable_cache=disable_cache) return ChainedHunk(MemoryHunk(_PLUGIN_BUNDLE_WRAPPER_PREFIX.format(plugin=self.plugin)), (hunk, lambda x: x.replace("\n", "\n ")), MemoryHunk(_PLUGIN_BUNDLE_WRAPPER_SUFFIX.format(plugin=self.plugin)))
def _get_bundles(self, obj): bundles = {} for key, data in obj.iteritems(): if data is None: data = {} contents = data.get('contents', []) if isinstance(contents, basestring): contents = [contents] bundles[key] = Bundle(filters=data.get('filters', None), output=data.get('output', None), *contents) return bundles
def modified(self): """Iterate template dependencies for modification and check web assets if a bundle needs to be rebuilt.""" for item in chain([self.path], self.loader.resolved[self.path]): if self.loader.modified[item]: return True for args, kwargs in self.loader.assets[self.path]: kwargs.setdefault('debug', False) bundle = Bundle(*args, **kwargs) rv = self.environment.webassets.environment.updater.needs_rebuild( bundle, self.environment.webassets.environment) if rv: return True return False
def __init__(self, plugin, *args, **kwargs): Bundle.__init__(self, *args, **kwargs) self.plugin = plugin
def test_check(self): bundle = Bundle() self.assertTrue(check(bundle, self.portal))
def create_app(test_config=None) -> Flask: logger.info("Creating app") assets_env._named_bundles = {} app = Flask(__name__, instance_relative_config=True) # Default settings from config file app.config.from_object(Config) if test_config is not None: app.config.from_object(test_config) # Check mandatory settings, and throw if they don't exist if app.config.get("UPLOAD_FOLDER") is None: raise ValueError("Missing setting for UPLOAD_FOLDER") # ensure the instance folder exists try: os.makedirs(app.instance_path) except OSError as e: logger.info(f"Exception occured: {e} ") # Init addons init_db(app.config['SQLALCHEMY_DATABASE_URI']) @app.teardown_appcontext def cleanup(resp_or_exc): session.remove() login_manager.init_app(app) csrf.init_app(app) mail.init_app(app) app.jinja_env.add_extension('webassets.ext.jinja2.AssetsExtension') webpack_manifest = Path( __file__).absolute().parent / 'static' / 'manifest.json' if webpack_manifest.exists(): webpack_env = WebpackEnvironment(manifest=webpack_manifest, publicRoot="") app.jinja_env.filters['webpack'] = WebpackFilter(webpack_env) app.jinja_env.assets_environment = assets_env # Register blueprints from . import auth logger.debug("Registering blueprint auth") app.register_blueprint(auth.bp) from . import main logger.debug("Registering blueprint main") app.register_blueprint(main.bp) from . import assets app.register_blueprint(assets.bp) from . import profile logger.debug("Registering blueprint profile") app.register_blueprint(profile.bp, url_prefix='/profile') from . import content logger.debug("Registering blueprint content") app.register_blueprint(content.bp, url_prefix='/content') from . import userassets logger.debug("Registering assets module") app.register_blueprint(userassets.bp, url_prefix='/assets') app.register_blueprint(userassets.apibp, url_prefix='/api/assets') from . import character logger.debug("Registering blueprint character") app.register_blueprint(character.bp, url_prefix='/character') app.register_blueprint(character.api, url_prefix='/api/character') character.register_assets(assets_env) from . import campaign app.register_blueprint(campaign.bp, url_prefix='/campaign') app.register_blueprint(campaign.apibp, url_prefix='/api/campaign') campaign.register_assets(assets_env) app.add_url_rule('/', endpoint='profile.index') @app.route('/hello') def hello(): return "Hello, World!" with app.app_context(): from .database import cli # noqa, Add some commands for database handling. logger.debug("Registering assets") assets_env.url = app.static_url_path assets_env.config['TYPESCRIPT_CONFIG'] = '--target ES6' scss = Bundle('scss/main.scss', filters='pyscss', output='css/all.css') assets_env.register('scss_all', scss) css_profile = Bundle('scss/profile.scss', filters='pyscss', output='css/profile.css') assets_env.register('scss_profile', css_profile) return app