vite-plugin-twig-drupal 1.5.0 → 1.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-twig-drupal",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Provides a ⚡️ Vite plugin to transform 🌱 Twig into HTML with a 💧 Drupal flavour",
5
5
  "keywords": [
6
6
  "Vite",
package/src/index.js CHANGED
@@ -260,8 +260,13 @@ const plugin = (options = {}) => {
260
260
  const component = ${code}
261
261
  ${includes ? `component.options.allowInlineIncludes = true;` : ""}
262
262
  try {
263
+ let defaultAttributes = context.defaultAttributes ? context.defaultAttributes : [];
264
+ if (!Array.isArray(defaultAttributes)) {
265
+ // We were passed a map, turn it into an array.
266
+ defaultAttributes = Object.entries(defaultAttributes);
267
+ }
263
268
  return frameworkTransform(component.render({
264
- attributes: new DrupalAttribute(),
269
+ attributes: new DrupalAttribute(defaultAttributes),
265
270
  ...${JSON.stringify(options.globalContext)},
266
271
  ...context
267
272
  }));
@@ -1,10 +1,92 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
+ exports[`Basic smoke test > Should cast default attributes to attributes 1`] = `
4
+ "<section>
5
+ <h1>Include</h1>
6
+ <article>
7
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. At dignissimos fugiat inventore laborum maiores molestiae neque quia quo unde veniam?
8
+ </article>
9
+ </section>
10
+ <section>
11
+ <h1>Embed</h1>
12
+ <article>
13
+ Lorem ipsum dolor sit amet.
14
+ <button class=\\"button--primary\\">Nested include</button>
15
+ IT WORKS!
16
+ </article>
17
+ </section>
18
+ <section>
19
+ <h1></h1>
20
+ <article>
21
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. At dignissimos fugiat inventore laborum maiores molestiae neque quia quo unde veniam?
22
+ </article>
23
+ </section>
24
+ <section>
25
+ <h1>Relative include</h1>
26
+ <article>
27
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. At dignissimos fugiat inventore laborum maiores molestiae neque quia quo unde veniam?
28
+ </article>
29
+ </section>
30
+ <h2>SDC</h2>
31
+ <p>Card</p>
32
+ <div>atom badge from nested dir 🙌</div>
33
+ <button>nested button 🙌</button>
34
+ <button>SDC</button>
35
+ <button>included button 👈️</button>
36
+ <h2>Include card</h2>
37
+ <p>🏆️ winning</p>
38
+ <div>atom badge from nested dir 🙌</div>
39
+ <button>nested button 🙌</button>
40
+ <div class=\\"ponies\\">hey there</div>
41
+ "
42
+ `;
43
+
3
44
  exports[`Basic smoke test > Should recognise default Drupal functions 1`] = `
4
45
  "
5
46
  <p>Functions work</p>"
6
47
  `;
7
48
 
49
+ exports[`Basic smoke test > Should support default attributes as a map 1`] = `
50
+ "<section>
51
+ <h1>Include</h1>
52
+ <article>
53
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. At dignissimos fugiat inventore laborum maiores molestiae neque quia quo unde veniam?
54
+ </article>
55
+ </section>
56
+ <section>
57
+ <h1>Embed</h1>
58
+ <article>
59
+ Lorem ipsum dolor sit amet.
60
+ <button class=\\"button--primary\\">Nested include</button>
61
+ IT WORKS!
62
+ </article>
63
+ </section>
64
+ <section>
65
+ <h1></h1>
66
+ <article>
67
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. At dignissimos fugiat inventore laborum maiores molestiae neque quia quo unde veniam?
68
+ </article>
69
+ </section>
70
+ <section>
71
+ <h1>Relative include</h1>
72
+ <article>
73
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. At dignissimos fugiat inventore laborum maiores molestiae neque quia quo unde veniam?
74
+ </article>
75
+ </section>
76
+ <h2>SDC</h2>
77
+ <p>Card</p>
78
+ <div>atom badge from nested dir 🙌</div>
79
+ <button>nested button 🙌</button>
80
+ <button>SDC</button>
81
+ <button>included button 👈️</button>
82
+ <h2>Include card</h2>
83
+ <p>🏆️ winning</p>
84
+ <div>atom badge from nested dir 🙌</div>
85
+ <button>nested button 🙌</button>
86
+ <div class=\\"ponies\\">hey there</div>
87
+ "
88
+ `;
89
+
8
90
  exports[`Basic smoke test > Should support global context and functions 1`] = `
9
91
  "<section>
10
92
  <h1>Include</h1>
@@ -42,6 +124,7 @@ exports[`Basic smoke test > Should support global context and functions 1`] = `
42
124
  <p>🏆️ winning</p>
43
125
  <div>atom badge from nested dir 🙌</div>
44
126
  <button>nested button 🙌</button>
127
+ <div >hey there</div>
45
128
  "
46
129
  `;
47
130
 
@@ -82,6 +165,7 @@ exports[`Basic smoke test > Should support includes 1`] = `
82
165
  <p>🏆️ winning</p>
83
166
  <div>atom badge from nested dir 🙌</div>
84
167
  <button>nested button 🙌</button>
168
+ <div >hey there</div>
85
169
  "
86
170
  `;
87
171
 
@@ -139,6 +223,7 @@ exports[`Basic smoke test > Should support nested SDC 1`] = `
139
223
  <p>🏆️ winning</p>
140
224
  <div>atom badge from nested dir 🙌</div>
141
225
  <button>nested button 🙌</button>
226
+ <div >hey there</div>
142
227
  "
143
228
  `;
144
229
 
@@ -179,5 +264,6 @@ exports[`Basic smoke test > Should support variables 1`] = `
179
264
  <p>🏆️ winning</p>
180
265
  <div>atom badge from nested dir 🙌</div>
181
266
  <button>nested button 🙌</button>
267
+ <div >hey there</div>
182
268
  "
183
269
  `;
@@ -26,3 +26,4 @@
26
26
  title: 'Include card',
27
27
  teaser: '🏆️ winning',
28
28
  } %}
29
+ <div {{ attributes }}>hey there</div>
@@ -49,4 +49,22 @@ describe("Basic smoke test", () => {
49
49
  expect(markup).toMatchSnapshot()
50
50
  expect(markup).toContain("Functions work")
51
51
  })
52
+ it("Should cast default attributes to attributes", () => {
53
+ const markup = Markup({
54
+ defaultAttributes: [["class", ["ponies"]]],
55
+ })
56
+ expect(markup).toMatchSnapshot()
57
+ expect(markup).toContain('class="ponies"')
58
+ expect(markup).toContain("hey there")
59
+ })
60
+ it("Should support default attributes as a map", () => {
61
+ const markup = Markup({
62
+ defaultAttributes: {
63
+ class: ["ponies"],
64
+ },
65
+ })
66
+ expect(markup).toMatchSnapshot()
67
+ expect(markup).toContain('class="ponies"')
68
+ expect(markup).toContain("hey there")
69
+ })
52
70
  })