fix: add scoped error logging for lexer/parser errors
- Add std.log.scoped(.pugz) to template.zig and view_engine.zig - Log detailed error info (code, line, column, message) when parsing fails - Log template path context in ViewEngine on parse errors - Remove debug print from lexer, use proper scoped logging instead - Move benchmarks, docs, examples, playground, tests out of src/ to project root - Update build.zig and documentation paths accordingly - Bump version to 0.3.1
This commit is contained in:
5
tests/sample_data/pug/examples/README.md
Normal file
5
tests/sample_data/pug/examples/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
The examples in this directory can be run simply by something like.
|
||||
|
||||
node attributes.js
|
||||
|
||||
You can also open `browser.html` in a browser.
|
||||
10
tests/sample_data/pug/examples/attributes.js
Normal file
10
tests/sample_data/pug/examples/attributes.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/attributes.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
console.log(fn({name: 'tj'}));
|
||||
8
tests/sample_data/pug/examples/attributes.pug
Normal file
8
tests/sample_data/pug/examples/attributes.pug
Normal file
@@ -0,0 +1,8 @@
|
||||
div#id.left.container(class='user user-' + name)
|
||||
h1.title= name
|
||||
form
|
||||
//- unbuffered comment :)
|
||||
// An example of attributes.
|
||||
input(type='text' name='user[name]' value=name)
|
||||
input(checked, type='checkbox', name='user[blocked]')
|
||||
input(type='submit', value='Update')
|
||||
15
tests/sample_data/pug/examples/code.js
Normal file
15
tests/sample_data/pug/examples/code.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/code.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
var users = {
|
||||
tj: {age: 23, email: 'tj@vision-media.ca', isA: 'human'},
|
||||
tobi: {age: 1, email: 'tobi@is-amazing.com', isA: 'ferret'},
|
||||
};
|
||||
|
||||
console.log(fn({users: users}));
|
||||
17
tests/sample_data/pug/examples/code.pug
Normal file
17
tests/sample_data/pug/examples/code.pug
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
- var title = "Things"
|
||||
|
||||
-
|
||||
var subtitle = ["Really", "long",
|
||||
"list", "of",
|
||||
"words"]
|
||||
h1= title
|
||||
h2= subtitle.join(" ")
|
||||
|
||||
ul#users
|
||||
each user, name in users
|
||||
// expands to if (user.isA == 'ferret')
|
||||
if user.isA == 'ferret'
|
||||
li(class='user-' + name) #{name} is just a ferret
|
||||
else
|
||||
li(class='user-' + name) #{name} #{user.email}
|
||||
15
tests/sample_data/pug/examples/dynamicscript.js
Normal file
15
tests/sample_data/pug/examples/dynamicscript.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../');
|
||||
|
||||
var locals = {
|
||||
users: {
|
||||
tj: {age: 23, email: 'tj@vision-media.ca', isA: 'human'},
|
||||
tobi: {age: 1, email: 'tobi@is-amazing.com', isA: 'ferret'},
|
||||
},
|
||||
};
|
||||
|
||||
var fn = pug.compileFile(__dirname + '/dynamicscript.pug');
|
||||
console.log(fn(locals));
|
||||
5
tests/sample_data/pug/examples/dynamicscript.pug
Normal file
5
tests/sample_data/pug/examples/dynamicscript.pug
Normal file
@@ -0,0 +1,5 @@
|
||||
html
|
||||
head
|
||||
title Dynamic Inline JavaScript
|
||||
script.
|
||||
var users = !{JSON.stringify(users).replace(/<\//g, "<\\/")}
|
||||
15
tests/sample_data/pug/examples/each.js
Normal file
15
tests/sample_data/pug/examples/each.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/each.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
var users = {
|
||||
tj: {age: 23, email: 'tj@vision-media.ca', isA: 'human'},
|
||||
tobi: {age: 1, email: 'tobi@is-amazing.com', isA: 'ferret'},
|
||||
};
|
||||
|
||||
console.log(fn({users: users}));
|
||||
3
tests/sample_data/pug/examples/each.pug
Normal file
3
tests/sample_data/pug/examples/each.pug
Normal file
@@ -0,0 +1,3 @@
|
||||
ul#users
|
||||
each user, name in users
|
||||
li(class='user-' + name) #{name} #{user.email}
|
||||
10
tests/sample_data/pug/examples/extend-layout.pug
Normal file
10
tests/sample_data/pug/examples/extend-layout.pug
Normal file
@@ -0,0 +1,10 @@
|
||||
html
|
||||
head
|
||||
h1 My Site - #{title}
|
||||
block scripts
|
||||
script(src='/jquery.js')
|
||||
body
|
||||
block content
|
||||
block foot
|
||||
#footer
|
||||
p some footer content
|
||||
19
tests/sample_data/pug/examples/extend.js
Normal file
19
tests/sample_data/pug/examples/extend.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/extend.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
var tobi = {name: 'tobi', age: 2};
|
||||
var loki = {name: 'loki', age: 1};
|
||||
var jane = {name: 'jane', age: 5};
|
||||
|
||||
console.log(
|
||||
fn({
|
||||
title: 'pets',
|
||||
pets: [tobi, loki, jane],
|
||||
})
|
||||
);
|
||||
11
tests/sample_data/pug/examples/extend.pug
Normal file
11
tests/sample_data/pug/examples/extend.pug
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
extends extend-layout.pug
|
||||
|
||||
block scripts
|
||||
script(src='/jquery.js')
|
||||
script(src='/pets.js')
|
||||
|
||||
block content
|
||||
h1= title
|
||||
each pet in pets
|
||||
include pet.pug
|
||||
17
tests/sample_data/pug/examples/form.js
Normal file
17
tests/sample_data/pug/examples/form.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/form.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
var user = {
|
||||
name: 'TJ',
|
||||
email: 'tj@vision-media.ca',
|
||||
city: 'Victoria',
|
||||
province: 'BC',
|
||||
};
|
||||
|
||||
console.log(fn({user: user}));
|
||||
29
tests/sample_data/pug/examples/form.pug
Normal file
29
tests/sample_data/pug/examples/form.pug
Normal file
@@ -0,0 +1,29 @@
|
||||
form(method="post")
|
||||
fieldset
|
||||
legend General
|
||||
p
|
||||
label(for="user[name]") Username:
|
||||
input(type="text", name="user[name]", value=user.name)
|
||||
p
|
||||
label(for="user[email]") Email:
|
||||
input(type="text", name="user[email]", value=user.email)
|
||||
.tip.
|
||||
Enter a valid
|
||||
email address
|
||||
such as <em>tj@vision-media.ca</em>.
|
||||
fieldset
|
||||
legend Location
|
||||
p
|
||||
label(for="user[city]") City:
|
||||
input(type="text", name="user[city]", value=user.city)
|
||||
p
|
||||
select(name="user[province]")
|
||||
option(value="") -- Select Province --
|
||||
option(value="AB") Alberta
|
||||
option(value="BC") British Columbia
|
||||
option(value="SK") Saskatchewan
|
||||
option(value="MB") Manitoba
|
||||
option(value="ON") Ontario
|
||||
option(value="QC") Quebec
|
||||
p.buttons
|
||||
input(type="submit", value="Save")
|
||||
10
tests/sample_data/pug/examples/includes.js
Normal file
10
tests/sample_data/pug/examples/includes.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/includes.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
console.log(fn());
|
||||
7
tests/sample_data/pug/examples/includes.pug
Normal file
7
tests/sample_data/pug/examples/includes.pug
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
html
|
||||
include includes/head.pug
|
||||
body
|
||||
h1 My Site
|
||||
p Welcome to my super lame site.
|
||||
include includes/foot.pug
|
||||
2
tests/sample_data/pug/examples/includes/foot.pug
Normal file
2
tests/sample_data/pug/examples/includes/foot.pug
Normal file
@@ -0,0 +1,2 @@
|
||||
#footer
|
||||
p Copyright (c) foobar
|
||||
6
tests/sample_data/pug/examples/includes/head.pug
Normal file
6
tests/sample_data/pug/examples/includes/head.pug
Normal file
@@ -0,0 +1,6 @@
|
||||
head
|
||||
title My Site
|
||||
// including other pug works
|
||||
include scripts.pug
|
||||
// including .html, .css, etc works
|
||||
include style.css
|
||||
2
tests/sample_data/pug/examples/includes/scripts.pug
Normal file
2
tests/sample_data/pug/examples/includes/scripts.pug
Normal file
@@ -0,0 +1,2 @@
|
||||
script(src='/javascripts/jquery.js')
|
||||
script(src='/javascripts/app.js')
|
||||
5
tests/sample_data/pug/examples/includes/style.css
Normal file
5
tests/sample_data/pug/examples/includes/style.css
Normal file
@@ -0,0 +1,5 @@
|
||||
<style>
|
||||
body {
|
||||
padding: 50px;
|
||||
}
|
||||
</style>
|
||||
10
tests/sample_data/pug/examples/layout-debug.js
Normal file
10
tests/sample_data/pug/examples/layout-debug.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../');
|
||||
|
||||
pug.renderFile(__dirname + '/layout.pug', {debug: true}, function(err, html) {
|
||||
if (err) throw err;
|
||||
console.log(html);
|
||||
});
|
||||
10
tests/sample_data/pug/examples/layout.js
Normal file
10
tests/sample_data/pug/examples/layout.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/layout.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
console.log(fn());
|
||||
14
tests/sample_data/pug/examples/layout.pug
Normal file
14
tests/sample_data/pug/examples/layout.pug
Normal file
@@ -0,0 +1,14 @@
|
||||
doctype html
|
||||
html(lang="en")
|
||||
head
|
||||
title Example
|
||||
script.
|
||||
if (foo) {
|
||||
bar();
|
||||
}
|
||||
body
|
||||
h1 Pug - node template engine
|
||||
#container
|
||||
:markdown-it
|
||||
Pug is a _high performance_ template engine for [node](http://nodejs.org),
|
||||
inspired by [haml](http://haml-lang.com/), and written by [TJ Holowaychuk](http://github.com/visionmedia).
|
||||
15
tests/sample_data/pug/examples/mixins.js
Normal file
15
tests/sample_data/pug/examples/mixins.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/mixins.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
var user = {
|
||||
name: 'tj',
|
||||
pets: ['tobi', 'loki', 'jane', 'manny'],
|
||||
};
|
||||
|
||||
console.log(fn({user: user}));
|
||||
14
tests/sample_data/pug/examples/mixins.pug
Normal file
14
tests/sample_data/pug/examples/mixins.pug
Normal file
@@ -0,0 +1,14 @@
|
||||
include mixins/dialog.pug
|
||||
include mixins/profile.pug
|
||||
|
||||
.one
|
||||
+dialog
|
||||
|
||||
.two
|
||||
+dialog-title('Whoop')
|
||||
|
||||
.three
|
||||
+dialog-title-desc('Whoop', 'Just a mixin')
|
||||
|
||||
#profile
|
||||
+profile(user)
|
||||
15
tests/sample_data/pug/examples/mixins/dialog.pug
Normal file
15
tests/sample_data/pug/examples/mixins/dialog.pug
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
mixin dialog
|
||||
.dialog
|
||||
h1 Whoop
|
||||
p stuff
|
||||
|
||||
mixin dialog-title(title)
|
||||
.dialog
|
||||
h1= title
|
||||
p stuff
|
||||
|
||||
mixin dialog-title-desc(title, desc)
|
||||
.dialog
|
||||
h1= title
|
||||
p= desc
|
||||
10
tests/sample_data/pug/examples/mixins/profile.pug
Normal file
10
tests/sample_data/pug/examples/mixins/profile.pug
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
mixin pets(pets)
|
||||
ul.pets
|
||||
each pet in pets
|
||||
li= pet
|
||||
|
||||
mixin profile(user)
|
||||
.user
|
||||
h2= user.name
|
||||
+pets(user.pets)
|
||||
3
tests/sample_data/pug/examples/pet.pug
Normal file
3
tests/sample_data/pug/examples/pet.pug
Normal file
@@ -0,0 +1,3 @@
|
||||
.pet
|
||||
h2= pet.name
|
||||
p #{pet.name} is <em>#{pet.age}</em> year(s) old.
|
||||
28
tests/sample_data/pug/examples/rss.js
Normal file
28
tests/sample_data/pug/examples/rss.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/rss.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
var items = [];
|
||||
|
||||
items.push({
|
||||
title: 'Example',
|
||||
description: 'Something',
|
||||
link: 'http://google.com',
|
||||
});
|
||||
items.push({
|
||||
title: 'LearnBoost',
|
||||
description: 'Cool',
|
||||
link: 'http://learnboost.com',
|
||||
});
|
||||
items.push({
|
||||
title: 'Express',
|
||||
description: 'Cool',
|
||||
link: 'http://expressjs.com',
|
||||
});
|
||||
|
||||
console.log(fn({items: items}));
|
||||
14
tests/sample_data/pug/examples/rss.pug
Normal file
14
tests/sample_data/pug/examples/rss.pug
Normal file
@@ -0,0 +1,14 @@
|
||||
doctype xml
|
||||
rss(version='2.0')
|
||||
channel
|
||||
title RSS Title
|
||||
description Some description here
|
||||
link http://google.com
|
||||
lastBuildDate Mon, 06 Sep 2010 00:01:00 +0000
|
||||
pubDate Mon, 06 Sep 2009 16:45:00 +0000
|
||||
|
||||
each item in items
|
||||
item
|
||||
title= item.title
|
||||
description= item.description
|
||||
link= item.link
|
||||
10
tests/sample_data/pug/examples/text.js
Normal file
10
tests/sample_data/pug/examples/text.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/text.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
console.log(fn({name: 'tj', email: 'tj@vision-media.ca'}));
|
||||
36
tests/sample_data/pug/examples/text.pug
Normal file
36
tests/sample_data/pug/examples/text.pug
Normal file
@@ -0,0 +1,36 @@
|
||||
| An example of an
|
||||
a(href='#') inline
|
||||
| link.
|
||||
|
||||
form
|
||||
label Username:
|
||||
input(type='text', name='user[name]')
|
||||
p
|
||||
| Just an example of some text usage.
|
||||
| You can have <em>inline</em> html,
|
||||
| as well as
|
||||
strong tags
|
||||
| .
|
||||
|
||||
| Interpolation is also supported. The
|
||||
| username is currently "#{name}".
|
||||
|
||||
label Email:
|
||||
input(type='text', name='user[email]')
|
||||
p
|
||||
| Email is currently
|
||||
em= email
|
||||
| .
|
||||
|
||||
// alternatively, if we plan on having only
|
||||
// text or inline-html, we can use a trailing
|
||||
// "." to let pug know we want to omit pipes
|
||||
|
||||
label Username:
|
||||
input(type='text')
|
||||
p.
|
||||
Just an example, like before
|
||||
however now we can omit those
|
||||
annoying pipes!.
|
||||
|
||||
Wahoo.
|
||||
10
tests/sample_data/pug/examples/whitespace.js
Normal file
10
tests/sample_data/pug/examples/whitespace.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pug = require('../'),
|
||||
path = __dirname + '/whitespace.pug',
|
||||
str = require('fs').readFileSync(path, 'utf8'),
|
||||
fn = pug.compile(str, {filename: path, pretty: true});
|
||||
|
||||
console.log(fn());
|
||||
11
tests/sample_data/pug/examples/whitespace.pug
Normal file
11
tests/sample_data/pug/examples/whitespace.pug
Normal file
@@ -0,0 +1,11 @@
|
||||
- var js = '<script></script>'
|
||||
doctype html
|
||||
html
|
||||
|
||||
head
|
||||
title= "Some " + "JavaScript"
|
||||
!= js
|
||||
|
||||
|
||||
|
||||
body
|
||||
15
tests/sample_data/pug/test/README.md
Normal file
15
tests/sample_data/pug/test/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Running Tests
|
||||
|
||||
To run tests (with node.js installed) you must complete 2 steps.
|
||||
|
||||
## 1 Install dependencies
|
||||
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
## 2 Run tests
|
||||
|
||||
```
|
||||
npm test
|
||||
```
|
||||
110
tests/sample_data/pug/test/__snapshots__/pug.test.js.snap
Normal file
110
tests/sample_data/pug/test/__snapshots__/pug.test.js.snap
Normal file
@@ -0,0 +1,110 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`pug .compileClient() should support module syntax in pug.compileClient(str, options) when inlineRuntimeFunctions it false 1`] = `
|
||||
"var pug = require(\\"pug-runtime\\");
|
||||
function template(locals) {
|
||||
var pug_html = \\"\\",
|
||||
pug_mixins = {},
|
||||
pug_interp;
|
||||
var pug_debug_filename, pug_debug_line;
|
||||
try {
|
||||
var self = locals || {};
|
||||
pug_debug_line = 1;
|
||||
pug_html = pug_html + '\\\\u003Cdiv class=\\"bar\\"\\\\u003E';
|
||||
pug_debug_line = 1;
|
||||
pug_html =
|
||||
pug_html +
|
||||
pug.escape(null == (pug_interp = self.foo) ? \\"\\" : pug_interp) +
|
||||
\\"\\\\u003C\\\\u002Fdiv\\\\u003E\\";
|
||||
} catch (err) {
|
||||
pug.rethrow(err, pug_debug_filename, pug_debug_line);
|
||||
}
|
||||
return pug_html;
|
||||
}
|
||||
module.exports = template;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`pug .compileClient() should support module syntax in pug.compileClient(str, options) when inlineRuntimeFunctions it true 1`] = `
|
||||
"function pug_escape(e) {
|
||||
var a = \\"\\" + e,
|
||||
t = pug_match_html.exec(a);
|
||||
if (!t) return e;
|
||||
var r,
|
||||
c,
|
||||
n,
|
||||
s = \\"\\";
|
||||
for (r = t.index, c = 0; r < a.length; r++) {
|
||||
switch (a.charCodeAt(r)) {
|
||||
case 34:
|
||||
n = \\""\\";
|
||||
break;
|
||||
case 38:
|
||||
n = \\"&\\";
|
||||
break;
|
||||
case 60:
|
||||
n = \\"<\\";
|
||||
break;
|
||||
case 62:
|
||||
n = \\">\\";
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
c !== r && (s += a.substring(c, r)), (c = r + 1), (s += n);
|
||||
}
|
||||
return c !== r ? s + a.substring(c, r) : s;
|
||||
}
|
||||
var pug_match_html = /[\\"&<>]/;
|
||||
function pug_rethrow(e, n, r, t) {
|
||||
if (!(e instanceof Error)) throw e;
|
||||
if (!((\\"undefined\\" == typeof window && n) || t))
|
||||
throw ((e.message += \\" on line \\" + r), e);
|
||||
var o, a, i, s;
|
||||
try {
|
||||
(t = t || require(\\"fs\\").readFileSync(n, { encoding: \\"utf8\\" })),
|
||||
(o = 3),
|
||||
(a = t.split(\\"\\\\n\\")),
|
||||
(i = Math.max(r - o, 0)),
|
||||
(s = Math.min(a.length, r + o));
|
||||
} catch (t) {
|
||||
return (
|
||||
(e.message += \\" - could not read from \\" + n + \\" (\\" + t.message + \\")\\"),
|
||||
void pug_rethrow(e, null, r)
|
||||
);
|
||||
}
|
||||
(o = a
|
||||
.slice(i, s)
|
||||
.map(function(e, n) {
|
||||
var t = n + i + 1;
|
||||
return (t == r ? \\" > \\" : \\" \\") + t + \\"| \\" + e;
|
||||
})
|
||||
.join(\\"\\\\n\\")),
|
||||
(e.path = n);
|
||||
try {
|
||||
e.message = (n || \\"Pug\\") + \\":\\" + r + \\"\\\\n\\" + o + \\"\\\\n\\\\n\\" + e.message;
|
||||
} catch (e) {}
|
||||
throw e;
|
||||
}
|
||||
function template(locals) {
|
||||
var pug_html = \\"\\",
|
||||
pug_mixins = {},
|
||||
pug_interp;
|
||||
var pug_debug_filename, pug_debug_line;
|
||||
try {
|
||||
var self = locals || {};
|
||||
pug_debug_line = 1;
|
||||
pug_html = pug_html + '\\\\u003Cdiv class=\\"bar\\"\\\\u003E';
|
||||
pug_debug_line = 1;
|
||||
pug_html =
|
||||
pug_html +
|
||||
pug_escape(null == (pug_interp = self.foo) ? \\"\\" : pug_interp) +
|
||||
\\"\\\\u003C\\\\u002Fdiv\\\\u003E\\";
|
||||
} catch (err) {
|
||||
pug_rethrow(err, pug_debug_filename, pug_debug_line);
|
||||
}
|
||||
return pug_html;
|
||||
}
|
||||
module.exports = template;
|
||||
"
|
||||
`;
|
||||
@@ -0,0 +1,3 @@
|
||||
script(type='text/x-template')
|
||||
#user(id!='user-<%= user.id %>')
|
||||
h1 <%= user.title %>
|
||||
4
tests/sample_data/pug/test/anti-cases/case-when.pug
Normal file
4
tests/sample_data/pug/test/anti-cases/case-when.pug
Normal file
@@ -0,0 +1,4 @@
|
||||
when 5
|
||||
.foo
|
||||
when 6
|
||||
.bar
|
||||
@@ -0,0 +1,2 @@
|
||||
case foo
|
||||
.div
|
||||
4
tests/sample_data/pug/test/anti-cases/else-condition.pug
Normal file
4
tests/sample_data/pug/test/anti-cases/else-condition.pug
Normal file
@@ -0,0 +1,4 @@
|
||||
if foo
|
||||
div
|
||||
else bar
|
||||
article
|
||||
@@ -0,0 +1,2 @@
|
||||
else
|
||||
.foo
|
||||
@@ -0,0 +1 @@
|
||||
foo()+bar()
|
||||
@@ -0,0 +1 @@
|
||||
div("foo"abc)
|
||||
@@ -0,0 +1 @@
|
||||
div(foo!~abc)
|
||||
@@ -0,0 +1,2 @@
|
||||
//- #1871
|
||||
p #[strong a}
|
||||
@@ -0,0 +1,2 @@
|
||||
mixin foo(a, b)
|
||||
+foo('a'b'b')
|
||||
@@ -0,0 +1,3 @@
|
||||
mixin foo
|
||||
block
|
||||
bar
|
||||
@@ -0,0 +1 @@
|
||||
foo()bar
|
||||
@@ -0,0 +1,2 @@
|
||||
:not-a-valid-filter
|
||||
foo bar
|
||||
@@ -0,0 +1,2 @@
|
||||
div
|
||||
block
|
||||
@@ -0,0 +1 @@
|
||||
div(title=[)
|
||||
1
tests/sample_data/pug/test/anti-cases/readme.md
Normal file
1
tests/sample_data/pug/test/anti-cases/readme.md
Normal file
@@ -0,0 +1 @@
|
||||
This folder collects examples of files that are not valid `pug`, but were at some point accepted by the parser without throwing an error. The tests ensure that all these cases now throw some form of error message (hopefully a helpful one).
|
||||
@@ -0,0 +1,2 @@
|
||||
input
|
||||
| Inputs cannot have content
|
||||
@@ -0,0 +1 @@
|
||||
input Input's can't have content
|
||||
@@ -0,0 +1 @@
|
||||
input= 'Inputs cannot have code'
|
||||
@@ -0,0 +1,3 @@
|
||||
div
|
||||
div
|
||||
article
|
||||
@@ -0,0 +1 @@
|
||||
+#{myMixin
|
||||
@@ -0,0 +1,4 @@
|
||||
mixin item
|
||||
block
|
||||
|
||||
+item( Contact
|
||||
@@ -0,0 +1 @@
|
||||
#{myMixin
|
||||
10
tests/sample_data/pug/test/browser/index.html
Normal file
10
tests/sample_data/pug/test/browser/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html><html><head></head><body><textarea id="input" placeholder="write pug here" style="width: 100%; min-height: 400px;">p
|
||||
author
|
||||
!= myName</textarea><pre style="background: #ECECEC;width: 100%; min-height: 400px;"><code id="output"></code></pre><script src="../../pug.js"></script><script>var input = document.getElementById('input');
|
||||
var output = document.getElementById('output');
|
||||
setInterval(function () {
|
||||
pug.render(input.value, {myName: 'Forbes Lindesay', pretty: true}, function (err, res) {
|
||||
if (err) throw err;
|
||||
output.textContent = res;
|
||||
})
|
||||
}, 500)</script></body></html>
|
||||
20
tests/sample_data/pug/test/browser/index.pug
Normal file
20
tests/sample_data/pug/test/browser/index.pug
Normal file
@@ -0,0 +1,20 @@
|
||||
!!! 5
|
||||
html
|
||||
head
|
||||
body
|
||||
textarea#input(placeholder='write pug here', style='width: 100%; min-height: 400px;').
|
||||
p
|
||||
author
|
||||
!= myName
|
||||
pre(style='background: #ECECEC;width: 100%; min-height: 400px;')
|
||||
code#output
|
||||
script(src='../../pug.js')
|
||||
script.
|
||||
var input = document.getElementById('input');
|
||||
var output = document.getElementById('output');
|
||||
setInterval(function () {
|
||||
pug.render(input.value, {myName: 'Forbes Lindesay', pretty: true}, function (err, res) {
|
||||
if (err) throw err;
|
||||
output.textContent = res;
|
||||
})
|
||||
}, 500)
|
||||
1
tests/sample_data/pug/test/cases-es2015/attr.html
Normal file
1
tests/sample_data/pug/test/cases-es2015/attr.html
Normal file
@@ -0,0 +1 @@
|
||||
<div class="avatar-div" style="background-image: url(https://www.gravatar.com/avatar/219b77f9d21de75e81851b6b886057c7)"></div>
|
||||
3
tests/sample_data/pug/test/cases-es2015/attr.pug
Normal file
3
tests/sample_data/pug/test/cases-es2015/attr.pug
Normal file
@@ -0,0 +1,3 @@
|
||||
- var avatar = '219b77f9d21de75e81851b6b886057c7'
|
||||
|
||||
div.avatar-div(style=`background-image: url(https://www.gravatar.com/avatar/${avatar})`)
|
||||
6
tests/sample_data/pug/test/cases/attrs-data.html
Normal file
6
tests/sample_data/pug/test/cases/attrs-data.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<foo data-user="{"name":"tobi"}"></foo>
|
||||
<foo data-items="[1,2,3]"></foo>
|
||||
<foo data-username="tobi"></foo>
|
||||
<foo data-escaped="{"message":"Let's rock!"}"></foo>
|
||||
<foo data-ampersand="{"message":"a quote: &quot; this & that"}"></foo>
|
||||
<foo data-epoc="1970-01-01T00:00:00.000Z"></foo>
|
||||
7
tests/sample_data/pug/test/cases/attrs-data.pug
Normal file
7
tests/sample_data/pug/test/cases/attrs-data.pug
Normal file
@@ -0,0 +1,7 @@
|
||||
- var user = { name: 'tobi' }
|
||||
foo(data-user=user)
|
||||
foo(data-items=[1,2,3])
|
||||
foo(data-username='tobi')
|
||||
foo(data-escaped={message: "Let's rock!"})
|
||||
foo(data-ampersand={message: "a quote: " this & that"})
|
||||
foo(data-epoc=new Date(0))
|
||||
1
tests/sample_data/pug/test/cases/attrs.colon.html
Normal file
1
tests/sample_data/pug/test/cases/attrs.colon.html
Normal file
@@ -0,0 +1 @@
|
||||
<div :my-var="model"></div><span v-for="item in items" :key="item.id" :value="item.name"></span><span v-for="item in items" :key="item.id" :value="item.name"></span><a :link="goHere" value="static" :my-value="dynamic" @click="onClick()" :another="more">Click Me!</a>
|
||||
9
tests/sample_data/pug/test/cases/attrs.colon.pug
Normal file
9
tests/sample_data/pug/test/cases/attrs.colon.pug
Normal file
@@ -0,0 +1,9 @@
|
||||
//- Tests for using a colon-prefexed attribute (typical when using short-cut for Vue.js `v-bind`)
|
||||
div(:my-var="model")
|
||||
span(v-for="item in items" :key="item.id" :value="item.name")
|
||||
span(
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
:value="item.name"
|
||||
)
|
||||
a(:link="goHere" value="static" :my-value="dynamic" @click="onClick()" :another="more") Click Me!
|
||||
20
tests/sample_data/pug/test/cases/attrs.html
Normal file
20
tests/sample_data/pug/test/cases/attrs.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<a href="/contact">contact</a><a class="button" href="/save">save</a><a foo="foo" bar="bar" baz="baz"></a><a foo="foo, bar, baz" bar="1"></a><a foo="((foo))" bar="1"></a>
|
||||
<select>
|
||||
<option value="foo" selected="selected">Foo</option>
|
||||
<option selected="selected" value="bar">Bar</option>
|
||||
</select><a foo="class:"></a>
|
||||
<input pattern="\S+"/><a href="/contact">contact</a><a class="button" href="/save">save</a><a foo="foo" bar="bar" baz="baz"></a><a foo="foo, bar, baz" bar="1"></a><a foo="((foo))" bar="1"></a>
|
||||
<select>
|
||||
<option value="foo" selected="selected">Foo</option>
|
||||
<option selected="selected" value="bar">Bar</option>
|
||||
</select><a foo="class:"></a>
|
||||
<input pattern="\S+"/>
|
||||
<foo terse="true"></foo>
|
||||
<foo date="1970-01-01T00:00:00.000Z"></foo>
|
||||
<foo abc="abc" def="def"></foo>
|
||||
<foo abc="abc" def="def"></foo>
|
||||
<foo abc="abc" def="def"></foo>
|
||||
<foo abc="abc" def="def"></foo>
|
||||
<foo abc="abc" def="def"></foo>
|
||||
<foo abc="abc" def="def"></foo>
|
||||
<div foo="bar" bar="<baz>"></div><a foo="foo" bar="bar"></a><a foo="foo" bar="bar"></a>
|
||||
5
tests/sample_data/pug/test/cases/attrs.js.html
Normal file
5
tests/sample_data/pug/test/cases/attrs.js.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<a class="button" href="/user/5"></a><a class="button" href="/user/5"></a>
|
||||
<meta key="answer" value="42"/><a class="class1 class2"></a><a class="tag-class class1 class2"></a><a class="button" href="/user/5"></a><a class="button" href="/user/5"></a>
|
||||
<meta key="answer" value="42"/><a class="class1 class2"></a><a class="tag-class class1 class2"></a>
|
||||
<div id="5" foo="bar"></div>
|
||||
<div baz="baz"></div>
|
||||
17
tests/sample_data/pug/test/cases/attrs.js.pug
Normal file
17
tests/sample_data/pug/test/cases/attrs.js.pug
Normal file
@@ -0,0 +1,17 @@
|
||||
- var id = 5
|
||||
- function answer() { return 42; }
|
||||
a(href='/user/' + id, class='button')
|
||||
a(href = '/user/' + id, class = 'button')
|
||||
meta(key='answer', value=answer())
|
||||
a(class = ['class1', 'class2'])
|
||||
a.tag-class(class = ['class1', 'class2'])
|
||||
|
||||
a(href='/user/' + id class='button')
|
||||
a(href = '/user/' + id class = 'button')
|
||||
meta(key='answer' value=answer())
|
||||
a(class = ['class1', 'class2'])
|
||||
a.tag-class(class = ['class1', 'class2'])
|
||||
|
||||
div(id=id)&attributes({foo: 'bar'})
|
||||
- var bar = null
|
||||
div(foo=null bar=bar)&attributes({baz: 'baz'})
|
||||
43
tests/sample_data/pug/test/cases/attrs.pug
Normal file
43
tests/sample_data/pug/test/cases/attrs.pug
Normal file
@@ -0,0 +1,43 @@
|
||||
a(href='/contact') contact
|
||||
a(href='/save').button save
|
||||
a(foo, bar, baz)
|
||||
a(foo='foo, bar, baz', bar=1)
|
||||
a(foo='((foo))', bar= (1) ? 1 : 0 )
|
||||
select
|
||||
option(value='foo', selected) Foo
|
||||
option(selected, value='bar') Bar
|
||||
a(foo="class:")
|
||||
input(pattern='\\S+')
|
||||
|
||||
a(href='/contact') contact
|
||||
a(href='/save').button save
|
||||
a(foo bar baz)
|
||||
a(foo='foo, bar, baz' bar=1)
|
||||
a(foo='((foo))' bar= (1) ? 1 : 0 )
|
||||
select
|
||||
option(value='foo' selected) Foo
|
||||
option(selected value='bar') Bar
|
||||
a(foo="class:")
|
||||
input(pattern='\\S+')
|
||||
foo(terse="true")
|
||||
foo(date=new Date(0))
|
||||
|
||||
foo(abc
|
||||
,def)
|
||||
foo(abc,
|
||||
def)
|
||||
foo(abc,
|
||||
def)
|
||||
foo(abc
|
||||
,def)
|
||||
foo(abc
|
||||
def)
|
||||
foo(abc
|
||||
def)
|
||||
|
||||
- var attrs = {foo: 'bar', bar: '<baz>'}
|
||||
|
||||
div&attributes(attrs)
|
||||
|
||||
a(foo='foo' "bar"="bar")
|
||||
a(foo='foo' 'bar'='bar')
|
||||
5
tests/sample_data/pug/test/cases/attrs.unescaped.html
Normal file
5
tests/sample_data/pug/test/cases/attrs.unescaped.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<script type="text/x-template">
|
||||
<div id="user-<%= user.id %>">
|
||||
<h1><%= user.title %></h1>
|
||||
</div>
|
||||
</script>
|
||||
3
tests/sample_data/pug/test/cases/attrs.unescaped.pug
Normal file
3
tests/sample_data/pug/test/cases/attrs.unescaped.pug
Normal file
@@ -0,0 +1,3 @@
|
||||
script(type='text/x-template')
|
||||
div(id!='user-<%= user.id %>')
|
||||
h1 <%= user.title %>
|
||||
@@ -0,0 +1 @@
|
||||
block content
|
||||
@@ -0,0 +1,4 @@
|
||||
mixin test()
|
||||
.test&attributes(attributes)
|
||||
|
||||
+test()
|
||||
@@ -0,0 +1,8 @@
|
||||
doctype html
|
||||
html
|
||||
head
|
||||
title Default title
|
||||
body
|
||||
block body
|
||||
.container
|
||||
block content
|
||||
6
tests/sample_data/pug/test/cases/auxiliary/dialog.pug
Normal file
6
tests/sample_data/pug/test/cases/auxiliary/dialog.pug
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
extends window.pug
|
||||
|
||||
block window-content
|
||||
.dialog
|
||||
block content
|
||||
@@ -0,0 +1,2 @@
|
||||
block test
|
||||
|
||||
3
tests/sample_data/pug/test/cases/auxiliary/escapes.html
Normal file
3
tests/sample_data/pug/test/cases/auxiliary/escapes.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<script>
|
||||
console.log("foo\nbar")
|
||||
</script>
|
||||
@@ -0,0 +1,5 @@
|
||||
extends empty-block.pug
|
||||
|
||||
block test
|
||||
div test1
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
extends empty-block.pug
|
||||
|
||||
block test
|
||||
div test2
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
extends /auxiliary/layout.pug
|
||||
|
||||
block content
|
||||
include /auxiliary/include-from-root.pug
|
||||
@@ -0,0 +1,4 @@
|
||||
extends ../../cases/auxiliary/layout
|
||||
|
||||
block content
|
||||
include ../../cases/auxiliary/include-from-root
|
||||
@@ -0,0 +1,8 @@
|
||||
html
|
||||
head
|
||||
style(type="text/css")
|
||||
:less
|
||||
@pad: 15px;
|
||||
body {
|
||||
padding: @pad;
|
||||
}
|
||||
8
tests/sample_data/pug/test/cases/auxiliary/includable.js
Normal file
8
tests/sample_data/pug/test/cases/auxiliary/includable.js
Normal file
@@ -0,0 +1,8 @@
|
||||
var STRING_SUBSTITUTIONS = {
|
||||
// table of character substitutions
|
||||
'\t': '\\t',
|
||||
'\r': '\\r',
|
||||
'\n': '\\n',
|
||||
'"': '\\"',
|
||||
'\\': '\\\\',
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
h1 hello
|
||||
@@ -0,0 +1,11 @@
|
||||
mixin article()
|
||||
article
|
||||
block
|
||||
|
||||
html
|
||||
head
|
||||
title My Application
|
||||
block head
|
||||
body
|
||||
+article
|
||||
block content
|
||||
@@ -0,0 +1,2 @@
|
||||
h1 grand-grandparent
|
||||
block grand-grandparent
|
||||
@@ -0,0 +1,6 @@
|
||||
extends inheritance.extend.recursive-grand-grandparent.pug
|
||||
|
||||
block grand-grandparent
|
||||
h2 grandparent
|
||||
block grandparent
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
extends inheritance.extend.recursive-grandparent.pug
|
||||
|
||||
block grandparent
|
||||
h3 parent
|
||||
block parent
|
||||
@@ -0,0 +1,7 @@
|
||||
html
|
||||
head
|
||||
title My Application
|
||||
block head
|
||||
body
|
||||
block content
|
||||
include window.pug
|
||||
6
tests/sample_data/pug/test/cases/auxiliary/layout.pug
Normal file
6
tests/sample_data/pug/test/cases/auxiliary/layout.pug
Normal file
@@ -0,0 +1,6 @@
|
||||
html
|
||||
head
|
||||
title My Application
|
||||
block head
|
||||
body
|
||||
block content
|
||||
@@ -0,0 +1,3 @@
|
||||
mixin slide
|
||||
section.slide
|
||||
block
|
||||
3
tests/sample_data/pug/test/cases/auxiliary/mixins.pug
Normal file
3
tests/sample_data/pug/test/cases/auxiliary/mixins.pug
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
mixin foo()
|
||||
p bar
|
||||
3
tests/sample_data/pug/test/cases/auxiliary/pet.pug
Normal file
3
tests/sample_data/pug/test/cases/auxiliary/pet.pug
Normal file
@@ -0,0 +1,3 @@
|
||||
.pet
|
||||
h1 {{name}}
|
||||
p {{name}} is a {{species}} that is {{age}} old
|
||||
1
tests/sample_data/pug/test/cases/auxiliary/smile.html
Normal file
1
tests/sample_data/pug/test/cases/auxiliary/smile.html
Normal file
@@ -0,0 +1 @@
|
||||
<p>:)</p>
|
||||
4
tests/sample_data/pug/test/cases/auxiliary/window.pug
Normal file
4
tests/sample_data/pug/test/cases/auxiliary/window.pug
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
.window
|
||||
a(href='#').close Close
|
||||
block window-content
|
||||
10
tests/sample_data/pug/test/cases/auxiliary/yield-nested.pug
Normal file
10
tests/sample_data/pug/test/cases/auxiliary/yield-nested.pug
Normal file
@@ -0,0 +1,10 @@
|
||||
html
|
||||
head
|
||||
title
|
||||
body
|
||||
h1 Page
|
||||
#content
|
||||
#content-wrapper
|
||||
yield
|
||||
#footer
|
||||
stuff
|
||||
5
tests/sample_data/pug/test/cases/basic.html
Normal file
5
tests/sample_data/pug/test/cases/basic.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>Title</h1>
|
||||
</body>
|
||||
</html>
|
||||
3
tests/sample_data/pug/test/cases/basic.pug
Normal file
3
tests/sample_data/pug/test/cases/basic.pug
Normal file
@@ -0,0 +1,3 @@
|
||||
html
|
||||
body
|
||||
h1 Title
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user