From 2149e88bdd64a66d867ad1f5c46e6aa0977d837a Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Fri, 2 Jun 2023 15:30:02 +0200 Subject: [PATCH] [mod] template preferences: split into elements (no functional change) HINT: this patch has no functional change / it is the preparation for following changes and bugfixes Over the years, the preferences template became an unmanageable beast. To make the source code more readable the monolith is splitted into elements. The splitting into elements also has the advantage that a new template can make use of them. The reversed checkbox is a quirk that is only used in the prefereces and must be eliminated in the long term. For this the macro 'checkbox_onoff_reversed' was added to the preferences.html template. The 'checkbox' macro is also a quirk of the preferences.html we don't want to use in other templates (it is an input-checkbox in a HTML form that was misused for status display). Signed-off-by: Markus Heiser --- .../themes/simple/src/less/toolkit.less | 4 +- searx/templates/simple/macros.html | 35 +- searx/templates/simple/page_with_header.html | 12 +- searx/templates/simple/preferences.html | 586 ++++++------------ .../simple/preferences/answerers.html | 43 ++ .../simple/preferences/autocomplete.html | 17 + .../simple/preferences/center_alignment.html | 12 + .../templates/simple/preferences/cookies.html | 45 ++ .../simple/preferences/doi_resolver.html | 16 + .../templates/simple/preferences/engines.html | 93 +++ .../templates/simple/preferences/footer.html | 14 + .../simple/preferences/image_proxy.html | 12 + .../simple/preferences/infinite_scroll.html | 12 + .../simple/preferences/language.html | 27 + .../templates/simple/preferences/method.html | 16 + .../simple/preferences/query_in_title.html | 12 + .../preferences/results_on_new_tab.html | 12 + .../simple/preferences/safesearch.html | 22 + searx/templates/simple/preferences/theme.html | 35 ++ .../templates/simple/preferences/tokens.html | 11 + .../simple/preferences/ui_locale.html | 16 + tests/unit/test_webapp.py | 2 +- 22 files changed, 623 insertions(+), 431 deletions(-) create mode 100644 searx/templates/simple/preferences/answerers.html create mode 100644 searx/templates/simple/preferences/autocomplete.html create mode 100644 searx/templates/simple/preferences/center_alignment.html create mode 100644 searx/templates/simple/preferences/cookies.html create mode 100644 searx/templates/simple/preferences/doi_resolver.html create mode 100644 searx/templates/simple/preferences/engines.html create mode 100644 searx/templates/simple/preferences/footer.html create mode 100644 searx/templates/simple/preferences/image_proxy.html create mode 100644 searx/templates/simple/preferences/infinite_scroll.html create mode 100644 searx/templates/simple/preferences/language.html create mode 100644 searx/templates/simple/preferences/method.html create mode 100644 searx/templates/simple/preferences/query_in_title.html create mode 100644 searx/templates/simple/preferences/results_on_new_tab.html create mode 100644 searx/templates/simple/preferences/safesearch.html create mode 100644 searx/templates/simple/preferences/theme.html create mode 100644 searx/templates/simple/preferences/tokens.html create mode 100644 searx/templates/simple/preferences/ui_locale.html diff --git a/searx/static/themes/simple/src/less/toolkit.less b/searx/static/themes/simple/src/less/toolkit.less index 93fa5e04c..18f72795d 100644 --- a/searx/static/themes/simple/src/less/toolkit.less +++ b/searx/static/themes/simple/src/less/toolkit.less @@ -428,7 +428,7 @@ reversed-checkbox displays unchecked checkedboxes as checked, and vice versa. see https://github.com/searxng/searxng/blob/3408d061aab9abc6168fec9bbc6deab71b236dac/searx/templates/simple/preferences.html#L313 */ input.checkbox-onoff[type="checkbox"], -.reversed-checkbox input.checkbox-onoff[type="checkbox"]:checked { +input.checkbox-onoff.reversed-checkbox[type="checkbox"]:checked { background: var(--color-toolkit-checkbox-onoff-off-background); &::before { @@ -440,7 +440,7 @@ input.checkbox-onoff[type="checkbox"], } input.checkbox-onoff[type="checkbox"]:checked, -.reversed-checkbox input.checkbox-onoff[type="checkbox"] { +input.checkbox-onoff.reversed-checkbox[type="checkbox"] { background: var(--color-toolkit-checkbox-onoff-on-background); &::before { diff --git a/searx/templates/simple/macros.html b/searx/templates/simple/macros.html index d9af3fbbb..7e3c05e5d 100644 --- a/searx/templates/simple/macros.html +++ b/searx/templates/simple/macros.html @@ -52,33 +52,12 @@ {%- endmacro -%} - -{%- macro tabs_open() -%} -
-{%- endmacro -%} - -{%- macro tab_header(name, id, label, checked) -%} - - -
-{%- endmacro -%} - -{%- macro tab_footer() -%} -
-{%- endmacro -%} - -{%- macro tabs_close() -%} -
-{%- endmacro -%} - + {%- macro checkbox_onoff(name, checked) -%} - -{%- endmacro -%} - -{%- macro checkbox(name, checked, disabled) -%} -{%- if checked == '?' -%} - {{- icon_small('warning') -}} -{%- else -%} - -{%- endif -%} + {%- endmacro -%} diff --git a/searx/templates/simple/page_with_header.html b/searx/templates/simple/page_with_header.html index d4466b612..719553a38 100644 --- a/searx/templates/simple/page_with_header.html +++ b/searx/templates/simple/page_with_header.html @@ -1,5 +1,7 @@ -{% set body_class = "page_with_header" %} -{% extends "simple/base.html" %} -{% block header %} - -{% endblock %} +{%- set body_class = "page_with_header" -%} +{%- extends "simple/base.html" -%} +{%- block header -%} + {{- '' -}} + {{- '' -}} + {{- '' -}} +{%- endblock -%} diff --git a/searx/templates/simple/preferences.html b/searx/templates/simple/preferences.html index 3210a36b0..8bc89a118 100644 --- a/searx/templates/simple/preferences.html +++ b/searx/templates/simple/preferences.html @@ -1,7 +1,40 @@ -{% from 'simple/macros.html' import tabs_open, tabs_close, tab_header, tab_footer, checkbox_onoff, checkbox %} -{% from 'simple/icons.html' import icon_big %} +{%- from 'simple/icons.html' import icon_big -%} +{%- extends "simple/page_with_header.html" -%} -{% extends "simple/page_with_header.html" %} +{%- macro tabs_open() -%} +
+{%- endmacro -%} + +{%- macro tab_header(name, id, label, checked) -%} + + +
+{%- endmacro -%} + +{%- macro tab_footer() -%} +
+{%- endmacro -%} + +{%- macro tabs_close() -%} +
+{%- endmacro -%} + +{%- macro checkbox(name, checked, disabled) -%} + {%- if checked == '?' -%} + {{- icon_small('warning') -}} + {%- else -%} + + {%- endif -%} +{%- endmacro -%} + +{%- macro checkbox_onoff_reversed(name, checked) -%} + +{%- endmacro -%} {%- macro plugin_preferences(section) -%} {%- for plugin in plugins -%} @@ -9,7 +42,7 @@
{{- '' -}} {{ _(plugin.name) }}{{- '' -}}
- {{- checkbox_onoff('plugin_' + plugin.id, plugin.id not in allowed_plugins) -}} + {{- checkbox_onoff_reversed('plugin_' + plugin.id, plugin.id not in allowed_plugins) -}}
{{- '' -}}
{{- _(plugin.description) -}} @@ -19,427 +52,190 @@ {%- endfor -%} {%- endmacro -%} -{% macro engine_about(search_engine) -%} -{% if search_engine.about is defined %} -{% set about = search_engine.about %} - {%- endif -%} -{%- endmacro %} +{%- endmacro -%} {%- macro engine_time(engine_name) -%} -{{- "" -}} + {{- '' -}} {%- if stats[engine_name].time != None -%} - {{- stats[engine_name].time -}}{{- "" -}} + {{- stats[engine_name].time -}}{{- '' -}} {{- "" -}} -