def __init__(self, app=None, **kwargs): r"""Extension initialization. :param app: An instance of :class:`~flask.Flask`. :param \**kwargs: Keyword arguments are passed to ``init_app`` method. """ self.env = Environment() self.collect = Collect() self.webpack = FlaskWebpackExt() if app: self.init_app(app, **kwargs)
def app(instance_path, static_folder): """Flask application.""" app_ = Flask('test', instance_path=instance_path, static_folder=static_folder) FlaskWebpackExt(app_) return app_
def test_project(app): """.""" WebpackTemplateProject() FlaskWebpackExt(app) with app.test_client() as client: res = client.get("/") assert res.status_code == 200 assert 'Welcome to Flask-WebpackExt' in str(res.data)
def init_app(self, app, **kwargs): """Initialize application object. :param app: An instance of :class:`~flask.Flask`. .. versionchanged:: 1.0.0b2 The *entrypoint* has been renamed to *entry_point_group*. """ self.init_config(app) self.collect = Collect(app) self.webpack = FlaskWebpackExt(app) app.extensions['invenio-assets'] = self
def test_init(): """Test extension initialization.""" app = Flask('testapp') ext = FlaskWebpackExt(app) assert 'flask-webpackext' in app.extensions app = Flask('testapp') ext = FlaskWebpackExt() assert 'flask-webpackext' not in app.extensions ext.init_app(app) assert 'flask-webpackext' in app.extensions
__path__ = dirname(realpath(__file__)) security = Security(app, admins_store) babel = Babel(app) project = WebpackTemplateProject( __name__, project_folder='assets', config_path='assets/config.json', ) app.config.update(dict(WEBPACKEXT_PROJECT=project, )) # Initialize extension FlaskWebpackExt(app) admin = AdminLte(app, skin='green-light', name=_('Hermes - Automates à réaction aux échanges IMAP'), short_name="<b>H</b><sup>ermes</sup>", long_name="<b>Hermes</b>", index_view=AdminIndexView(name=_("Éditeur d'Automate"), menu_icon_value='fa-pencil', menu_icon_type='fa')) db.init_app(app) migrate = Migrate(app, db) ma = Marshmallow(app) NotificationIncident.init_app(app)
from indico.web.assets.util import get_custom_assets class IndicoManifestLoader(JinjaManifestLoader): cache = {} def __init__(self, *args, **kwargs): self.custom = kwargs.pop('custom', True) super(IndicoManifestLoader, self).__init__(*args, **kwargs) def load(self, filepath): key = (filepath, os.path.getmtime(filepath)) if key not in IndicoManifestLoader.cache: IndicoManifestLoader.cache[key] = manifest = ManifestLoader.load( self, filepath) if self.custom: self._add_custom_assets(manifest) return IndicoManifestLoader.cache[key] def _add_custom_assets(self, manifest): # custom assets (from CUSTOMIZATION_DIR) are not part of the webpack manifest # since they are not build with webpack (it's generally not available on the # machine running indico), but we add them here anyway so they can be handled # without too much extra code, e.g. when building a static site. manifest.add(self.entry_cls('__custom.css', get_custom_assets('css'))) manifest.add(self.entry_cls('__custom.js', get_custom_assets('js'))) webpack = FlaskWebpackExt()
import app.logging as applogging # noqa imported for side effects import logging from config import Config from typing import Type from .database import init_db, session login_manager = LoginManager() login_manager.login_view = 'auth.login' mail = Mail() assets = Environment() csrf = CSRFProtect() webpackext = FlaskWebpackExt() logger = logging.getLogger(__name__) def create_app(config_class: Type[Config] = Config): logger.info("Creating app") assets._named_bundles = {} app = Flask(__name__, instance_relative_config=True) app.config.from_object(config_class) # ensure the instance folder exists try: os.makedirs(app.instance_path) except OSError as e: logger.info(f"Exception occured: {e} ")
class InvenioAssets(object): """Invenio asset extension.""" def __init__(self, app=None, **kwargs): r"""Extension initialization. :param app: An instance of :class:`~flask.Flask`. :param \**kwargs: Keyword arguments are passed to ``init_app`` method. """ self.env = Environment() self.collect = Collect() self.webpack = FlaskWebpackExt() if app: self.init_app(app, **kwargs) def init_app(self, app, entry_point_group='invenio_assets.bundles', **kwargs): """Initialize application object. :param app: An instance of :class:`~flask.Flask`. :param entry_point_group: A name of entry point group used to load ``webassets`` bundles. .. versionchanged:: 1.0.0b2 The *entrypoint* has been renamed to *entry_point_group*. """ self.init_config(app) self.env.init_app(app) self.collect.init_app(app) self.webpack.init_app(app) if entry_point_group: self.load_entrypoint(entry_point_group) app.extensions['invenio-assets'] = self def init_config(self, app): """Initialize configuration. :param app: An instance of :class:`~flask.Flask`. """ app.config.setdefault('REQUIREJS_BASEURL', app.static_folder) app.config.setdefault('COLLECT_STATIC_ROOT', app.static_folder) app.config.setdefault('COLLECT_STORAGE', 'flask_collect.storage.link') app.config.setdefault( 'COLLECT_FILTER', partial(collect_staticroot_removal, app)) app.config.setdefault( 'WEBPACKEXT_PROJECT', 'invenio_assets.webpack:project') def load_entrypoint(self, entry_point_group): """Load entrypoint. :param entry_point_group: A name of entry point group used to load ``webassets`` bundles. .. versionchanged:: 1.0.0b2 The *entrypoint* has been renamed to *entry_point_group*. """ for ep in pkg_resources.iter_entry_points(entry_point_group): self.env.register(ep.name, ep.load())