address djlint lint

and autoformat js in templates
This commit is contained in:
Min RK
2024-04-19 10:12:28 +02:00
parent d9ce1b917f
commit 75c947be59
19 changed files with 384 additions and 312 deletions

View File

@@ -42,6 +42,9 @@ repos:
- id: djlint-reformat-jinja - id: djlint-reformat-jinja
files: ".*templates/.*.html" files: ".*templates/.*.html"
types_or: ["html"] types_or: ["html"]
- id: djlint-jinja
files: ".*templates/.*.html"
types_or: ["html"]
# Autoformat and linting, misc. details # Autoformat and linting, misc. details
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks

View File

@@ -23,8 +23,12 @@
document.body.innerText = "Rendered API specification doesn't work with file: protocol. Use sphinx-autobuild to do local builds of the docs, served over HTTP." document.body.innerText = "Rendered API specification doesn't work with file: protocol. Use sphinx-autobuild to do local builds of the docs, served over HTTP."
} else { } else {
Redoc.init( Redoc.init(
"{{ pathto('_static/rest-api.yml', 1) }}", "{{ pathto('_static/rest-api.yml', 1) }}", {
{{ meta.redoc_options | default({}) }}, {
meta.redoc_options |
default ({})
}
},
document.getElementById("redoc-spec"), document.getElementById("redoc-spec"),
); );
} }

View File

@@ -1,5 +1,7 @@
{% extends "templates/page.html" %} {% extends "templates/page.html" %}
{% block announcement %}<div class="container text-center announcement"></div>{% endblock %} {% block announcement %}
<div class="container text-center announcement"></div>
{% endblock announcement %}
{% block script %} {% block script %}
{{ super() }} {{ super() }}
<script> <script>
@@ -7,4 +9,4 @@
$(".announcement").html(data["announcement"]); $(".announcement").html(data["announcement"]);
}); });
</script> </script>
{% endblock %} {% endblock script %}

View File

@@ -17,7 +17,7 @@ It makes the following modifications:
style="margin-right: 4px; style="margin-right: 4px;
margin-left: 2px">Control Panel</a> margin-left: 2px">Control Panel</a>
</span> </span>
{% endblock %} {% endblock header_buttons %}
{% block logo %} {% block logo %}
<img src="{{ logo_url }}" alt="Jupyter Notebook" /> <img src="{{ logo_url }}" alt="Jupyter Notebook" />
{% endblock logo %} {% endblock logo %}

View File

