From c0a5f35a007c65b2744915d85404b482d2ef6eee Mon Sep 17 00:00:00 2001 From: Veeck Date: Sat, 2 Sep 2023 22:18:57 +0200 Subject: [PATCH] Cleanup nunjuck templates (#3109) Ran a linter over it (djlint) which fixed intendation and a few errors --------- Co-authored-by: veeck --- CHANGELOG.md | 1 + modules/default/alert/templates/alert.njk | 26 ++++---- .../default/alert/templates/notification.njk | 8 +-- modules/default/helloworld/helloworld.njk | 2 +- modules/default/newsfeed/fullarticle.njk | 2 +- modules/default/newsfeed/newsfeed.njk | 64 +++++++++---------- modules/default/newsfeed/oldconfig.njk | 2 +- .../updatenotification/updatenotification.njk | 26 ++++---- modules/default/weather/current.njk | 36 +++++------ modules/default/weather/forecast.njk | 16 ++--- modules/default/weather/hourly.njk | 14 ++-- tests/e2e/modules/weather_current_spec.js | 2 +- 12 files changed, 95 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f859dd48..965c012a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ _This release is scheduled to be released on 2023-10-01._ - Replace pretty-quick by lint-staged () - Update engine node >=18. v16 reached it's end of life. (#3170) - Update typescript definition for modules +- Cleaned up nunjuck templates ### Fixed diff --git a/modules/default/alert/templates/alert.njk b/modules/default/alert/templates/alert.njk index 7349a7ae..b7db3a4d 100644 --- a/modules/default/alert/templates/alert.njk +++ b/modules/default/alert/templates/alert.njk @@ -1,18 +1,20 @@ {% if imageUrl or imageFA %} - {% set imageHeight = imageHeight if imageHeight else "80px" %} - {% if imageUrl %} - - {% else %} - - {% endif %} -
+ {% set imageHeight = imageHeight if imageHeight else "80px" %} + {% if imageUrl %} + + {% else %} + + {% endif %} +
{% endif %} {% if title %} - {{ title if titleType == 'text' else title | safe }} + {{ title if titleType == 'text' else title | safe }} {% endif %} {% if message %} - {% if title %} -
- {% endif %} - {{ message if messageType == 'text' else message | safe }} + {% if title %}
{% endif %} + {{ message if messageType == 'text' else message | safe }} {% endif %} diff --git a/modules/default/alert/templates/notification.njk b/modules/default/alert/templates/notification.njk index 1594ad48..0de6908b 100644 --- a/modules/default/alert/templates/notification.njk +++ b/modules/default/alert/templates/notification.njk @@ -1,9 +1,7 @@ {% if title %} - {{ title if titleType == 'text' else title | safe }} + {{ title if titleType == 'text' else title | safe }} {% endif %} {% if message %} - {% if title %} -
- {% endif %} - {{ message if messageType == 'text' else message | safe }} + {% if title %}
{% endif %} + {{ message if messageType == 'text' else message | safe }} {% endif %} diff --git a/modules/default/helloworld/helloworld.njk b/modules/default/helloworld/helloworld.njk index 005ca28e..05e5edd3 100644 --- a/modules/default/helloworld/helloworld.njk +++ b/modules/default/helloworld/helloworld.njk @@ -2,4 +2,4 @@ Use ` | safe` to allow html tages within the text string. https://mozilla.github.io/nunjucks/templating.html#autoescaping --> -
{{text | safe}}
+
{{ text | safe }}
diff --git a/modules/default/newsfeed/fullarticle.njk b/modules/default/newsfeed/fullarticle.njk index 6570396e..0be4b042 100644 --- a/modules/default/newsfeed/fullarticle.njk +++ b/modules/default/newsfeed/fullarticle.njk @@ -1,3 +1,3 @@
-
\ No newline at end of file + diff --git a/modules/default/newsfeed/newsfeed.njk b/modules/default/newsfeed/newsfeed.njk index 9e7e9d78..5bdfe2cd 100644 --- a/modules/default/newsfeed/newsfeed.njk +++ b/modules/default/newsfeed/newsfeed.njk @@ -1,27 +1,31 @@ {% macro escapeText(text, dangerouslyDisableAutoEscaping=false) %} - {% if dangerouslyDisableAutoEscaping %} - {{ text | safe}} - {% else %} - {{ text }} - {% endif %} + {% if dangerouslyDisableAutoEscaping -%} + {{ text | safe }} + {%- else -%} + {{ text }} + {%- endif %} {% endmacro %} - {% macro escapeTitle(title, url, dangerouslyDisableAutoEscaping=false, showTitleAsUrl=false) %} - {% if dangerouslyDisableAutoEscaping %} - {% if showTitleAsUrl %} - {{ title | safe }} + {% if dangerouslyDisableAutoEscaping %} + {% if showTitleAsUrl %} + {{ title | safe }} + {% else %} + {{ title | safe }} + {% endif %} {% else %} - {{ title | safe}} + {% if showTitleAsUrl %} + {{ title }} + {% else %} + {{ title }} + {% endif %} {% endif %} - {% else %} - {% if showTitleAsUrl %} - {{ title }} - {% else %} - {{ title }} - {% endif %} - {% endif %} {% endmacro %} - {% if loaded %} {% if config.showAsList %}
    @@ -30,11 +34,9 @@ {% if (config.showSourceTitle and item.sourceTitle) or config.showPublishDate %}
    {% if item.sourceTitle and config.showSourceTitle %} - {{ item.sourceTitle }}{% if config.showPublishDate %}, {% else %}: {% endif %} - {% endif %} - {% if config.showPublishDate %} - {{ item.publishDate }}: + {{ item.sourceTitle }}{% if config.showPublishDate %}, {% else %}:{% endif %} {% endif %} + {% if config.showPublishDate %}{{ item.publishDate }}:{% endif %}
    {% endif %}
    @@ -43,7 +45,7 @@ {% if config.showDescription %}
    {% if config.truncDescription %} - {{ escapeText(item.description | truncate(config.lengthDescription), config.dangerouslyDisableAutoEscaping) }} + {{ escapeText(item.description | truncate(config.lengthDescription) , config.dangerouslyDisableAutoEscaping) }} {% else %} {{ escapeText(item.description, config.dangerouslyDisableAutoEscaping) }} {% endif %} @@ -57,11 +59,9 @@ {% if (config.showSourceTitle and sourceTitle) or config.showPublishDate %}
    {% if sourceTitle and config.showSourceTitle %} - {{ escapeText(sourceTitle, config.dangerouslyDisableAutoEscaping) }}{% if config.showPublishDate %}, {% else %}: {% endif %} - {% endif %} - {% if config.showPublishDate %} - {{ publishDate }}: + {{ escapeText(sourceTitle, config.dangerouslyDisableAutoEscaping) }}{% if config.showPublishDate %}, {% else %}:{% endif %} {% endif %} + {% if config.showPublishDate %}{{ publishDate }}:{% endif %}
    {% endif %}
    @@ -70,7 +70,7 @@ {% if config.showDescription %}
    {% if config.truncDescription %} - {{ escapeText(description | truncate(config.lengthDescription), config.dangerouslyDisableAutoEscaping) }} + {{ escapeText(description | truncate(config.lengthDescription) , config.dangerouslyDisableAutoEscaping) }} {% else %} {{ escapeText(description, config.dangerouslyDisableAutoEscaping) }} {% endif %} @@ -79,15 +79,11 @@
    {% endif %} {% elseif empty %} -
    - {{ "NEWSFEED_NO_ITEMS" | translate | safe }} -
    +
    {{ "NEWSFEED_NO_ITEMS" | translate | safe }}
    {% elseif error %}
    {{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Newsfeed", ERROR: error}) | safe }}
    {% else %} -
    - {{ "LOADING" | translate | safe }} -
    +
    {{ "LOADING" | translate | safe }}
    {% endif %} diff --git a/modules/default/newsfeed/oldconfig.njk b/modules/default/newsfeed/oldconfig.njk index db0f8d4b..0e3b9b5d 100644 --- a/modules/default/newsfeed/oldconfig.njk +++ b/modules/default/newsfeed/oldconfig.njk @@ -1,3 +1,3 @@
    {{ "MODULE_CONFIG_CHANGED" | translate({MODULE_NAME: "Newsfeed"}) | safe }} -
    \ No newline at end of file +
    diff --git a/modules/default/updatenotification/updatenotification.njk b/modules/default/updatenotification/updatenotification.njk index 77d79754..415688d6 100644 --- a/modules/default/updatenotification/updatenotification.njk +++ b/modules/default/updatenotification/updatenotification.njk @@ -1,15 +1,15 @@ {% if not suspended %} - {% for name, status in moduleList %} -
    - - - {% set mainTextLabel = "UPDATE_NOTIFICATION" if name === "MagicMirror" else "UPDATE_NOTIFICATION_MODULE" %} - {{ mainTextLabel | translate({MODULE_NAME: name}) }} - -
    -
    - {% set subTextLabel = "UPDATE_INFO_SINGLE" if status.behind === 1 else "UPDATE_INFO_MULTIPLE" %} - {{ subTextLabel | translate({COMMIT_COUNT: status.behind, BRANCH_NAME: status.current}) | diffLink(status) | safe }} -
    - {% endfor %} + {% for name, status in moduleList %} +
    + + + {% set mainTextLabel = "UPDATE_NOTIFICATION" if name === "MagicMirror" else "UPDATE_NOTIFICATION_MODULE" %} + {{ mainTextLabel | translate({MODULE_NAME: name}) }} + +
    +
    + {% set subTextLabel = "UPDATE_INFO_SINGLE" if status.behind === 1 else "UPDATE_INFO_MULTIPLE" %} + {{ subTextLabel | translate({COMMIT_COUNT: status.behind, BRANCH_NAME: status.current}) | diffLink(status) | safe }} +
    + {% endfor %} {% endif %} diff --git a/modules/default/weather/current.njk b/modules/default/weather/current.njk index 09781db7..e2fa2f51 100644 --- a/modules/default/weather/current.njk +++ b/modules/default/weather/current.njk @@ -7,7 +7,8 @@ {% if config.showWindDirection %} {% if config.showWindDirectionAsArrow %} - + {% else %} {{ current.cardinalWindDirection() | translate }} {% endif %} @@ -29,34 +30,28 @@ {% endif %} {% if config.showUVIndex %} - +
    - {{ current.uv_index }} - + {{ current.uv_index }} + {% endif %}
    {% endif %}
    - - - {{ current.temperature | roundValue | unit("temperature") | decimalSymbol }} - + + {{ current.temperature | roundValue | unit("temperature") | decimalSymbol }}
    {% if config.showIndoorTemperature and indoor.temperature %}
    - - {{ indoor.temperature | roundValue | unit("temperature") | decimalSymbol }} - + {{ indoor.temperature | roundValue | unit("temperature") | decimalSymbol }}
    {% endif %} {% if config.showIndoorHumidity and indoor.humidity %}
    - - {{ indoor.humidity | roundValue | unit("humidity") | decimalSymbol }} - + {{ indoor.humidity | roundValue | unit("humidity") | decimalSymbol }}
    {% endif %}
    @@ -65,14 +60,16 @@ {% if config.showFeelsLike %} {{ "FEELS" | translate({DEGREE: current.feelsLike() | roundValue | unit("temperature") | decimalSymbol }) }} -
    + +
    {% endif %} {% if config.showPrecipitationAmount and current.precipitationAmount %} {{ "PRECIP_AMOUNT" | translate }} {{ current.precipitationAmount | unit("precip", current.precipitationUnits) }} -
    + +
    {% endif %} - {% if config.showPrecipitationProbability and current.precipitationProbability %} + {% if config.showPrecipitationProbability and current.precipitationProbability %} {{ "PRECIP_POP" | translate }} {{ current.precipitationProbability }}% @@ -80,10 +77,7 @@
    {% endif %} {% else %} -
    - {{ "LOADING" | translate }} -
    +
    {{ "LOADING" | translate }}
    {% endif %} - diff --git a/modules/default/weather/forecast.njk b/modules/default/weather/forecast.njk index af5825e3..85570fbb 100644 --- a/modules/default/weather/forecast.njk +++ b/modules/default/weather/forecast.njk @@ -7,15 +7,18 @@ {% endif %} {% set forecast = forecast.slice(0, numSteps) %} {% for f in forecast %} - + {% if (currentStep == 0) and config.ignoreToday == false and config.absoluteDates == false %} {{ "TODAY" | translate }} {% elif (currentStep == 1) and config.ignoreToday == false and config.absoluteDates == false %} {{ "TOMORROW" | translate }} {% else %} - {{ f.date.format('ddd') }} + {{ f.date.format("ddd") }} {% endif %} - + + + {{ f.maxTemperature | roundValue | unit("temperature") | decimalSymbol }} @@ -29,7 +32,7 @@ {% endif %} {% if config.showPrecipitationProbability %} - {{ f.precipitationProbability | unit("precip", "%") }} + {{ f.precipitationProbability | unit('precip', '%') }} {% endif %} {% if config.showUVIndex %} @@ -43,10 +46,7 @@ {% endfor %} {% else %} -
    - {{ "LOADING" | translate }} -
    +
    {{ "LOADING" | translate }}
    {% endif %} - diff --git a/modules/default/weather/hourly.njk b/modules/default/weather/hourly.njk index 51fb67d5..0e464f77 100644 --- a/modules/default/weather/hourly.njk +++ b/modules/default/weather/hourly.njk @@ -4,9 +4,12 @@ {% set hours = hourly.slice(0, numSteps) %} {% for hour in hours %} - + - + @@ -25,7 +28,7 @@ {% endif %} {% if config.showPrecipitationProbability %} {% endif %} @@ -33,10 +36,7 @@ {% endfor %}
    {{ hour.date | formatTime }} + + {{ hour.temperature | roundValue | unit("temperature") }} - {{ hour.precipitationProbability | unit("precip", "%") }} + {{ hour.precipitationProbability | unit('precip', '%') }}
    {% else %} -
    - {{ "LOADING" | translate }} -
    +
    {{ "LOADING" | translate }}
    {% endif %} - diff --git a/tests/e2e/modules/weather_current_spec.js b/tests/e2e/modules/weather_current_spec.js index 6cea8e15..592b3735 100644 --- a/tests/e2e/modules/weather_current_spec.js +++ b/tests/e2e/modules/weather_current_spec.js @@ -48,7 +48,7 @@ describe("Weather module", () => { it("should render windDirection with an arrow", async () => { const elem = await helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-down"); expect(elem).not.toBe(null); - expect(elem.outerHTML).toContain("transform:rotate(250deg);"); + expect(elem.outerHTML).toContain("transform:rotate(250deg)"); }); it("should render humidity", async () => {