Assets¶
Additional extensions and functions for the flask_assets module.
-
invenio.ext.assets.
command
¶ Flask-Script command that deals with assets.
Documentation is on: webassets Included Commands
# How to install it from flask_script import Manager manager = Manager() manager.add_command("assets", command)
-
invenio.ext.assets.
registry
¶ Flask-Registry registry that handles the bundles. Use it directly as it’s lazy loaded.
-
invenio.ext.assets.
setup_app
(app)¶ Initialize Assets extension.
Use the
ASSETS_BUNDLES_DIR
option to change the name of the directory where the assets are generated (by defaultgen
).Parameters: app – Flask application
-
class
invenio.ext.assets.
Bundle
(*contents, **options)¶ Bases:
webassets.bundle.Bundle
Bundle extension with a name and bower dependencies.
The name is only used for the requirements from the templates and the weight does the bundle ordering.
The bower dependencies are used to generate a bower.json file.
-
has_filter
(*filters)¶ Tell whether a given filter is set up for this bundle.
-
-
class
invenio.ext.assets.
RequireJSFilter
(*args, **kwargs)¶ Bases:
webassets.filter.requirejs.RequireJSFilter
Optimize AMD-style modularized JavaScript into a single asset.
Adds support for exclusion of files already in defined in other bundles.
-
method
= False¶
-
setup
()¶ Setup filter (only called when filter is actually used).
-
-
class
invenio.ext.assets.
CleanCSSFilter
(**kwargs)¶ Bases:
webassets.filter.ExternalTool
Minify css using cleancss.
Implements opener capable of rebasing relative CSS URLs against
COLLECT_STATIC_ROOT
.-
input
(_in, out, **kw)¶ Input filtering.
-
method
= u'open'¶
-
name
= u'cleancssurl'¶
-
open
(out, source_path, **kw)¶ Open source.
-
options
= {u'binary': u'CLEANCSS_BIN'}¶
-
output
(_in, out, **kw)¶ Output filtering.
-
setup
()¶ Initialize filter just before it will be used.
-
Flask-Script commands¶
Command-line tools for assets.
-
class
invenio.ext.assets.commands.
AssetsCommand
(assets_env=None, impl=<class 'flask_assets.FlaskArgparseInterface'>, log=None)¶ Bases:
flask_assets.ManageAssets
Command-line operation for assets.
-
run
(args)¶ Run the command-line.
It loads the bundles from the
bundles registry
.
-
-
class
invenio.ext.assets.commands.
BowerCommand
(func=None)¶ Bases:
flask_script.commands.Command
Command-line operation for bower.
-
option_list
= (<flask_script.commands.Option object at 0x7fdcf03b7590>, <flask_script.commands.Option object at 0x7fdcf03b7610>, <flask_script.commands.Option object at 0x7fdcf03b7650>)¶
-
run
(filename=None, override=False, output_file=None)¶ Generate a bower.json file.
It comes with default values for the ignore. Name and version are set to be invenio’s.
-
Jinja2 extensions¶
Custom Jinja2 extensions.
-
class
invenio.ext.assets.extensions.
BundleExtension
(environment)¶ Bases:
jinja2.ext.Extension
Jinja extension for css and js bundles.
Definition of the required bundles.
{%- bundles "jquery.js", "invenio.css" -%} {%- bundle "require.js" -%}
Usage.
{%- for bundle in get_bundle('js') %} <!-- {{ bundle.output }} --> {%- assets bundle %} <script type="text/javascript" src="{{ ASSET_URL }}"></script> {%- endassets %} {%- endfor %} </body> </html>
-
identifier
= 'invenio.ext.assets.extensions.BundleExtension'¶
-
classmethod
inject
()¶ Inject the get_bundle function into the jinja templates.
-
classmethod
install
(app)¶ Install the extension into the application.
-
parse
(parser)¶ Parse the bundles block and feed the bundles environment.
Bundles entries are replaced by an empty string.
-
classmethod
storage
()¶ Store used bundles on request context stack.
-
-
class
invenio.ext.assets.extensions.
InvenioResolver
¶ Bases:
flask_assets.FlaskResolver
Custom resource resolver for webassets.
-
resolve_source
(ctx, item)¶ Return the absolute path of the resource.
-
resolve_source_to_url
(ctx, filepath, item)¶ Return the url of the resource.
Displaying them as is in debug mode as the web server knows where to search for them.
-
search_for_source
(ctx, item)¶ Return absolute path of the resource.
webassets.env.Resolver.search_for_source()
Parameters: - ctx – environment
- item – resource filename
Returns: absolute path
-
Registry¶
Registry for bundles.
-
invenio.ext.assets.registry.
bundles
¶ Flask-Registry registry that handles the bundles. Use it directly as it’s lazy loaded.
Wrappers¶
Custom modified classes.
-
class
invenio.ext.assets.wrappers.
Bundle
(*contents, **options)¶ Bases:
webassets.bundle.Bundle
Bundle extension with a name and bower dependencies.
The name is only used for the requirements from the templates and the weight does the bundle ordering.
The bower dependencies are used to generate a bower.json file.
-
has_filter
(*filters)¶ Tell whether a given filter is set up for this bundle.
-
-
class
invenio.ext.assets.wrappers.
BundlesAutoDiscoveryRegistry
(module_name=None, app=None, with_setup=False, silent=False)¶ Bases:
flask_registry.registries.modulediscovery.ModuleAutoDiscoveryRegistry
Registry that searches for bundles.
Its registry is a list of the package name and the bundle itself. This way you can keep track of where a bundle was loaded from.
-
class
invenio.ext.assets.wrappers.
CleanCSSFilter
(**kwargs)¶ Bases:
webassets.filter.ExternalTool
Minify css using cleancss.
Implements opener capable of rebasing relative CSS URLs against
COLLECT_STATIC_ROOT
.-
input
(_in, out, **kw)¶ Input filtering.
-
method
= u'open'¶
-
name
= u'cleancssurl'¶
-
open
(out, source_path, **kw)¶ Open source.
-
options
= {u'binary': u'CLEANCSS_BIN'}¶
-
output
(_in, out, **kw)¶ Output filtering.
-
setup
()¶ Initialize filter just before it will be used.
-
-
class
invenio.ext.assets.wrappers.
RequireJSFilter
(*args, **kwargs)¶ Bases:
webassets.filter.requirejs.RequireJSFilter
Optimize AMD-style modularized JavaScript into a single asset.
Adds support for exclusion of files already in defined in other bundles.
-
method
= False¶
-
setup
()¶ Setup filter (only called when filter is actually used).
-