@gov-cy/dsf-email-templates 2.0.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [v2.1.0] - 2025-04-08
9
+
10
+ ### Added
11
+ - `bodyKeyValue` component
12
+
13
+ ## [v2.0.5] - 2025-04-05
14
+
15
+ ### Changed
16
+ - Fix vulnerability issue
17
+
8
18
  ## [v2.0.4] - 2024-07-24
9
19
 
10
20
  ### Changed
package/README.md CHANGED
@@ -28,6 +28,11 @@ Compatibility with clients based on mailtrap test on 2024-04-10
28
28
  | Yahoo Mail | 100% | 80% | 80% |
29
29
  | Other | 100% | 89% | 89% |
30
30
 
31
+ Though the project is not intended to be used for production purposes and does provide any guaranties, your welcome to try it.
32
+
33
+ > [!WARNING]
34
+ > The project allows you to input un-escaped HTML in your emails, so use it with care.
35
+
31
36
  ## Features
32
37
 
33
38
  `DSF-email-templates` can:
@@ -285,6 +290,28 @@ Usage example:
285
290
  ```
286
291
  </details>
287
292
 
293
+ <details>
294
+ <summary>bodyKeyValue</summary>
295
+
296
+ Returns govcy an ordered or un-ordered list with key and value. It should be used in the `body` block.
297
+
298
+ **Parameters**
299
+ - {string} `type` The list type. Optional, default is 'ul'. Can be 'ul', 'ol'
300
+ - {array} `items` The array of items to turn onto list items.
301
+ i.e. items:
302
+ [
303
+ {key:'key1', value:'value 1'},
304
+ {key:'key2', value:'value 2'}
305
+ ]
306
+ - {string} `lang` The language used. Can be 'en','el'. Optional.
307
+
308
+ Usage example:
309
+
310
+ ```njk
311
+ {{ govcyEmailElement ('bodyKeyValue',{type:'ul', items: [ {key:'key1', value:'value 1'}, {key:'key2', value:'value 2'} ]}) }}
312
+ ```
313
+ </details>
314
+
288
315
  ---------
289
316
 
290
317
  Here's a complete example of a nunjucks template using DSF assets:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gov-cy/dsf-email-templates",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "description": "This project can be used to produce html email templates to be used by DSF.",
5
5
  "author": "DMRID - DSF Team",
6
6
  "license": "MIT",
@@ -0,0 +1,34 @@
1
+ {# body key value list
2
+ @param {string} type The list type. Optional, default is 'ul'. Can be 'ul', 'ol'
3
+ @param {array} items The array of items to turn onto list items.
4
+ i.e. items:
5
+ [
6
+ {key:'key1', value:'value 1'},
7
+ {key:'key2', value:'value 2'}
8
+ ]
9
+ @param {string} lang The language used. Can be 'en','el'. Optional.
10
+ @returns govcy body key value list for emails html
11
+ #}
12
+ {% macro gocvyEmailBodyKeyValue(params) -%}
13
+ {%- from "./bodyParagraph.njk" import gocvyEmailBodyParagraph -%}
14
+ {#- set default values -#}
15
+ {%- set type = params.type | default('ul') -%}
16
+ {# depending on the heading level set the font-size #}
17
+ {%- if type == 'ol' -%}
18
+ {%- set openHTML = '<ol style="margin:0; margin-left: 16px; padding:0; line-height:22px;" align="left">' -%}
19
+ {%- set closeHTML = '</ol>' -%}
20
+ {%- else -%}
21
+ {%- set openHTML = '<ul style="margin:0; margin-left: 16px; padding:0; line-height:22px;" align="left" type="disc">' -%}
22
+ {%- set closeHTML = '</ul>' -%}
23
+ {%- endif -%}
24
+ {% call gocvyEmailBodyParagraph({lang:params.lang}) %}
25
+ {{ openHTML | safe }}
26
+ {# for each item render list item #}
27
+ {%- for item in params.items -%}
28
+ {%- if item -%}
29
+ <li><b>{{ item.key }}:</b> {{ item.value }}</li>
30
+ {%- endif -%}
31
+ {%- endfor -%}
32
+ {{ closeHTML | safe }}
33
+ {% endcall %}
34
+ {%- endmacro %}
@@ -15,6 +15,10 @@
15
15
  {%- elif component == 'bodyList' -%}
16
16
  {%- from "./components/bodyList.njk" import gocvyEmailBodyList -%}
17
17
  {{ gocvyEmailBodyList(params) }}
18
+ {#- bodyKeyValue -#}
19
+ {%- elif component == 'bodyKeyValue' -%}
20
+ {%- from "./components/bodyKeyValue.njk" import gocvyEmailBodyKeyValue -%}
21
+ {{ gocvyEmailBodyKeyValue(params) }}
18
22
  {#- footer -#}
19
23
  {%- elif component == 'footer' -%}
20
24
  {%- from "./components/footer.njk" import gocvyEmailFooter -%}
@@ -56,6 +56,7 @@
56
56
  {%- endcall %}
57
57
  {{ govcyEmailElement ('bodyList',{type:'ol', items: ["xero -", "go", "kouvente"]}) }}
58
58
  {{ govcyEmailElement ('bodyList',{type:'ul', items: ['<a href="#">xero</a>', "go", "kouvente"]}) }}
59
+ {{ govcyEmailElement ('bodyKeyValue',{type:'ul', items: [ {key:'key1', value:'value 1'}, {key:'key2', value:'value 2'} ]}) }}
59
60
  {%- endcall%}
60
61
  {%- endblock %}
61
62
  {# footer block #}
@@ -23,6 +23,7 @@ describe('1. Testing `DSFEmailRenderer.renderFromString`, use of `govcyBase.njk`
23
23
  {% call govcyEmailElement('bodyHeading',{headingLevel:4}) -%}Heading 4{%- endcall %}
24
24
  {{ govcyEmailElement ('bodyList',{type:'ol', items: ["item 1", "item 2", "item 3"]}) }}
25
25
  {{ govcyEmailElement ('bodyList',{type:'ul', items: ["item 1", "item 2", "item 3"]}) }}
26
+ {{ govcyEmailElement ('bodyKeyValue',{type:'ul', items: [ {key:'key1', value:'value 1'}, {key:'key2', value:'value 2'} ]}) }}
26
27
  {% endcall %}
27
28
  {% endblock %}
28
29
  {% block footer -%}
@@ -49,6 +50,7 @@ describe('2. Testing `DSFEmailRenderer.renderFromJson`', () => {
49
50
  {"component": "bodyHeading",params: {"headingLevel":4},body:"Heading 4"},
50
51
  {"component": "bodyList", params:{type:'ol', items: ["item 1", "item 2", "item 3"]}},
51
52
  {"component": "bodyList", params:{type:'ul', items: ["item 1", "item 2", "item 3"]}},
53
+ {"component": "bodyKeyValue", params:{type:'ul', items: [{key:'key1', value:'value 1'}, {key:'key2', value:'value 2'} ]}},
52
54
  ],
53
55
  footer: {
54
56
  footerText: "Name of service"
@@ -186,5 +188,11 @@ function renderChecks(renderedHTML, checksNum){
186
188
  expectedRegex = /<body>([\s\S]*?)<ul([\s\S]*?)>\s*<li>([\s\S]*?)item 1\s*<\/li>\s*<li>([\s\S]*?)item 2\s*<\/li>\s*<li>([\s\S]*?)item 3\s*<\/li>\s*<\/ul>/;
187
189
  expect(renderedHTML).to.match(expectedRegex);
188
190
  })
191
+ //check for bodyKeyValue.njk macro render as expected
192
+ it(checksNum+'13 `bodyKeyValue` macro render as expected', async () => {
193
+ //check for structure of `ol` block
194
+ let expectedRegex = /<body>([\s\S]*?)<ul([\s\S]*?)>\s*<li>\s*<b>\s*key1:<\/b> value 1\s*<\/li>\s*<li>\s*<b>\s*key2:<\/b> value 2\s*<\/li>\s*<\/ul>/;
195
+ expect(renderedHTML).to.match(expectedRegex);
196
+ })
189
197
 
190
198
  }