From 27e38101a46ad012eadc851fcefe42a89001192d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=20V=C3=AEjdea?= Date: Mon, 10 Sep 2018 02:41:02 +0300 Subject: [PATCH] Add customization blocks to ui templates Closes #178. --- docs/changelog.rst | 1 + docs/custom_ui.rst | 17 ++++- src/drf_yasg/templates/drf-yasg/redoc.html | 14 ++-- .../templates/drf-yasg/swagger-ui.html | 69 ++++++------------- 4 files changed, 45 insertions(+), 56 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 832a721..a2e3958 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -11,6 +11,7 @@ Changelog - **ADDED:** added the ``SPEC_URL`` setting for controlling the download link in ``swagger-ui`` and ``ReDoc`` - **ADDED:** updated ``ReDoc`` settings (added ``NATIVE_SCROLLBARS`` and ``REQUIRED_PROPS_FIRST``) +- **ADDED:** added ``extra_styles`` and ``extra_scripts`` blocks to ui templates (:issue:`178`) - **IMPROVED:** updated ``swagger-ui`` to version 3.18.2 - **IMPROVED:** updated ``ReDoc`` to version 2.0.0-alpha.37 - **FIXED:** stopped generating invalid OpenAPI by improper placement of ``readOnly`` Schemas diff --git a/docs/custom_ui.rst b/docs/custom_ui.rst index ed5c3d5..c81d5ad 100644 --- a/docs/custom_ui.rst +++ b/docs/custom_ui.rst @@ -2,6 +2,17 @@ Customizing the web UI ###################### -There is currently no pluggable way of customizing the web UI apart from the settings available in -:ref:`swagger-ui-settings` and :ref:`redoc-ui-settings`. If you really need to, you can override one of the -``drf-yasg/swagger-ui.html`` or ``drf-yasg/redoc.html`` templates that are used for rendering. +The web UI can be customized using the settings available in :ref:`swagger-ui-settings` and :ref:`redoc-ui-settings`. + +You can also extend one of the ``drf-yasg/swagger-ui.html`` or ``drf-yasg/redoc.html`` templates that are used for +rendering. The customizable blocks are currently limited to: + +{% block extra_styles %} + additional stylesheets + +{% block extra_scripts %} + additional scripts + +{% block user_context_message %} + *(swagger-ui session auth only)* + logged in user message diff --git a/src/drf_yasg/templates/drf-yasg/redoc.html b/src/drf_yasg/templates/drf-yasg/redoc.html index 5a5b527..34f4a2f 100644 --- a/src/drf_yasg/templates/drf-yasg/redoc.html +++ b/src/drf_yasg/templates/drf-yasg/redoc.html @@ -7,12 +7,18 @@ + {% block extra_styles %} + {# -- Add any additional CSS scripts here -- #} + {% endblock %} - + - - - + + + +{% block extra_scripts %} + {# -- Add any additional scripts here -- #} +{% endblock %} diff --git a/src/drf_yasg/templates/drf-yasg/swagger-ui.html b/src/drf_yasg/templates/drf-yasg/swagger-ui.html index 570a10a..515974b 100644 --- a/src/drf_yasg/templates/drf-yasg/swagger-ui.html +++ b/src/drf_yasg/templates/drf-yasg/swagger-ui.html @@ -11,53 +11,14 @@ - + {% block extra_styles %} + {# -- Add any additional CSS scripts here -- #} + {% endblock %} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - @@ -66,28 +27,38 @@ +{% block extra_scripts %} + {# -- Add any additional scripts here -- #} +{% endblock %} {% if USE_SESSION_AUTH %}