@@ -124,6 +124,18 @@ select = [
# https://djlint.com/docs/configuration/ # https://djlint.com/docs/configuration/
[tool.djlint] [tool.djlint]
indent = 2 indent = 2
# ignore often-incorrect lint
# H006: image height/width attributes
# ignore style lint that formatter doesn't catch
# H008: double-quotes
# H029: form method case
ignore = "H006,H008,H021,H029"
use_gitignore = true
format_js = true
[tool.djlint.js]
indent_size = 2
# tbump is used to simplify and standardize the release process when updating # tbump is used to simplify and standardize the release process when updating
# the version, making a git commit and tag, and pushing changes. # the version, making a git commit and tag, and pushing changes.

View File

@@ -1,2 +1,4 @@
{% extends "error.html" %} {% extends "error.html" %}
{% block error_detail %}<p>Jupyter has lots of moons, but this is not one...</p>{% endblock %} {% block error_detail %}
<p>Jupyter has lots of moons, but this is not one...</p>
{% endblock error_detail %}

View File

@@ -1,5 +1,6 @@
{% extends "page.html" %} {% extends "page.html" %}
{% block login_widget %}{% endblock %} {% block login_widget %}
{% endblock login_widget %}
{% block main %} {% block main %}
<div class="container"> <div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">
@@ -16,7 +17,7 @@
to start the server before you can access it. to start the server before you can access it.
</p> </p>
{% endif %} {% endif %}
<form method="POST" action=""> <form method="post" action="">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
By accepting the invitation, you will be granted the following permissions, By accepting the invitation, you will be granted the following permissions,
@@ -48,4 +49,4 @@
</div> </div>
</div> </div>
</div> </div>
{% endblock %} {% endblock main %}

View File

@@ -7,7 +7,7 @@
</script> </script>
<script src={{ static_url("js/admin-react.js") }}></script> <script src={{ static_url("js/admin-react.js") }}></script>
</div> </div>
{% endblock %} {% endblock main %}
{% block footer %} {% block footer %}
<div class="py-2 px-4 bg-body-tertiary small version_footer">JupyterHub {{ server_version }}</div> <div class="py-2 px-4 bg-body-tertiary small version_footer">JupyterHub {{ server_version }}</div>
{% endblock %} {% endblock footer %}

View File

@@ -1,5 +1,6 @@
{% extends "page.html" %} {% extends "page.html" %}
{% block login_widget %}{% endblock %} {% block login_widget %}
{% endblock login_widget %}
{% block main %} {% block main %}
<div class="error"> <div class="error">
{% block h1_error %} {% block h1_error %}
@@ -11,7 +12,7 @@
{% if extra_error_html %}<p>{{ extra_error_html | safe }}</p>{% endif %} {% if extra_error_html %}<p>{{ extra_error_html | safe }}</p>{% endif %}
{% endblock error_detail %} {% endblock error_detail %}
</div> </div>
{% endblock %} {% endblock main %}
{% block script %} {% block script %}
{{ super() }} {{ super() }}
<script type="text/javascript"> <script type="text/javascript">
@@ -40,4 +41,4 @@
_remove_redirects_from_url(); _remove_redirects_from_url();
</script> </script>
{% endblock %} {% endblock script %}

View File

@@ -86,5 +86,7 @@
{% endblock main %} {% endblock main %}
{% block script %} {% block script %}
{{ super() }} {{ super() }}
<script type="text/javascript">require(["home"]);</script> <script type="text/javascript">
{% endblock %} require(["home"]);
</script>
{% endblock script %}

View File

@@ -2,7 +2,8 @@
{% if announcement_login is string %} {% if announcement_login is string %}
{% set announcement = announcement_login %} {% set announcement = announcement_login %}
{% endif %} {% endif %}
{% block login_widget %}{% endblock %} {% block login_widget %}
{% endblock login_widget %}
{% block main %} {% block main %}
{% block login %} {% block login %}
<div id="login-main" class="container"> <div id="login-main" class="container">
@@ -86,7 +87,7 @@
{% endblock login_container %} {% endblock login_container %}
</div> </div>
{% endblock login %} {% endblock login %}
{% endblock %} {% endblock main %}
{% block script %} {% block script %}
{{ super() }} {{ super() }}
<script> <script>
@@ -103,4 +104,4 @@ $('form').submit((e) => {
form.find('.feedback-widget>*').toggleClass('fa-pulse'); form.find('.feedback-widget>*').toggleClass('fa-pulse');
}); });
</script> </script>
{% endblock %} {% endblock script %}

View File

@@ -6,4 +6,4 @@
<div id="logout-main" class="container"> <div id="logout-main" class="container">
<p>Successfully logged out.</p> <p>Successfully logged out.</p>
</div> </div>
{% endblock %} {% endblock main %}

View File

