Skip to content

Commit 9b7acfd

Browse files
authored
Merge pull request #13 from 11ty/pug
Initial pug plugin code from https://github.com/Zearin/eleventy-plugin-pug
2 parents fe88e7d + 4f422ed commit 9b7acfd

33 files changed

+712
-21
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
- [`@11ty/eleventy-plugin-handlebars` in `handlebars/`](./handlebars/README.md)
55
- [`@11ty/eleventy-plugin-mustache` in `mustache/`](./mustache/README.md)
66
- [`@11ty/eleventy-plugin-haml` in `haml/`](./haml/README.md)
7+
- [`@11ty/eleventy-plugin-pug` in `pug/`](./pug/README.md)

ejs/test/ejs-test.mjs

+9-9
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ name: Zach
6060
});
6161

6262
describe("EJS Includes", () => {
63-
test("EJS Render Absolute Include, Fxn no Data", async function () {
63+
test("Render Absolute Include, Fxn no Data", async function () {
6464
let [result] = await getTestResults((eleventyConfig) => {
6565
eleventyConfig.addTemplate("filename.ejs", "<p><%- include('/included') %></p>", {
6666
name: "Zach",
@@ -70,7 +70,7 @@ describe("EJS Includes", () => {
7070
strictEqual(result.content, `<p>This is an include.</p>`);
7171
});
7272

73-
test("EJS Render Absolute Include, Fxn with Data", async function () {
73+
test("Render Absolute Include, Fxn with Data", async function () {
7474
let [result] = await getTestResults((eleventyConfig) => {
7575
// includes require a full filename passed in
7676
eleventyConfig.addTemplate(
@@ -83,7 +83,7 @@ describe("EJS Includes", () => {
8383
strictEqual(result.content, `<p>This is an Bill.</p>`);
8484
});
8585

86-
test("EJS Render Relative Include (no leading dot-slash for current dir)", async function () {
86+
test("Render Relative Include (no leading dot-slash for current dir)", async function () {
8787
let [result] = await getTestResults((eleventyConfig) => {
8888
// includes require a full filename passed in
8989
eleventyConfig.addTemplate(
@@ -96,7 +96,7 @@ describe("EJS Includes", () => {
9696
strictEqual(result.content, `<p>This is an include.</p>`);
9797
});
9898

99-
test("EJS Render Relative Include Current dir to Subdir", async function () {
99+
test("Render Relative Include Current dir to Subdir", async function () {
100100
let [result] = await getTestResults((eleventyConfig) => {
101101
// includes require a full filename passed in
102102
eleventyConfig.addTemplate(
@@ -109,7 +109,7 @@ describe("EJS Includes", () => {
109109
strictEqual(result.content, `<p>This is an include.</p>`);
110110
});
111111

112-
test("EJS Render Relative Include Parent dir to Subdir", async function () {
112+
test("Render Relative Include Parent dir to Subdir", async function () {
113113
let [result] = await getTestResults((eleventyConfig) => {
114114
// includes require a full filename passed in
115115
eleventyConfig.addTemplate(
@@ -122,7 +122,7 @@ describe("EJS Includes", () => {
122122
strictEqual(result.content, `<p>This is an include.</p>`);
123123
});
124124

125-
test("EJS Render Relative Include Parent dir to Subdir", async function () {
125+
test("Render Relative Include Parent dir to Subdir", async function () {
126126
let [result] = await getTestResults((eleventyConfig) => {
127127
// includes require a full filename passed in
128128
eleventyConfig.addTemplate(
@@ -135,7 +135,7 @@ describe("EJS Includes", () => {
135135
strictEqual(result.content, `<p>This is an include.</p>`);
136136
});
137137

138-
test("EJS Render Relative Include, Fxn no Data", async function () {
138+
test("Render Relative Include, Fxn no Data", async function () {
139139
let [result] = await getTestResults((eleventyConfig) => {
140140
// includes require a full filename passed in
141141
eleventyConfig.addTemplate(
@@ -148,7 +148,7 @@ describe("EJS Includes", () => {
148148
strictEqual(result.content, `<p>This is an include.</p>`);
149149
});
150150

151-
test("EJS Render Relative Include current dir to subdir, Fxn no Data", async function () {
151+
test("Render Relative Include current dir to subdir, Fxn no Data", async function () {
152152
let [result] = await getTestResults((eleventyConfig) => {
153153
// includes require a full filename passed in
154154
eleventyConfig.addTemplate(
@@ -161,7 +161,7 @@ describe("EJS Includes", () => {
161161
strictEqual(result.content, `<p>This is an include.</p>`);
162162
});
163163

164-
test("EJS Render Relative Include, Fxn with Data", async function () {
164+
test("Render Relative Include, Fxn with Data", async function () {
165165
let [result] = await getTestResults((eleventyConfig) => {
166166
// includes require a full filename passed in
167167
eleventyConfig.addTemplate(

handlebars/test/hbs-test.mjs

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ test("Handlebars permalink", async function () {
4444
strictEqual(result.url, `/this-is-a-url/`);
4545
});
4646

47-
describe("Escaped and unescaped output", () => {
47+
describe("Handlebars Escaped and unescaped output", () => {
4848

49-
test("Handlebars unescaped output (no HTML)", async function () {
49+
test("Unescaped output (no HTML)", async function () {
5050
let [result] = await getTestResults((eleventyConfig) => {
5151
eleventyConfig.addTemplate("sample.hbs", "<p>{{{name}}}</p>", {
5252
name: "Zach",
@@ -56,7 +56,7 @@ describe("Escaped and unescaped output", () => {
5656
strictEqual(result.content, `<p>Zach</p>`);
5757
});
5858

59-
test("Handlebars escaped output (HTML)", async function () {
59+
test("Escaped output (HTML)", async function () {
6060
let [result] = await getTestResults((eleventyConfig) => {
6161
eleventyConfig.addTemplate("sample.hbs", "<p>{{name}}</p>", {
6262
name: "<b>Zach</b>",
@@ -66,7 +66,7 @@ describe("Escaped and unescaped output", () => {
6666
strictEqual(result.content, `<p>&lt;b&gt;Zach&lt;/b&gt;</p>`);
6767
});
6868

69-
test("Handlebars Unescaped Output (HTML)", async function () {
69+
test("Unescaped Output (HTML)", async function () {
7070
let [result] = await getTestResults((eleventyConfig) => {
7171
eleventyConfig.addTemplate("sample.hbs", "<p>{{{name}}}</p>", {
7272
name: "<b>Zach</b>",
@@ -78,31 +78,31 @@ describe("Escaped and unescaped output", () => {
7878
});
7979

8080
describe("Handlebars Partials", () => {
81-
test("Handlebars Partial", async function () {
81+
test("Partial", async function () {
8282
let [result] = await getTestResults((eleventyConfig) => {
8383
eleventyConfig.addTemplate("sample.hbs", "<p>{{> included}}</p>", {});
8484
});
8585

8686
strictEqual(result.content, `<p>This is an include.</p>`);
8787
});
8888

89-
test("Handlebars Render Partial (Subdirectory)", async () => {
89+
test("Render Partial (Subdirectory)", async () => {
9090
let [result] = await getTestResults((eleventyConfig) => {
9191
eleventyConfig.addTemplate("sample.hbs", "<p>{{> subfolder/included-subfolder}}</p>", {});
9292
});
9393

9494
strictEqual(result.content, `<p>This is a subfolder include.</p>`);
9595
});
9696

97-
test("Handlebars Partial with variable", async () => {
97+
test("Partial with variable", async () => {
9898
let [result] = await getTestResults((eleventyConfig) => {
9999
eleventyConfig.addTemplate("sample.hbs", "<p>{{> includedvar}}</p>", { name: "Zach" });
100100
});
101101

102102
strictEqual(result.content, "<p>This is a Zach.</p>");
103103
});
104104

105-
test("Handlebars Partial with parameter", async () => {
105+
test("Partial with parameter", async () => {
106106
let [result] = await getTestResults((eleventyConfig) => {
107107
eleventyConfig.addTemplate("sample.hbs", "<p>{{> myPartial parameter=name }}</p>", { name: "Zach" });
108108
});

mustache/test/mustache-test.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test("Mustache permalink", async function () {
4444
strictEqual(result.url, `/this-is-a-url/`);
4545
});
4646

47-
describe("Partials", () => {
47+
describe("Mustache Partials", () => {
4848
test("Partial raw text", async function () {
4949
let [result] = await getTestResults((eleventyConfig) => {
5050
eleventyConfig.addTemplate("sample.mustache", "<p>{{> include}}</p>");
@@ -70,7 +70,7 @@ describe("Partials", () => {
7070
});
7171
});
7272

73-
test("Library override", async function () {
73+
test("Mustache Library override", async function () {
7474
let [result] = await getTestResults((eleventyConfig) => {
7575
eleventyConfig.addTemplate("sample.mustache", "<p>{{name}}</p>", { name: "Zach" });
7676
}, {
@@ -80,7 +80,7 @@ test("Library override", async function () {
8080
strictEqual(result.content, `<p>Zach</p>`);
8181
});
8282

83-
describe("Escaped/unescaped output", () => {
83+
describe("Mustache Escaped/unescaped output", () => {
8484
test("Escaped output (no HTML)", async function () {
8585
let [result] = await getTestResults((eleventyConfig) => {
8686
eleventyConfig.addTemplate("sample.mustache", "<p>{{{name}}}</p>", { name: "Zach" });

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"ejs",
55
"handlebars",
66
"mustache",
7-
"haml"
7+
"haml",
8+
"pug"
89
],
910
"type": "module",
1011
"scripts": {

pug/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Zearin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

pug/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# eleventy-plugin-pug
2+
Pug templates for Eleventy 3!

pug/defaults.js

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @fileoverview Pug default options.
3+
*/
4+
5+
export const DEFAULT_PUG_OPTIONS = {
6+
/**
7+
* The name of the file being compiled. Used in exceptions, and required for
8+
* relative `include`\s and `extend`\s.
9+
* @type {String}
10+
* @default 'Pug'
11+
*/
12+
filename: 'Pug',
13+
14+
/**
15+
* The root directory of all absolute inclusion.
16+
* @type {String}
17+
*/
18+
basedir: '.',
19+
20+
/**
21+
* If the doctype is not specified as part of the template, you can specify it here.
22+
* It is sometimes useful to get self-closing tags and remove mirroring of boolean attributes.
23+
* See doctype documentation for more information.
24+
* @type {String|undefined}
25+
* @default undefined
26+
*/
27+
doctype: undefined,
28+
29+
/**
30+
* [Deprecated.] Adds whitespace to the resulting HTML to make it easier for a human to read
31+
* using ' ' as indentation. If a string is specified, that will be used as indentation instead
32+
* (e.g. '\t').
33+
*
34+
* We strongly recommend against using this option. Too often, it creates subtle bugs in your
35+
* templates because of the way it alters the interpretation and rendering of whitespace, and
36+
* so this feature is going to be removed. Defaults to `false`.
37+
*
38+
* @type {Boolean|String}
39+
* @default false
40+
*/
41+
pretty: false,
42+
43+
/**
44+
* Hash table of custom filters. Defaults to `undefined`.
45+
* @type {Object|undefined}
46+
* @default undefined
47+
*/
48+
filters: undefined,
49+
50+
/**
51+
* Use a self namespace to hold the locals. It will speed up the compilation, but
52+
* instead of writing `variable` you will have to write `self.variable` to access
53+
* a property of the `locals` object. Defaults to `false`.
54+
* @type {Boolean}
55+
* @default false
56+
*/
57+
self: false,
58+
59+
/**
60+
* If set to `true`, the tokens and function body are logged to stdout.
61+
* @type {Boolean}
62+
* @default false
63+
*/
64+
debug: false,
65+
66+
/**
67+
* If set to `true`, the function source will be included in the compiled template for
68+
* better error messages (sometimes useful in development).
69+
* It is enabled by default, unless used with Express in production mode.
70+
* @type {Boolean}
71+
* @default true
72+
*/
73+
compileDebug: true,
74+
75+
/**
76+
* Add a list of global names to make accessible in templates.
77+
* @type {Array<String>}
78+
* @default []
79+
*/
80+
globals: [],
81+
82+
/**
83+
* (Only applies to `render*` functions.) If set to `true`, compiled functions
84+
* are cached. `filename` must be set as the cache key. Defaults to `false`.
85+
* @type {Boolean}
86+
* @default false
87+
*/
88+
cache: false,
89+
90+
/**
91+
* Inline runtime functions instead of require-ing them from a shared version.
92+
*
93+
* For `compileClient*` functions, the default is `true` (so that one does not
94+
* have to include the runtime).
95+
*
96+
* For all other compilation or rendering types, the default is `false`.
97+
* @type {Boolean}
98+
* @default false
99+
*/
100+
inlineRuntimeFunctions: false,
101+
102+
/**
103+
* (Only applies to `compileClient*` functions.) The name of the template function.
104+
* Defaults to 'template'.
105+
* @type {String}
106+
* @default 'template'
107+
*/
108+
name: 'template'
109+
}
110+
111+
export default DEFAULT_PUG_OPTIONS

0 commit comments

Comments
 (0)