vite-plugin-twig-drupal 1.0.1 → 1.0.2

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.0.1",
3
+ "version": "1.0.2",
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
@@ -18,6 +18,7 @@ const includeTokenTypes = [
18
18
  "Twig.logic.type.embed",
19
19
  "Twig.logic.type.include",
20
20
  "Twig.logic.type.extends",
21
+ "Twig.logic.type.import",
21
22
  ]
22
23
 
23
24
  const pluckIncludes = (tokens) => {
@@ -136,6 +137,7 @@ const plugin = (options = {}) => {
136
137
  }
137
138
  includes.forEach(processIncludes)
138
139
  embed = includes
140
+ .filter((template) => template !== "_self")
139
141
  .map(
140
142
  (template) =>
141
143
  `import '${resolve(
@@ -23,6 +23,23 @@ exports[`Basic smoke test > Should support includes 1`] = `
23
23
  "
24
24
  `;
25
25
 
26
+ exports[`Basic smoke test > Should support macros 1`] = `
27
+ "<ul>
28
+ <li><a href=\\"/home\\">Home</a>
29
+ </li>
30
+
31
+ <li><a href=\\"/about\\">About</a>
32
+ <ul>
33
+ <li><a href=\\"/contact\\">Contact</a>
34
+ </li>
35
+
36
+ </ul>
37
+ </li>
38
+
39
+ </ul>
40
+ "
41
+ `;
42
+
26
43
  exports[`Basic smoke test > Should support variables 1`] = `
27
44
  "<section>
28
45
  <h1>Include</h1>
@@ -0,0 +1,12 @@
1
+ {% macro menu_link(title, href, children = []) %}
2
+ {% import _self as navigation %}
3
+ <li><a href="{{ href }}">{{ title }}</a>
4
+ {% if children|length %}
5
+ <ul>
6
+ {% for child in children %}
7
+ {{ navigation.menu_link(child.title, child.href) }}
8
+ {% endfor %}
9
+ </ul>
10
+ {% endif %}
11
+ </li>
12
+ {% endmacro %}
@@ -0,0 +1,7 @@
1
+ {% import "@tests/macro.twig" as navigation %}
2
+ <ul>
3
+ {{ navigation.menu_link('Home', '/home') }}
4
+ {{ navigation.menu_link('About', '/about', [
5
+ { title: 'Contact', href: '/contact'}
6
+ ]) }}
7
+ </ul>
@@ -1,6 +1,7 @@
1
1
  import Markup from "../dist/test.js"
2
2
  import Error from "../dist/error.js"
3
3
  import ErrorInclude from "../dist/errorInclude.js"
4
+ import Menu from "../dist/menu.js"
4
5
  import { describe, expect, it } from "vitest"
5
6
 
6
7
  describe("Basic smoke test", () => {
@@ -22,4 +23,9 @@ describe("Basic smoke test", () => {
22
23
  const error = ErrorInclude()
23
24
  expect(error).toContain("An error occurred")
24
25
  })
26
+ it("Should support macros", () => {
27
+ const markup = Menu()
28
+ expect(markup).toContain("Contact")
29
+ expect(markup).toMatchSnapshot()
30
+ })
25
31
  })
package/vite.config.js CHANGED
@@ -9,6 +9,7 @@ export default defineConfig({
9
9
  entry: {
10
10
  test: resolve(__dirname, "tests/fixtures/mockup.twig"),
11
11
  error: resolve(__dirname, "tests/fixtures/error.twig"),
12
+ menu: resolve(__dirname, "tests/fixtures/menu.twig"),
12
13
  errorInclude: resolve(__dirname, "tests/fixtures/error-include.twig"),
13
14
  },
14
15
  name: "vite-plugin-twig-drupal",