vite-plugin-twig-drupal 1.6.3 → 1.6.4

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.6.3",
3
+ "version": "1.6.4",
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
@@ -186,6 +186,11 @@ const plugin = (options = {}) => {
186
186
  return includes.reduce(
187
187
  (queue, template) =>
188
188
  queue.then(() => {
189
+ // _self is a special Twig variable referring to the current
190
+ // template — it is not a real file import.
191
+ if (template === "_self") {
192
+ return Promise.resolve()
193
+ }
189
194
  const file = resolveFile(
190
195
  dirname(id),
191
196
  resolveNamespaceOrComponent(options.namespaces, template)
@@ -134,6 +134,20 @@ exports[`Basic smoke test > Should support global context and functions 1`] = `
134
134
  "
135
135
  `;
136
136
 
137
+ exports[`Basic smoke test > Should support import _self for recursive macros 1`] = `
138
+ "
139
+
140
+ <nav>
141
+ <ul>
142
+ <li><a href=\\"/home\\">Home</a></li>
143
+
144
+ <li><a href=\\"/about\\">About</a></li>
145
+
146
+ </ul>
147
+ </nav>
148
+ "
149
+ `;
150
+
137
151
  exports[`Basic smoke test > Should support includes 1`] = `
138
152
  "<section>
139
153
  <h1>Include</h1>
@@ -0,0 +1,12 @@
1
+ {% import _self as nav %}
2
+
3
+ {% macro menu_link(title, href) %}
4
+ <li><a href="{{ href }}">{{ title }}</a></li>
5
+ {% endmacro %}
6
+
7
+ <nav>
8
+ <ul>
9
+ {{ nav.menu_link('Home', '/home') }}
10
+ {{ nav.menu_link('About', '/about') }}
11
+ </ul>
12
+ </nav>
@@ -3,6 +3,7 @@ import Error from "../dist/error.js"
3
3
  import ErrorInclude from "../dist/errorInclude.js"
4
4
  import drupalFunctions from "../dist/drupalFunctions.js"
5
5
  import Menu from "../dist/menu.js"
6
+ import SelfImport from "../dist/selfImport.js"
6
7
  import { describe, expect, it } from "vitest"
7
8
 
8
9
  describe("Basic smoke test", () => {
@@ -72,4 +73,10 @@ describe("Basic smoke test", () => {
72
73
  expect(markup).toContain("All received")
73
74
  expect(markup).toContain("pony town")
74
75
  })
76
+ it("Should support import _self for recursive macros", () => {
77
+ const markup = SelfImport()
78
+ expect(markup).toContain("Home")
79
+ expect(markup).toContain("About")
80
+ expect(markup).toMatchSnapshot()
81
+ })
75
82
  })
package/vite.config.js CHANGED
@@ -15,6 +15,7 @@ export default defineConfig({
15
15
  __dirname,
16
16
  "tests/fixtures/drupal-functions.twig"
17
17
  ),
18
+ selfImport: resolve(__dirname, "tests/fixtures/self-import.twig"),
18
19
  },
19
20
  name: "vite-plugin-twig-drupal",
20
21
  formats: ["es"],