@@ -11,7 +11,7 @@
Server not running Server not running
{% endif %} {% endif %}
</h1> </h1>
{% endblock %} {% endblock heading %}
{% block message %} {% block message %}
<p> <p>
{% if failed %} {% if failed %}
@@ -35,7 +35,7 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
</p> </p>
{% endblock %} {% endblock message %}
{% block start_button %} {% block start_button %}
<a id="start" <a id="start"
role="button" role="button"
@@ -48,17 +48,21 @@
{% endif %} {% endif %}
Server {{ server_name }} Server {{ server_name }}
</a> </a>
{% endblock %} {% endblock start_button %}
</div> </div>
</div> </div>
</div> </div>
{% endblock %} {% endblock main %}
{% block script %} {% block script %}
{{ super () }} {{ super () }}
{% if implicit_spawn_seconds %} {% if implicit_spawn_seconds %}
<script type="text/javascript"> <script type="text/javascript">
var spawn_url = "{{ spawn_url }}"; var spawn_url = "{{ spawn_url }}";
var implicit_spawn_seconds = {{ implicit_spawn_seconds }}; var implicit_spawn_seconds = {
{
implicit_spawn_seconds
}
};
setTimeout(function() { setTimeout(function() {
console.log("redirecting to spawn at", spawn_url); console.log("redirecting to spawn at", spawn_url);
window.location = spawn_url; window.location = spawn_url;
@@ -67,5 +71,7 @@
); );
</script> </script>
{% endif %} {% endif %}
<script type="text/javascript">require(["not_running"]);</script> <script type="text/javascript">
require(["not_running"]);
</script>
{% endblock script %} {% endblock script %}

View File

@@ -1,5 +1,6 @@
{% extends "page.html" %} {% extends "page.html" %}
{% block login_widget %}{% endblock %} {% block login_widget %}
{% endblock login_widget %}
{% block main %} {% block main %}
<div class="container"> <div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">
@@ -14,7 +15,7 @@
your behalf. your behalf.
{% endif %} {% endif %}
</p> </p>
<form method="POST" action=""> <form method="post" action="">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<p class="h5">This will grant the application permission to:</p> <p class="h5">This will grant the application permission to:</p>
@@ -26,9 +27,12 @@
{% for scope_info in scope_descriptions %} {% for scope_info in scope_descriptions %}
<div class="checkbox input-group"> <div class="checkbox input-group">
<label> <label>
<input type="checkbox" name="raw-scopes" checked="true" title="This authorization is required" {# disabled because it's required #}
disabled="disabled" <input type="checkbox"
{# disabled because it's required #} /> name="raw-scopes"
checked="true"
title="This authorization is required"
disabled="disabled" />
<span> <span>
{{ scope_info['description'] }} {{ scope_info['description'] }}
{% if scope_info['filter'] %}Applies to {{ scope_info['filter'] }}.{% endif %} {% if scope_info['filter'] %}Applies to {{ scope_info['filter'] }}.{% endif %}
@@ -44,4 +48,5 @@
</form> </form>
</div> </div>
</div> </div>
{% endblock %} </div>
{% endblock main %}

View File

@@ -10,9 +10,7 @@
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h2 class="modal-title" id="{{ key }}-label"> <h2 class="modal-title" id="{{ key }}-label">{{ title }}</h2>
{{ title }}
</h1>
<button type="button" <button type="button"
class="btn-close" class="btn-close"
data-bs-dismiss="modal" data-bs-dismiss="modal"
@@ -34,22 +32,30 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title> <title>
{% block title %}JupyterHub{% endblock %} {%- block title -%}
JupyterHub
{%- endblock title -%}
</title> </title>
<meta http-equiv="X-UA-Compatible" content="chrome=1"> <meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
{% block stylesheet %} {% block stylesheet %}
<link rel="stylesheet" href="{{ static_url("css/style.min.css") }}" type="text/css" /> <link rel="stylesheet" href="{{ static_url("css/style.min.css") }}" type="text/css" />
{% endblock %} {% endblock stylesheet %}
{% block favicon %}<link rel="icon" href="{{ static_url("favicon.ico") }}" type="image/x-icon">{% endblock %} {% block favicon %}
<link rel="icon" href="{{ static_url("favicon.ico") }}" type="image/x-icon">
{% endblock favicon %}
{% block scripts %} {% block scripts %}
<script src="{{static_url("components/bootstrap/dist/js/bootstrap.bundle.min.js") }}" type="text/javascript" charset="utf-8"></script> <script src="{{static_url("components/bootstrap/dist/js/bootstrap.bundle.min.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("components/requirejs/require.js") }}" type="text/javascript" charset="utf-8"></script> <script src="{{static_url("components/requirejs/require.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("components/jquery/dist/jquery.min.js") }}" type="text/javascript" charset="utf-8"></script> <script src="{{static_url("components/jquery/dist/jquery.min.js") }}" type="text/javascript" charset="utf-8"></script>
{% endblock %} {% endblock scripts %}
<script> {# djlint js formatting doesn't handle template blocks in js #}
{# djlint: off #}
<script type="text/javascript">
require.config({ require.config({
{% if version_hash %}urlArgs: "v={{version_hash}}",{% endif %} {% if version_hash %}
urlArgs: "v={{version_hash}}",
{% endif %}
baseUrl: '{{static_url("js", include_version=False)}}', baseUrl: '{{static_url("js", include_version=False)}}',
paths: { paths: {
components: '../components', components: '../components',
@@ -57,17 +63,14 @@
moment: "../components/moment/moment", moment: "../components/moment/moment",
}, },
}); });
</script>
<script type="text/javascript">
window.jhdata = { window.jhdata = {
base_url: "{{base_url}}", base_url: "{{base_url}}",
prefix: "{{prefix}}", prefix: "{{prefix}}",
{% if user %} {% if user %}
{# {#- Autoescaping in templates is turned on in JupyterHub, #}
Autoescaping in templates is turned on in JupyterHub, {#- need `| safe` to prevent escaping #}
need `| safe` to prevent escaping {#- `https://github.com/pallets/markupsafe/blob/2.1.4/src/markupsafe/_native.py#L6` #}
https://github.com/pallets/markupsafe/blob/2.1.4/src/markupsafe/_native.py#L6
#}
user: "{{ user.json_escaped_name | safe }}", user: "{{ user.json_escaped_name | safe }}",
{% endif %} {% endif %}
{% if admin_access %} {% if admin_access %}
@@ -81,10 +84,14 @@
options_form: false, options_form: false,
{% endif %} {% endif %}
xsrf_token: "{{ xsrf_token }}", xsrf_token: "{{ xsrf_token }}",
} };
</script> </script>
{# djlint: on #}
{% block meta %} {% block meta %}
{% endblock %} <meta name="description" content="JupyterHub">
<meta name="keywords" content="Jupyter, JupyterHub">
{% endblock meta %}
</head> </head>
<body> <body>
<noscript> <noscript>
@@ -100,12 +107,21 @@ Please enable it to proceed.
{% block logo %} {% block logo %}
<span id="jupyterhub-logo" class="navbar-brand"> <span id="jupyterhub-logo" class="navbar-brand">
<a href="{{ logo_url or base_url }}"> <a href="{{ logo_url or base_url }}">
<img src='{{ base_url }}logo' alt='JupyterHub logo' class='jpy-logo' title='Home' /> <img src='{{ base_url }}logo'
alt='JupyterHub logo'
class='jpy-logo'
title='Home' />
</a> </a>
</span> </span>
{% endblock %} {% endblock logo %}
{% if user %} {% if user %}
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#thenavbar" aria-controls="thenavbar" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#thenavbar"
aria-controls="thenavbar"
aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
{% endif %} {% endif %}
@@ -126,19 +142,23 @@ Please enable it to proceed.
{% endif %} {% endif %}
{% if services %} {% if services %}
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false">Services</a> <a href="#"
class="nav-link dropdown-toggle"
data-bs-toggle="dropdown"
role="button"
aria-expanded="false">Services</a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
{% for service in services %} {% for service in services %}
{% block service scoped %} {% block service scoped %}
<li> <li>
<a class="dropdown-item" href="{{ service.href }}">{{ service.name }}</a> <a class="dropdown-item" href="{{ service.href }}">{{ service.name }}</a>
</li> </li>
{% endblock %} {% endblock service %}
{% endfor %} {% endfor %}
</ul> </ul>
</li> </li>
{% endif %} {% endif %}
{% endblock %} {% endblock nav_bar_left_items %}
</ul> </ul>
{% endif %} {% endif %}
<ul class="nav navbar-nav me-2"> <ul class="nav navbar-nav me-2">
@@ -148,30 +168,40 @@ Please enable it to proceed.
<span id="login_widget"> <span id="login_widget">
{% if user %} {% if user %}
<span class="navbar-text">{{ user.name }}</span> <span class="navbar-text">{{ user.name }}</span>
<a id="logout" role="button" class="btn btn-sm btn-outline-dark" href="{{ logout_url }}"> <i aria-hidden="true" class="fa fa-sign-out"></i> Logout</a> <a id="logout"
role="button"
class="btn btn-sm btn-outline-dark"
href="{{ logout_url }}"> <i aria-hidden="true" class="fa fa-sign-out"></i> Logout</a>
{% else %} {% else %}
<a id="login" role="button" class="btn btn-sm btn-outline-dark" href="{{ login_url }}">Login</a> <a id="login"
role="button"
class="btn btn-sm btn-outline-dark"
href="{{ login_url }}">Login</a>
{% endif %} {% endif %}
</span> </span>
{% endblock %} {% endblock login_widget %}
</li> </li>
{% endblock %} {% endblock nav_bar_right_items %}
</ul> </ul>
</div> </div>
{% block header %}{% endblock %} {% block header %}
{% endblock header %}
</div> </div>
</nav> </nav>
{% endblock %} {% endblock nav_bar %}
{% block announcement %} {% block announcement %}
{% if announcement %} {% if announcement %}
<div class="container text-center announcement alert alert-warning">{{ announcement | safe }}</div> <div class="container text-center announcement alert alert-warning">{{ announcement | safe }}</div>
{% endif %} {% endif %}
{% endblock %} {% endblock announcement %}
{% block main %}{% endblock %} {% block main %}
{% block footer %}{% endblock %} {% endblock main %}
{% block footer %}
{% endblock footer %}
{% call modal('Error', btn_label='OK') %} {% call modal('Error', btn_label='OK') %}
<div class="ajax-error alert-danger">The error</div> <div class="ajax-error alert-danger">The error</div>
{% endcall %} {% endcall %}
{% block script %}{% endblock %} {% block script %}
{% endblock script %}
</body> </body>
</html> </html>

View File

@@ -8,7 +8,7 @@
<div class="row text-center"> <div class="row text-center">
<h1>Server Options</h1> <h1>Server Options</h1>
</div> </div>
{% endblock %} {% endblock heading %}
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-8"> <div class="col-md-8">
{% if for_user and user.name != for_user.name -%} {% if for_user and user.name != for_user.name -%}
@@ -31,7 +31,8 @@
</form> </form>
</div> </div>
</div> </div>
{% endblock %} </div>
{% endblock main %}
{% block script %} {% block script %}
{{ super() }} {{ super() }}
<script> <script>
@@ -43,4 +44,4 @@ $('form').submit((e) => {
form.find('.feedback-widget>*').toggleClass('fa-pulse'); form.find('.feedback-widget>*').toggleClass('fa-pulse');
}); });
</script> </script>
{% endblock %} {% endblock script %}

View File

@@ -6,15 +6,14 @@
{% block message %} {% block message %}
<p>Your server is starting up.</p> <p>Your server is starting up.</p>
<p>You will be redirected automatically when it's ready for you.</p> <p>You will be redirected automatically when it's ready for you.</p>
{% endblock %} {% endblock message %}
<div class="progress"> <div class="progress">
<div id="progress-bar" <div id="progress-bar"
class="progress-bar" class="progress-bar"
role="progressbar" role="progressbar"
aria-valuenow="0" aria-valuenow="0"
aria-valuemin="0" aria-valuemin="0"
aria-valuemax="100" aria-valuemax="100">
style="width: 0%">
<span class="sr-only"><span id="sr-progress">0%</span> Complete</span> <span class="sr-only"><span id="sr-progress">0%</span> Complete</span>
</div> </div>
</div> </div>
@@ -30,7 +29,7 @@
</div> </div>
</div> </div>
</div> </div>
{% endblock %} {% endblock main %}
{% block script %} {% block script %}
{{ super() }} {{ super() }}
<script type="text/javascript"> <script type="text/javascript">
@@ -93,4 +92,4 @@ require(["jquery"], function ($) {
window._jupyterhub_page_loaded = true; window._jupyterhub_page_loaded = true;
}); });
</script> </script>
{% endblock %} {% endblock script %}

View File

@@ -14,7 +14,7 @@
</div> </div>
</div> </div>
</div> </div>
{% endblock %} {% endblock main %}
{% block script %} {% block script %}
{{ super() }} {{ super() }}
<script type="text/javascript"> <script type="text/javascript">
@@ -27,4 +27,4 @@ require(["jquery"], function ($) {
}, 5000); }, 5000);
}); });
</script> </script>
{% endblock %} {% endblock script %}

View File

@@ -166,6 +166,7 @@
</td> </td>
<td class="col-sm-1 text-center"> <td class="col-sm-1 text-center">
<button class="revoke-token-btn btn btn-xs btn-danger">revoke</button> <button class="revoke-token-btn btn btn-xs btn-danger">revoke</button>
</td>
{% endblock client_row %} {% endblock client_row %}
</tr> </tr>
{% endfor %} {% endfor %}
@@ -177,5 +178,7 @@
{% endblock main %} {% endblock main %}
{% block script %} {% block script %}
{{ super() }} {{ super() }}
<script type="text/javascript">require(["token"]);</script> <script type="text/javascript">
require(["token"]);
</script>
{% endblock script %} {% endblock script %}