express-hbs 2.4.2 → 3.0.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/.github/workflows/publish.yml +73 -0
- package/.github/workflows/test.yml +32 -8
- package/.nvmrc +1 -0
- package/.nycrc.json +16 -0
- package/.oxfmtrc.json +19 -0
- package/.oxlintrc.json +32 -0
- package/AGENTS.md +40 -0
- package/LICENSE +1 -1
- package/README.md +51 -22
- package/example/app-layoutsDir.js +32 -38
- package/example/app.js +27 -33
- package/lib/hbs.js +90 -89
- package/lib/resolver.js +10 -9
- package/package.json +29 -22
- package/renovate.json +9 -2
- package/test/apps/async/index.js +54 -41
- package/test/apps/i18n/index.js +9 -6
- package/test/asyncSpecs.js +12 -12
- package/test/cacheSpecs.js +18 -21
- package/test/customExtension.js +15 -15
- package/test/handlebarsSpecs.js +16 -19
- package/test/helperSpecs.js +24 -20
- package/test/helpers.js +3 -3
- package/test/i18nSpecs.js +10 -8
- package/test/issues.js +164 -122
- package/test/layoutSpecs.js +35 -19
- package/test/localTemplateOptions.js +48 -42
- package/test/multiple.js +30 -32
- package/test/nonExpress.js +11 -10
- package/test/optionsSpecs.js +5 -7
- package/test/resolverSpecs.js +54 -0
- package/.eslintrc +0 -42
package/test/apps/async/index.js
CHANGED
|
@@ -9,50 +9,50 @@ var url = require('url');
|
|
|
9
9
|
var pages = [
|
|
10
10
|
{
|
|
11
11
|
id: 1,
|
|
12
|
-
title: 'Title 1'
|
|
12
|
+
title: 'Title 1',
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
id: 2,
|
|
16
|
-
title: 'Title 2'
|
|
16
|
+
title: 'Title 2',
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
id: 3,
|
|
20
|
-
title: 'Title 3'
|
|
21
|
-
}
|
|
22
|
-
]
|
|
20
|
+
title: 'Title 3',
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
23
|
|
|
24
24
|
var comments = [
|
|
25
25
|
{
|
|
26
26
|
id: 1,
|
|
27
27
|
page: 1,
|
|
28
28
|
subject: 'Title 1 Comment 1',
|
|
29
|
-
auther: 'JT'
|
|
29
|
+
auther: 'JT',
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
id: 2,
|
|
33
33
|
page: 1,
|
|
34
34
|
subject: 'Title 1 Comment 2',
|
|
35
|
-
auther: 'Anna'
|
|
35
|
+
auther: 'Anna',
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
id: 3,
|
|
39
39
|
page: 1,
|
|
40
40
|
subject: 'Title 1 Comment 3',
|
|
41
|
-
auther: 'Jane'
|
|
41
|
+
auther: 'Jane',
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
id: 4,
|
|
45
45
|
page: 1,
|
|
46
46
|
subject: 'Title 1 Comment 4',
|
|
47
|
-
auther: 'Bob'
|
|
47
|
+
auther: 'Bob',
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
id: 5,
|
|
51
51
|
page: 4,
|
|
52
52
|
subject: 'This should not show!',
|
|
53
|
-
auther: 'Jill'
|
|
54
|
-
}
|
|
55
|
-
]
|
|
53
|
+
auther: 'Jill',
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
56
|
|
|
57
57
|
function getRandomNumber(min, max) {
|
|
58
58
|
return Math.random() * (max - min) + min;
|
|
@@ -64,9 +64,13 @@ function create(hbs, env) {
|
|
|
64
64
|
var viewsDir = path.join(__dirname, 'views');
|
|
65
65
|
|
|
66
66
|
// Hook in express-hbs and tell it where known directories reside
|
|
67
|
-
app.engine(
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
app.engine(
|
|
68
|
+
'hbs',
|
|
69
|
+
hbs.express4({
|
|
70
|
+
defaultLayout: path.join(viewsDir, 'layout.hbs'),
|
|
71
|
+
restrictLayoutsTo: viewsDir,
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
70
74
|
app.set('view engine', 'hbs');
|
|
71
75
|
app.set('views', viewsDir);
|
|
72
76
|
|
|
@@ -75,7 +79,7 @@ function create(hbs, env) {
|
|
|
75
79
|
app.get('/', function (req, res) {
|
|
76
80
|
res.render('index', {
|
|
77
81
|
message: 'Hello,',
|
|
78
|
-
username: req.cookies.user
|
|
82
|
+
username: req.cookies.user,
|
|
79
83
|
});
|
|
80
84
|
});
|
|
81
85
|
|
|
@@ -83,42 +87,51 @@ function create(hbs, env) {
|
|
|
83
87
|
res.render('failer');
|
|
84
88
|
});
|
|
85
89
|
|
|
86
|
-
hbs.registerAsyncHelper('user', function(username, resultcb) {
|
|
87
|
-
setTimeout(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
hbs.registerAsyncHelper('user', function (username, resultcb) {
|
|
91
|
+
setTimeout(
|
|
92
|
+
function () {
|
|
93
|
+
resultcb(username);
|
|
94
|
+
},
|
|
95
|
+
getRandomNumber(100, 900),
|
|
96
|
+
);
|
|
90
97
|
});
|
|
91
98
|
|
|
92
|
-
hbs.registerAsyncHelper('pages', function(options, resultcb) {
|
|
99
|
+
hbs.registerAsyncHelper('pages', function (options, resultcb) {
|
|
93
100
|
var self = this;
|
|
94
|
-
setTimeout(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
setTimeout(
|
|
102
|
+
function () {
|
|
103
|
+
var result = [];
|
|
104
|
+
for (var i = 0; i < pages.length; i++) {
|
|
105
|
+
options.data.page = pages[i];
|
|
106
|
+
result.push(options.fn.call(self, pages[i], options));
|
|
107
|
+
}
|
|
108
|
+
resultcb(result.join(''));
|
|
109
|
+
},
|
|
110
|
+
getRandomNumber(100, 900),
|
|
111
|
+
);
|
|
102
112
|
});
|
|
103
113
|
|
|
104
|
-
hbs.registerAsyncHelper('comments', function(options, resultcb) {
|
|
114
|
+
hbs.registerAsyncHelper('comments', function (options, resultcb) {
|
|
105
115
|
var self = this;
|
|
106
|
-
setTimeout(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
116
|
+
setTimeout(
|
|
117
|
+
function () {
|
|
118
|
+
var result = [];
|
|
119
|
+
for (var i = 0; i < comments.length; i++) {
|
|
120
|
+
if (options.hash.page === comments[i].page) {
|
|
121
|
+
result.push(options.fn(comments[i]));
|
|
122
|
+
}
|
|
111
123
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
124
|
+
resultcb(result.join(''));
|
|
125
|
+
},
|
|
126
|
+
getRandomNumber(100, 300),
|
|
127
|
+
);
|
|
115
128
|
});
|
|
116
129
|
|
|
117
|
-
hbs.registerAsyncHelper('failer', function(_, resultcb) {
|
|
118
|
-
setTimeout(function() {
|
|
130
|
+
hbs.registerAsyncHelper('failer', function (_, resultcb) {
|
|
131
|
+
setTimeout(function () {
|
|
119
132
|
resultcb(options.fn());
|
|
120
133
|
}, 100);
|
|
121
|
-
})
|
|
134
|
+
});
|
|
122
135
|
|
|
123
136
|
return app;
|
|
124
137
|
}
|
package/test/apps/i18n/index.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
function create(hbs, env) {
|
|
12
11
|
'use strict';
|
|
13
12
|
|
|
@@ -26,13 +25,17 @@ function create(hbs, env) {
|
|
|
26
25
|
i18n.configure({
|
|
27
26
|
locales: ['en', 'fr'],
|
|
28
27
|
cookie: 'locale',
|
|
29
|
-
directory: __dirname + '/locales'
|
|
28
|
+
directory: __dirname + '/locales',
|
|
30
29
|
});
|
|
31
30
|
|
|
32
31
|
// Hook in express-hbs and tell it where known directories reside
|
|
33
|
-
app.engine(
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
app.engine(
|
|
33
|
+
'hbs',
|
|
34
|
+
hbs.express3({
|
|
35
|
+
i18n: i18n,
|
|
36
|
+
restrictLayoutsTo: viewsDir,
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
36
39
|
app.set('view engine', 'hbs');
|
|
37
40
|
app.set('views', viewsDir);
|
|
38
41
|
|
|
@@ -44,7 +47,7 @@ function create(hbs, env) {
|
|
|
44
47
|
|
|
45
48
|
app.get('/', function (req, res) {
|
|
46
49
|
res.render('index', {
|
|
47
|
-
array: [1, 2]
|
|
50
|
+
array: [1, 2],
|
|
48
51
|
});
|
|
49
52
|
});
|
|
50
53
|
|
package/test/asyncSpecs.js
CHANGED
|
@@ -10,7 +10,7 @@ function makeUserRequest(app, user, cb) {
|
|
|
10
10
|
request(app)
|
|
11
11
|
.get('/')
|
|
12
12
|
.set('Cookie', 'user=' + user)
|
|
13
|
-
.end(function(err, res) {
|
|
13
|
+
.end(function (err, res) {
|
|
14
14
|
if (err) cb(err);
|
|
15
15
|
if (res.text.search('Hello, ' + user) <= 0) {
|
|
16
16
|
return cb(new Error('Wrong template send for user ' + user + ': ' + res.text), user);
|
|
@@ -21,18 +21,18 @@ function makeUserRequest(app, user, cb) {
|
|
|
21
21
|
|
|
22
22
|
function requestAll(app, users, cb) {
|
|
23
23
|
var status = {};
|
|
24
|
-
for(var i = 0; i < users.length; i++) {
|
|
24
|
+
for (var i = 0; i < users.length; i++) {
|
|
25
25
|
status[users[i]] = 'Pending';
|
|
26
|
-
makeUserRequest(app, users[i], function(err, user) {
|
|
26
|
+
makeUserRequest(app, users[i], function (err, user) {
|
|
27
27
|
if (err) {
|
|
28
28
|
status[user] = 'Error: ' + err.message;
|
|
29
29
|
} else {
|
|
30
|
-
status[user] = 'Completed'
|
|
30
|
+
status[user] = 'Completed';
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
var checkTimer = setInterval(function() {
|
|
35
|
-
for(var i = 0; i < users.length; i++) {
|
|
34
|
+
var checkTimer = setInterval(function () {
|
|
35
|
+
for (var i = 0; i < users.length; i++) {
|
|
36
36
|
if (status[users[i]] === 'Pending') {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
@@ -42,10 +42,10 @@ function requestAll(app, users, cb) {
|
|
|
42
42
|
}, 100);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
describe('async', function() {
|
|
46
|
-
it('should render all async helpers', function(done) {
|
|
45
|
+
describe('async', function () {
|
|
46
|
+
it('should render all async helpers', function (done) {
|
|
47
47
|
var app = asyncApp.create(hbs.create(), 'production');
|
|
48
|
-
requestAll(app, ['jt','anna','joe','jeff','jane'], function(results) {
|
|
48
|
+
requestAll(app, ['jt', 'anna', 'joe', 'jeff', 'jane'], function (results) {
|
|
49
49
|
assert.equal(results.jt, 'Completed');
|
|
50
50
|
assert.equal(results.anna, 'Completed');
|
|
51
51
|
assert.equal(results.joe, 'Completed');
|
|
@@ -55,14 +55,14 @@ describe('async', function() {
|
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
it('should render nested async helpers', function(done) {
|
|
58
|
+
it('should render nested async helpers', function (done) {
|
|
59
59
|
var app = asyncApp.create(hbs.create(), 'production');
|
|
60
|
-
makeUserRequest(app, 'jt', function(err, user, results) {
|
|
60
|
+
makeUserRequest(app, 'jt', function (err, user, results) {
|
|
61
61
|
if (err) {
|
|
62
62
|
return done(err);
|
|
63
63
|
}
|
|
64
64
|
assert.equal(false, resolver.hasResolvers(results));
|
|
65
|
-
assert.equal(-1, results.search('This should not show!'))
|
|
65
|
+
assert.equal(-1, results.search('This should not show!'));
|
|
66
66
|
done();
|
|
67
67
|
});
|
|
68
68
|
});
|
package/test/cacheSpecs.js
CHANGED
|
@@ -4,7 +4,6 @@ var rewire = require('rewire');
|
|
|
4
4
|
var assert = require('assert');
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Creates instance of example app using an injected version of express-hbs to track the number of times a
|
|
10
9
|
* file is read. Additionally, the $NODE_ENV environment variable may be set.
|
|
@@ -16,7 +15,7 @@ function createApp(env) {
|
|
|
16
15
|
var readCounts = {};
|
|
17
16
|
var hbs = rewire('../lib/hbs');
|
|
18
17
|
hbs.__set__('fs', {
|
|
19
|
-
readFileSync: function(filename, encoding) {
|
|
18
|
+
readFileSync: function (filename, encoding) {
|
|
20
19
|
if (typeof readCounts[filename] === 'undefined') {
|
|
21
20
|
readCounts[filename] = 1;
|
|
22
21
|
} else {
|
|
@@ -26,7 +25,7 @@ function createApp(env) {
|
|
|
26
25
|
return fs.readFileSync(filename, encoding);
|
|
27
26
|
},
|
|
28
27
|
|
|
29
|
-
readFile: function(filename, encoding, cb) {
|
|
28
|
+
readFile: function (filename, encoding, cb) {
|
|
30
29
|
if (typeof readCounts[filename] === 'undefined') {
|
|
31
30
|
readCounts[filename] = 1;
|
|
32
31
|
} else {
|
|
@@ -35,33 +34,31 @@ function createApp(env) {
|
|
|
35
34
|
|
|
36
35
|
fs.readFile(filename, encoding, cb);
|
|
37
36
|
},
|
|
38
|
-
existsSync: function(filename, encoding) {
|
|
37
|
+
existsSync: function (filename, encoding) {
|
|
39
38
|
return fs.existsSync(filename, encoding);
|
|
40
|
-
}
|
|
39
|
+
},
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
// used mocked hbs in example
|
|
44
43
|
var example = require('../example/app');
|
|
45
44
|
var app = example.create(hbs, env);
|
|
46
|
-
return {app: app, readCounts: readCounts};
|
|
45
|
+
return { app: app, readCounts: readCounts };
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
describe('
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
it('should not cache layout in `development`', function(done) {
|
|
48
|
+
describe('express-hbs', function () {
|
|
49
|
+
describe('cache', function () {
|
|
50
|
+
it('should not cache layout in `development`', function (done) {
|
|
54
51
|
var mock = createApp('development');
|
|
55
52
|
|
|
56
53
|
request(mock.app)
|
|
57
54
|
.get('/')
|
|
58
|
-
.end(function(err) {
|
|
55
|
+
.end(function (err) {
|
|
59
56
|
assert.ifError(err);
|
|
60
57
|
|
|
61
58
|
request(mock.app)
|
|
62
59
|
.get('/')
|
|
63
60
|
.expect(/DEFAULT LAYOUT/)
|
|
64
|
-
.end(function(err) {
|
|
61
|
+
.end(function (err) {
|
|
65
62
|
assert.ifError(err);
|
|
66
63
|
|
|
67
64
|
var filename = path.resolve(__dirname, '../example/views/layout/default.hbs');
|
|
@@ -71,19 +68,19 @@ describe('express-hbs', function() {
|
|
|
71
68
|
});
|
|
72
69
|
});
|
|
73
70
|
|
|
74
|
-
it('should cache layout in `production` reading file once', function(done) {
|
|
71
|
+
it('should cache layout in `production` reading file once', function (done) {
|
|
75
72
|
var mock = createApp('production');
|
|
76
73
|
|
|
77
74
|
// reads layout from fs once
|
|
78
75
|
request(mock.app)
|
|
79
76
|
.get('/')
|
|
80
|
-
.end(function(err) {
|
|
77
|
+
.end(function (err) {
|
|
81
78
|
assert.ifError(err);
|
|
82
79
|
|
|
83
80
|
request(mock.app)
|
|
84
81
|
.get('/')
|
|
85
82
|
.expect(/DEFAULT LAYOUT/)
|
|
86
|
-
.end(function(err, res) {
|
|
83
|
+
.end(function (err, res) {
|
|
87
84
|
assert.ifError(err);
|
|
88
85
|
|
|
89
86
|
var filename = path.resolve(__dirname, '../example/views/layout/default.hbs');
|
|
@@ -93,18 +90,18 @@ describe('express-hbs', function() {
|
|
|
93
90
|
});
|
|
94
91
|
});
|
|
95
92
|
|
|
96
|
-
it('should not cache partials in `development`', function(done) {
|
|
93
|
+
it('should not cache partials in `development`', function (done) {
|
|
97
94
|
var mock = createApp('development');
|
|
98
95
|
|
|
99
96
|
request(mock.app)
|
|
100
97
|
.get('/veggies')
|
|
101
98
|
.expect(/just a comment/)
|
|
102
|
-
.end(function(err) {
|
|
99
|
+
.end(function (err) {
|
|
103
100
|
assert.ifError(err);
|
|
104
101
|
request(mock.app)
|
|
105
102
|
.get('/veggies')
|
|
106
103
|
.expect(/just a comment/)
|
|
107
|
-
.end(function(err) {
|
|
104
|
+
.end(function (err) {
|
|
108
105
|
assert.ifError(err);
|
|
109
106
|
|
|
110
107
|
var filename = path.resolve(__dirname, '../example/views/partials/sub/comment.hbs');
|
|
@@ -120,12 +117,12 @@ describe('express-hbs', function() {
|
|
|
120
117
|
request(mock.app)
|
|
121
118
|
.get('/veggies')
|
|
122
119
|
.expect(/just a comment/)
|
|
123
|
-
.end(function(err) {
|
|
120
|
+
.end(function (err) {
|
|
124
121
|
assert.ifError(err);
|
|
125
122
|
request(mock.app)
|
|
126
123
|
.get('/veggies')
|
|
127
124
|
.expect(/just a comment/)
|
|
128
|
-
.end(function(err) {
|
|
125
|
+
.end(function (err) {
|
|
129
126
|
assert.ifError(err);
|
|
130
127
|
|
|
131
128
|
var filename = path.resolve(__dirname, '../example/views/partials/sub/comment.hbs');
|
package/test/customExtension.js
CHANGED
|
@@ -4,32 +4,32 @@ var hbs = require('..');
|
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var H = require('./helpers');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
// MEANJS is using custom extension .server.view.html instead of .hbs
|
|
7
|
+
// MEANJS is using custom extension .server.view.html instead of .hbs
|
|
9
8
|
// https://github.com/meanjs/mean
|
|
10
|
-
describe('custom extension for partials view', function() {
|
|
9
|
+
describe('custom extension for partials view', function () {
|
|
11
10
|
var dirname = path.join(__dirname, 'views/customExtension');
|
|
12
11
|
var render = hbs.create().express4({
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
extname: '.server.view.html',
|
|
13
|
+
partialsDir: dirname + '/partialsDir',
|
|
14
|
+
restrictLayoutsTo: dirname,
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
it('should allow rendering multiple partials with custom extension', function(done) {
|
|
17
|
+
it('should allow rendering multiple partials with custom extension', function (done) {
|
|
18
18
|
function check(err, html) {
|
|
19
19
|
assert.ifError(err);
|
|
20
20
|
assert.equal(
|
|
21
|
-
'<html>' +
|
|
22
|
-
'<subpartial>1</subpartial>' +
|
|
23
|
-
'<partial>1</partial>' +
|
|
24
|
-
'<subpartial>2</subpartial>' +
|
|
25
|
-
'<partial>2</partial>' +
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
'<html>' +
|
|
22
|
+
'<subpartial>1</subpartial>' +
|
|
23
|
+
'<partial>1</partial>' +
|
|
24
|
+
'<subpartial>2</subpartial>' +
|
|
25
|
+
'<partial>2</partial>' +
|
|
26
|
+
'</html>',
|
|
27
|
+
H.stripWs(html),
|
|
28
|
+
);
|
|
28
29
|
done();
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
var options = {cache: true, settings: {views: dirname }};
|
|
32
|
+
var options = { cache: true, settings: { views: dirname } };
|
|
32
33
|
render(dirname + '/template.server.view.html', options, check);
|
|
33
34
|
});
|
|
34
|
-
|
|
35
35
|
});
|
package/test/handlebarsSpecs.js
CHANGED
|
@@ -2,90 +2,87 @@ var request = require('supertest');
|
|
|
2
2
|
var assert = require('assert');
|
|
3
3
|
var hbs = require('..');
|
|
4
4
|
|
|
5
|
-
describe('express-hbs', function() {
|
|
6
|
-
|
|
7
|
-
describe('defaults', function() {
|
|
5
|
+
describe('express-hbs', function () {
|
|
6
|
+
describe('defaults', function () {
|
|
8
7
|
var app;
|
|
9
8
|
|
|
10
|
-
beforeEach(function() {
|
|
9
|
+
beforeEach(function () {
|
|
11
10
|
var example = require('../example/app');
|
|
12
11
|
app = example.create(hbs.create());
|
|
13
12
|
});
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
it('should render using default layout', function(done) {
|
|
14
|
+
it('should render using default layout', function (done) {
|
|
17
15
|
request(app)
|
|
18
16
|
.get('/')
|
|
19
17
|
.expect(/DEFAULT LAYOUT/, done);
|
|
20
18
|
});
|
|
21
19
|
|
|
22
|
-
it('should render layout declared in markup', function(done) {
|
|
20
|
+
it('should render layout declared in markup', function (done) {
|
|
23
21
|
request(app)
|
|
24
22
|
.get('/fruits')
|
|
25
23
|
.expect(/DECLARATIVE LAYOUT/, done);
|
|
26
24
|
});
|
|
27
25
|
|
|
28
|
-
it('should render nested declarative layouts correctly', function(done) {
|
|
26
|
+
it('should render nested declarative layouts correctly', function (done) {
|
|
29
27
|
request(app)
|
|
30
28
|
.get('/fruits/apple')
|
|
31
29
|
.expect(/DECLARATIVE LAYOUT/)
|
|
32
30
|
.expect(/NESTED LAYOUT/, done);
|
|
33
31
|
});
|
|
34
32
|
|
|
35
|
-
it('should render layout specified as locals', function(done) {
|
|
33
|
+
it('should render layout specified as locals', function (done) {
|
|
36
34
|
request(app)
|
|
37
35
|
.get('/veggies')
|
|
38
36
|
.expect(/PROGRAMMATIC LAYOUT/, done);
|
|
39
37
|
});
|
|
40
38
|
|
|
41
|
-
it('should render nested layouts correctly when first layout is specified as locals', function(done) {
|
|
39
|
+
it('should render nested layouts correctly when first layout is specified as locals', function (done) {
|
|
42
40
|
request(app)
|
|
43
41
|
.get('/veggies/carrot')
|
|
44
42
|
.expect(/PROGRAMMATIC LAYOUT/)
|
|
45
43
|
.expect(/NESTED LAYOUT/, done);
|
|
46
44
|
});
|
|
47
45
|
|
|
48
|
-
it('should render partial', function(done) {
|
|
46
|
+
it('should render partial', function (done) {
|
|
49
47
|
request(app)
|
|
50
48
|
.get('/veggies')
|
|
51
49
|
.expect(/jquery\.js/)
|
|
52
50
|
.expect(/Other partial/, done);
|
|
53
51
|
});
|
|
54
52
|
|
|
55
|
-
it('should render sub partial', function(done) {
|
|
53
|
+
it('should render sub partial', function (done) {
|
|
56
54
|
request(app)
|
|
57
55
|
.get('/veggies')
|
|
58
56
|
.expect(/just a comment/, done);
|
|
59
57
|
});
|
|
60
58
|
|
|
61
|
-
it('should render block', function(done) {
|
|
59
|
+
it('should render block', function (done) {
|
|
62
60
|
request(app)
|
|
63
61
|
.get('/')
|
|
64
62
|
.expect(/color: blue/, done);
|
|
65
63
|
});
|
|
66
64
|
|
|
67
|
-
it('should render block default content', function(done) {
|
|
65
|
+
it('should render block default content', function (done) {
|
|
68
66
|
request(app)
|
|
69
67
|
.get('/')
|
|
70
68
|
.expect(/Default block content/, done);
|
|
71
69
|
});
|
|
72
70
|
|
|
73
|
-
it('should render block content instead of default content when contentFor is declared', function(done) {
|
|
71
|
+
it('should render block content instead of default content when contentFor is declared', function (done) {
|
|
74
72
|
request(app)
|
|
75
73
|
.get('/replace')
|
|
76
74
|
.expect(/Non-default block content/, done);
|
|
77
75
|
});
|
|
78
76
|
|
|
79
|
-
it('should replace {{body}}', function(done) {
|
|
77
|
+
it('should replace {{body}}', function (done) {
|
|
80
78
|
request(app)
|
|
81
79
|
.get('/')
|
|
82
80
|
.expect(/Vegetables/, done);
|
|
83
81
|
});
|
|
84
|
-
|
|
85
82
|
});
|
|
86
83
|
|
|
87
|
-
describe('instances', function() {
|
|
88
|
-
it('should create isolated instances', function() {
|
|
84
|
+
describe('instances', function () {
|
|
85
|
+
it('should create isolated instances', function () {
|
|
89
86
|
var hbs2 = hbs.create();
|
|
90
87
|
var hbs3 = hbs.create();
|
|
91
88
|
|
package/test/helperSpecs.js
CHANGED
|
@@ -2,53 +2,57 @@ var assert = require('assert');
|
|
|
2
2
|
var hbs = require('..');
|
|
3
3
|
var H = require('./helpers');
|
|
4
4
|
|
|
5
|
-
describe('helpers', function() {
|
|
6
|
-
|
|
7
|
-
describe('sync', function() {
|
|
5
|
+
describe('helpers', function () {
|
|
6
|
+
describe('sync', function () {
|
|
8
7
|
var dirname = __dirname + '/views/helpers';
|
|
9
8
|
|
|
10
9
|
function sync(s, options) {
|
|
11
|
-
return new hbs.SafeString(
|
|
10
|
+
return new hbs.SafeString('-sync-' + s);
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
it
|
|
13
|
+
it('should register functions', function (done) {
|
|
15
14
|
var hb = hbs.create();
|
|
16
|
-
hb.registerHelper(
|
|
15
|
+
hb.registerHelper('sync', sync);
|
|
17
16
|
var render = hb.express3({
|
|
18
|
-
viewsDir: dirname
|
|
17
|
+
viewsDir: dirname,
|
|
18
|
+
restrictLayoutsTo: dirname,
|
|
19
19
|
});
|
|
20
20
|
var locals = H.createLocals('express3', dirname);
|
|
21
21
|
|
|
22
|
-
render(dirname + '/home/index.hbs', locals, function(err, html) {
|
|
22
|
+
render(dirname + '/home/index.hbs', locals, function (err, html) {
|
|
23
23
|
assert.equal('<default>index-sync-index</default>', H.stripWs(html));
|
|
24
24
|
done();
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
describe('async', function() {
|
|
29
|
+
describe('async', function () {
|
|
30
30
|
var dirname = __dirname + '/views/helpers';
|
|
31
|
-
it
|
|
31
|
+
it('should register functions', function (done) {
|
|
32
32
|
var hb = hbs.create();
|
|
33
33
|
function async(s, cb) {
|
|
34
|
-
setTimeout(
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
setTimeout(
|
|
35
|
+
function () {
|
|
36
|
+
cb(new hb.SafeString('-async-' + s));
|
|
37
|
+
},
|
|
38
|
+
Math.floor(Math.random() * 10 + 1),
|
|
39
|
+
);
|
|
37
40
|
}
|
|
38
|
-
hb.registerAsyncHelper(
|
|
41
|
+
hb.registerAsyncHelper('async', async);
|
|
39
42
|
|
|
40
43
|
var render = hb.express3({
|
|
41
|
-
viewsDir: dirname
|
|
44
|
+
viewsDir: dirname,
|
|
45
|
+
restrictLayoutsTo: dirname,
|
|
42
46
|
});
|
|
43
47
|
var locals = H.createLocals('express3', dirname);
|
|
44
48
|
|
|
45
|
-
render(dirname + '/home/async.hbs', locals, function(err, html) {
|
|
46
|
-
assert.equal(
|
|
49
|
+
render(dirname + '/home/async.hbs', locals, function (err, html) {
|
|
50
|
+
assert.equal(
|
|
51
|
+
'<default>asynctemplate-async-foo-async-bar-async-bah-async-baz</default>',
|
|
52
|
+
H.stripWs(html),
|
|
53
|
+
);
|
|
47
54
|
done();
|
|
48
55
|
});
|
|
49
56
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
57
|
});
|
|
53
|
-
|
|
54
58
|
});
|
package/test/helpers.js
CHANGED
|
@@ -7,7 +7,7 @@ function createLocals(which, viewsDir, locals) {
|
|
|
7
7
|
var opts = {};
|
|
8
8
|
if (which === 'express3' || which === 'express4') {
|
|
9
9
|
opts.settings = {
|
|
10
|
-
views: viewsDir
|
|
10
|
+
views: viewsDir,
|
|
11
11
|
};
|
|
12
12
|
opts.cache = process.env.NODE_ENV === 'production';
|
|
13
13
|
for (var k in locals) {
|
|
@@ -20,5 +20,5 @@ function createLocals(which, viewsDir, locals) {
|
|
|
20
20
|
|
|
21
21
|
module.exports = {
|
|
22
22
|
createLocals: createLocals,
|
|
23
|
-
stripWs: stripWs
|
|
24
|
-
};
|
|
23
|
+
stripWs: stripWs,
|
|
24
|
+
};
|