From 9c77a1b4a8337f8ea004e0f1b20bcb5364e9359e Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 23 Apr 2020 18:07:49 +0200 Subject: [PATCH] Add views --- views/about.njk | 14 ++++ views/errors/400.njk | 2 + views/errors/401.njk | 2 + views/errors/403.njk | 2 + views/errors/404.njk | 2 + views/errors/500.njk | 2 + views/errors/503.njk | 2 + views/errors/error.njk | 36 ++++++++++ views/home.njk | 7 ++ views/layouts/barebone.njk | 35 ++++++++++ views/layouts/base.njk | 40 +++++++++++ views/macros.njk | 136 +++++++++++++++++++++++++++++++++++++ 12 files changed, 280 insertions(+) create mode 100644 views/about.njk create mode 100644 views/errors/400.njk create mode 100644 views/errors/401.njk create mode 100644 views/errors/403.njk create mode 100644 views/errors/404.njk create mode 100644 views/errors/500.njk create mode 100644 views/errors/503.njk create mode 100644 views/errors/error.njk create mode 100644 views/home.njk create mode 100644 views/layouts/barebone.njk create mode 100644 views/layouts/base.njk create mode 100644 views/macros.njk diff --git a/views/about.njk b/views/about.njk new file mode 100644 index 0000000..08342ae --- /dev/null +++ b/views/about.njk @@ -0,0 +1,14 @@ +{% extends 'layouts/base.njk' %} + +{% set title = 'Example App - About us' %} + +{% block body %} +

Very interesting

+ +
+
+

This is us

+

And we like wms!

+
+
+{% endblock %} \ No newline at end of file diff --git a/views/errors/400.njk b/views/errors/400.njk new file mode 100644 index 0000000..a5bc022 --- /dev/null +++ b/views/errors/400.njk @@ -0,0 +1,2 @@ +{% extends './error.njk' %} +{% import 'macros.njk' as macros %} diff --git a/views/errors/401.njk b/views/errors/401.njk new file mode 100644 index 0000000..a5bc022 --- /dev/null +++ b/views/errors/401.njk @@ -0,0 +1,2 @@ +{% extends './error.njk' %} +{% import 'macros.njk' as macros %} diff --git a/views/errors/403.njk b/views/errors/403.njk new file mode 100644 index 0000000..a5bc022 --- /dev/null +++ b/views/errors/403.njk @@ -0,0 +1,2 @@ +{% extends './error.njk' %} +{% import 'macros.njk' as macros %} diff --git a/views/errors/404.njk b/views/errors/404.njk new file mode 100644 index 0000000..a5bc022 --- /dev/null +++ b/views/errors/404.njk @@ -0,0 +1,2 @@ +{% extends './error.njk' %} +{% import 'macros.njk' as macros %} diff --git a/views/errors/500.njk b/views/errors/500.njk new file mode 100644 index 0000000..a5bc022 --- /dev/null +++ b/views/errors/500.njk @@ -0,0 +1,2 @@ +{% extends './error.njk' %} +{% import 'macros.njk' as macros %} diff --git a/views/errors/503.njk b/views/errors/503.njk new file mode 100644 index 0000000..a5bc022 --- /dev/null +++ b/views/errors/503.njk @@ -0,0 +1,2 @@ +{% extends './error.njk' %} +{% import 'macros.njk' as macros %} diff --git a/views/errors/error.njk b/views/errors/error.njk new file mode 100644 index 0000000..3e0236a --- /dev/null +++ b/views/errors/error.njk @@ -0,0 +1,36 @@ +{% extends '../layouts/barebone.njk' %} + +{% set title = error_code + ' - ' + error_message %} + +{% block _stylesheets %} + +{% endblock %} + +{% block _body %} + + +
+ {% if flash %} + {{ macros.messages(flash) }} + {% endif %} + +
{{ error_code }}
+
{{ error_message }}
+
{{ error_instructions|safe }}
+ + +
+ +
+ Error ID: {{ error_id }} +
+ If you think this isn't right, please contact us with the above error ID at + contact@example.net. +
+{% endblock %} \ No newline at end of file diff --git a/views/home.njk b/views/home.njk new file mode 100644 index 0000000..1afefb7 --- /dev/null +++ b/views/home.njk @@ -0,0 +1,7 @@ +{% extends 'layouts/base.njk' %} + +{% set title = 'Example App - Hello world!' %} + +{% block body %} +

