From 3b390858ff8b92f45f3c4adedc7dfe30df07e8ea Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Tue, 8 Aug 2023 10:48:36 +0200 Subject: [PATCH] Use macros for html generation instead of variables --- .../corpora/_analysis/concordance.html.j2 | 291 +++++++++--------- .../corpora/_analysis/reader.html.j2 | 139 ++++----- .../corpora/_analysis/template.html.j2 | 18 +- app/templates/corpora/analysis.html.j2 | 36 ++- 4 files changed, 234 insertions(+), 250 deletions(-) diff --git a/app/templates/corpora/_analysis/concordance.html.j2 b/app/templates/corpora/_analysis/concordance.html.j2 index 7fe1c6a6..a26c1a9a 100644 --- a/app/templates/corpora/_analysis/concordance.html.j2 +++ b/app/templates/corpora/_analysis/concordance.html.j2 @@ -2,168 +2,156 @@ {% import 'corpora/_analysis/query_builder/_query_builder.html.j2' as query_builder with context %} +{% set icon = 'list_alt' %} {% set name = 'Concordance' %} +{% set description = 'Query your corpus with the CQP query language utilizing a KWIC view.' %} -{% set description %} -Query your corpus with the CQP query language utilizing a KWIC view. -{% endset %} -{% set id_prefix = name.lower().replace(' ', '-') + '-extension' %} - -{% set tab_content %} -list_alt{{ name }} -{% endset %} - -{% set container_content %} -
-
-
-
-
-
- Query -
-
-
- -
-
-
-
- {{ expert_mode.card_content(id_prefix) }} -
-
- {# {{ query_builder.card_content(id_prefix) }} #} -
-
-
- search - {# #} -
- {# #} - - help Corpus Query Language tutorial - | - info Tagsets -
-
- arrow_forward - - -
-
-

Preview:

-

-
-
-
-
Use the following options to build your query.
-

- Add new token to your query - Add structural attributes to your query -
-
-

 

- -
-
-
+{% macro container_element(id_prefix) %} +
+
+
+
+ Query +
+
+
+
-
- -
-
- -
-
- Results -

-
-
-
-
-
-
-
-
-
- short_text - - -
-
- format_list_numbered - - -
-
- format_shapes - - -
-
- format_quote - - -
-
-
+
+ {{ expert_mode.card_content(id_prefix) }} +
+
+ {# {{ query_builder.card_content(id_prefix) }} #} +
+ +
+ search + {# #} +
+ {# #} + + help Corpus Query Language tutorial + | + info Tagsets +
+
+ arrow_forward + + +
+
+

Preview:

+

+
+
+
+
Use the following options to build your query.
+

+ Add new token to your query + Add structural attributes to your query +
+
+

 

+
-
-

-
-
- - - - - - - - - - - - -
SourceLeft contextKWICRight Context
-
    -{% endset %} -{% set modals %} +
    + +
    +
    + Results +

    +
    +
    +
    +
    +
    +
    +
    +
    +
    + short_text + + +
    +
    + format_list_numbered + + +
    +
    + format_shapes + + +
    +
    + format_quote + + +
    +
    +
    +
    +
    +
    +

    +
    +
    + + + + + + + + + + + + +
    SourceLeft contextKWICRight Context
    +
      +
      +
      +{% endmacro %} + +{# The extension modals #} +{% macro modals(id_prefix) %}
      -{% endset %} +{% endmacro %} -{% set scripts %} +{# The extension scripts #} +{% macro scripts(id_prefix) %} -{% endset %} +{% endmacro %} diff --git a/app/templates/corpora/_analysis/template.html.j2 b/app/templates/corpora/_analysis/template.html.j2 index 00565b16..b55ca772 100644 --- a/app/templates/corpora/_analysis/template.html.j2 +++ b/app/templates/corpora/_analysis/template.html.j2 @@ -1,3 +1,5 @@ +{# The extension icon #} +{% set icon = '' %} {# The extension name #} {% set name = '' %} @@ -5,22 +7,12 @@ {# The extension description #} {% set description = '' %} -{# - The extension id prefix, used for related HTML elements with an id. - The prefix is used to avoid id conflicts with other extensions. - Reserved ids (do not use): - - -extension-container -#} -{% set id_prefix = name.lower().replace(' ', '-') + '-extension' %} - -{# The extension tab content #} -{% set tab_content = name %} {# The extension container content #} -{% set container_content = '' %} +{% macro container_content(id_prefix) %}{% endmacro %} {# The extension modals #} -{% set modals = '' %} +{% macro modals(id_prefix) %}{% endmacro %} {# The extension scripts #} -{% set scripts = '' %} +{% macro scripts(id_prefix) %}{% endmacro %} diff --git a/app/templates/corpora/analysis.html.j2 b/app/templates/corpora/analysis.html.j2 index 046fa161..4c43552a 100644 --- a/app/templates/corpora/analysis.html.j2 +++ b/app/templates/corpora/analysis.html.j2 @@ -4,16 +4,25 @@ {% import 'corpora/_analysis/reader.html.j2' as reader_extension %} {% import 'corpora/_analysis/static_visualization.html.j2' as static_visualization_extension %} -{% set extensions = [concordance_extension, reader_extension, static_visualization_extension] %} -{% block main_attribs %} class="service-scheme" data-service="corpus-analysis" id="corpus-analysis-app-container"{% endblock main_attribs %} +{% set extensions = + { + 'concordance-extension': concordance_extension, + 'reader-extension': reader_extension, + 'static-visualizations-extension': static_visualization_extension + } +%} +{% block main_attribs %} class="service-scheme" data-service="corpus-analysis" id="corpus-analysis-app-container"{% endblock main_attribs %} + {% block page_content %} @@ -21,9 +30,9 @@

      {{ title }}

      - {% for extension in extensions if extension.name != 'Static Visualization (beta)' %} + {% for id, extension in extensions.items() if extension.name != 'Static Visualization (beta)' %}
      -
      +
      {{ extension.name }}

      {{ extension.description }}

      @@ -37,9 +46,9 @@
      -{% for extension in extensions if extension.name != 'Static Visualization (beta)' %} -
      - {{ extension.container_content }} +{% for id, extension in extensions.items() if extension.name != 'Static Visualization (beta)' %} +
      + {{ extension.container_content(id) }}
      {% endfor %} {% endblock page_content %} @@ -61,10 +70,9 @@
      -{% for extension in extensions %} -{{ extension.modals }} +{% for id, extension in extensions.items() %} +{{ extension.modals(id) }} {% endfor %} - {% endblock modals %} {% block scripts %} @@ -73,8 +81,8 @@ const corpusAnalysisApp = new CorpusAnalysisApp({{ corpus.hashid|tojson }}); -{% for extension in extensions %} -{{ extension.scripts }} +{% for id, extension in extensions.items() %} +{{ extension.scripts(id) }} {% endfor %}