Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jinja): webpack_optional global helper #265

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions oarepo_ui/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
from pathlib import Path

from flask import Response, current_app
from flask_webpackext import current_manifest
from flask_webpackext.errors import ManifestKeyNotFoundError
from importlib_metadata import entry_points
from invenio_base.utils import obj_or_import_string
from flask_login import user_logged_in, user_logged_out
from markupsafe import Markup

from .proxies import current_optional_manifest
from .utils import clear_view_deposit_page_permission_from_session


Expand All @@ -20,6 +25,12 @@ def __init__(self, app):
self.init_builder_plugin()
self._catalog = None

def optional_manifest(self, key):
try:
return current_manifest[key]
except ManifestKeyNotFoundError as e:
return Markup(f"<!-- Warn: {e} -->")

def reinitialize_catalog(self):
self._catalog = None
try:
Expand Down Expand Up @@ -95,6 +106,7 @@ def init_app(self, app):
app.extensions["oarepo_ui"] = OARepoUIState(app)
user_logged_in.connect(clear_view_deposit_page_permission_from_session)
user_logged_out.connect(clear_view_deposit_page_permission_from_session)
app.add_template_global(current_optional_manifest, name="webpack_optional")

def init_config(self, app):
"""Initialize configuration."""
Expand Down
3 changes: 3 additions & 0 deletions oarepo_ui/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

current_oarepo_ui = LocalProxy(lambda: current_app.extensions["oarepo_ui"])
"""Proxy to the oarepo_ui state."""

current_optional_manifest = LocalProxy(lambda: current_oarepo_ui.optional_manifest)
"""Proxy to current optional webpack manifest."""
5 changes: 2 additions & 3 deletions oarepo_ui/templates/oarepo_ui/javascript.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% include "invenio_theme/javascript.html" %}

{{ webpack['oarepo-overridable-registry.js'] }}
{{ webpack['oarepo_ui_theme.js'] }}
{{ webpack['oarepo_ui_components.js'] }}
{{ webpack['oarepo-overridable-registry.js'] }}


{{ webpack_optional('overrides-' ~ request.endpoint ~ '.js') }}
Loading