Hello world!

+{% endblock %} \ No newline at end of file diff --git a/views/layouts/barebone.njk b/views/layouts/barebone.njk new file mode 100644 index 0000000..c40f522 --- /dev/null +++ b/views/layouts/barebone.njk @@ -0,0 +1,35 @@ + + + + + {{ title }} + + + + + + {% if description %} + + {% endif %} + + {% if refresh_after %} + + {% endif %} + + {% block _stylesheets %}{% endblock %} + {% block _scripts %} + + {% endblock %} + + + +
+ {% block header %}{% endblock %} +
+ +{% block _body %}{% endblock %} + + + + + \ No newline at end of file diff --git a/views/layouts/base.njk b/views/layouts/base.njk new file mode 100644 index 0000000..36e5e8d --- /dev/null +++ b/views/layouts/base.njk @@ -0,0 +1,40 @@ +{% extends './barebone.njk' %} +{% import 'macros.njk' as macros %} + +{% block _stylesheets %} + {{ super() }} + + {% block stylesheets %}{% endblock %} +{% endblock %} +{% block _scripts %} + {{ super() }} + {% block scripts %}{% endblock %} +{% endblock %} + +{% block header %} + + +{% endblock %} + +{% block _body %} +
+ {{ macros.messages(flash) }} +
+ +
+ {% if h1 %} +

{{ h1 }}

+ {% endif %} + {% if subtitle %} +

{{ subtitle }}

+ {% endif %} + + {% block body %}{% endblock %} +
+{% endblock %} + +{% block footer %}Example app v{{ app_version }} - all rights reserved.{% endblock %} \ No newline at end of file diff --git a/views/macros.njk b/views/macros.njk new file mode 100644 index 0000000..6ba1583 --- /dev/null +++ b/views/macros.njk @@ -0,0 +1,136 @@ +{% macro message(type, content, raw=false, discreet=false) %} +
+ + + {{ content|safe if raw else content }} + +
+{% endmacro %} + +{% macro messages(flash) %} + {% set flashed = flash() %} + {% set display = 0 %} + + {% for type, bag in flashed %} + {% if bag|length %} + {% set display = 1 %} + {% endif %} + {% endfor %} + + {% if display %} +
+ {% for type, bag in flashed %} + {% for content in bag %} + {{ message(type, content) }} + {% endfor %} + {% endfor %} +
+ {% endif %} +{% endmacro %} + +{% macro csrf(getCSRFToken) %} + +{% endmacro %} + +{% macro field(_locals, type, name, value, placeholder, hint, validation_attributes='', extraData='') %} + {% set validation = _locals.validation() %} + {% set validation = validation[name] if validation[name] or null %} + {% set previousFormData = _locals.previousFormData() %} + {% set value = previousFormData[name] or value or validation.value or '' %} + + {% if type == 'hidden' %} + {% if validation %} + {{ message('error', validation.message) }} + {% endif %} + + {% else %} +
+ {% if type == 'duration' %} +
+ {% for f in extraData %} +
+ {% if previousFormData[name] %} + {% set v = value[f] %} + {% else %} + {% set v = (value % 60) if f == 's' else (((value - value % 60) / 60 % 60) if f == 'm' else ((value - value % 3600) / 3600 if f == 'h')) %} + {% endif %} + + +
+ {% endfor %} +
+ {% elseif type == 'select' %} + + + {% else %} + + {% endif %} + + + {% if validation %} +
{{ validation.message }}
+ {% endif %} + {% if hint %} +
{{ hint }}
+ {% endif %} +
+ {% endif %} +{% endmacro %} + +{% macro websocket(websocketUrl, listener, reconnectOnClose = 1, checkFunction = 0) %} + +{% endmacro %} + +{% macro paginate(pagination, routeName) %} + {% if pagination.hasPrevious() or pagination.hasNext() %} + + {% endif %} +{% endmacro %} \ No newline at end of file