diff --git a/doc/development/api/general.rst b/doc/development/api/general.rst index f88212bd56..98984c3076 100644 --- a/doc/development/api/general.rst +++ b/doc/development/api/general.rst @@ -26,7 +26,7 @@ Frontend -------- .. automodule:: pretix.presale.signals - :members: html_head, html_footer, footer_link, front_page_top, front_page_bottom, fee_calculation_for_cart, contact_form_fields, question_form_fields, checkout_confirm_messages, checkout_confirm_page_content, checkout_all_optional + :members: html_head, html_footer, footer_link, front_page_top, front_page_bottom, fee_calculation_for_cart, contact_form_fields, question_form_fields, checkout_confirm_messages, checkout_confirm_page_content, checkout_all_optional, html_page_header, sass_preamble, sass_postamble .. automodule:: pretix.presale.signals diff --git a/src/pretix/presale/context.py b/src/pretix/presale/context.py index 24e2e98f15..6735a5ddac 100644 --- a/src/pretix/presale/context.py +++ b/src/pretix/presale/context.py @@ -8,7 +8,7 @@ from pretix.helpers.i18n import ( get_javascript_format_without_seconds, get_moment_locale, ) -from .signals import footer_link, html_footer, html_head +from .signals import footer_link, html_footer, html_head, html_page_header def contextprocessor(request): @@ -23,6 +23,7 @@ def contextprocessor(request): 'DEBUG': settings.DEBUG, } _html_head = [] + _html_page_header = [] _html_foot = [] _footer = [] @@ -45,6 +46,8 @@ def contextprocessor(request): if hasattr(request, 'event'): for receiver, response in html_head.send(request.event, request=request): _html_head.append(response) + for receiver, response in html_page_header.send(request.event, request=request): + _html_page_header.append(response) for receiver, response in html_footer.send(request.event, request=request): _html_foot.append(response) for receiver, response in footer_link.send(request.event, request=request): @@ -71,6 +74,7 @@ def contextprocessor(request): ctx['html_head'] = "".join(_html_head) ctx['html_foot'] = "".join(_html_foot) + ctx['html_page_header'] = "".join(_html_page_header) ctx['footer'] = _footer ctx['site_url'] = settings.SITE_URL diff --git a/src/pretix/presale/signals.py b/src/pretix/presale/signals.py index 8aed761808..8cca4ac085 100644 --- a/src/pretix/presale/signals.py +++ b/src/pretix/presale/signals.py @@ -11,6 +11,17 @@ of every page in the frontend. You will get the request as the keyword argument As with all plugin signals, the ``sender`` keyword argument will contain the event. """ +html_page_header = EventPluginSignal( + providing_args=["request"] +) +""" +This signal allows you to put code right in the beginnong of the HTML ``
`` tag +of every page in the frontend. You will get the request as the keyword argument +``request`` and are expected to return plain HTML. + +As with all plugin signals, the ``sender`` keyword argument will contain the event. +""" + html_footer = EventPluginSignal( providing_args=["request"] ) @@ -22,6 +33,33 @@ of every page in the frontend. You will get the request as the keyword argument As with all plugin signals, the ``sender`` keyword argument will contain the event. """ +sass_preamble = EventPluginSignal( + providing_args=["filename"] +) +""" +This signal allows you to put SASS code at the beginning of the event-specific +stylesheet. Keep in mind that this will only be called/rebuilt when the user changes +display settings or pretix gets updated. You will get the filename that is being +generated (usually "main.scss" or "widget.scss"). This SASS code will be loaded *after* +setting of user-defined variables like colors and fonts but *before* pretix' SASS +code. + +As with all plugin signals, the ``sender`` keyword argument will contain the event. +""" + +sass_postamble = EventPluginSignal( + providing_args=["filename"] +) +""" +This signal allows you to put SASS code at the end of the event-specific +stylesheet. Keep in mind that this will only be called/rebuilt when the user changes +display settings or pretix gets updated. You will get the filename that is being +generated (usually "main.scss" or "widget.scss"). This SASS code will be loaded *after* +all of pretix' SASS code. + +As with all plugin signals, the ``sender`` keyword argument will contain the event. +""" + footer_link = EventPluginSignal( providing_args=["request"] ) diff --git a/src/pretix/presale/style.py b/src/pretix/presale/style.py index 6a98da43a9..a7fff3e4b5 100644 --- a/src/pretix/presale/style.py +++ b/src/pretix/presale/style.py @@ -16,6 +16,7 @@ from pretix.base.models import Event, Event_SettingsStore, Organizer from pretix.base.services.tasks import ProfiledTask from pretix.celery_app import app from pretix.multidomain.urlreverse import get_domain +from pretix.presale.signals import sass_postamble, sass_preamble logger = logging.getLogger('pretix.presale.style') affected_keys = ['primary_font', 'primary_color'] @@ -54,8 +55,16 @@ def compile_scss(object, file="main.scss", fonts=True): font )) + if isinstance(object, Event): + for recv, resp in sass_preamble.send(object, filename=file): + sassrules.append(resp) + sassrules.append('@import "{}";'.format(file)) + if isinstance(object, Event): + for recv, resp in sass_postamble.send(object, filename=file): + sassrules.append(resp) + cf = dict(django_libsass.CUSTOM_FUNCTIONS) cf['static'] = static css = sass.compile( diff --git a/src/pretix/presale/templates/pretixpresale/base.html b/src/pretix/presale/templates/pretixpresale/base.html index 7d7e215b54..beb7b5341f 100644 --- a/src/pretix/presale/templates/pretixpresale/base.html +++ b/src/pretix/presale/templates/pretixpresale/base.html @@ -59,6 +59,7 @@ +{{ html_page_header|safe }} {% block above %} {% endblock %}