express-hbs 2.5.0 → 4.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/LICENSE +1 -1
- package/README.md +50 -22
- package/lib/hbs.js +89 -91
- package/lib/resolver.js +10 -9
- package/package.json +32 -21
- package/.editorconfig +0 -8
- package/.eslintrc +0 -42
- package/.github/workflows/test.yml +0 -24
- package/.jsbeautifyrc +0 -17
- package/SECURITY.md +0 -9
- package/example/app-layoutsDir.js +0 -106
- package/example/app.js +0 -110
- package/example/public/css/style.css +0 -17
- package/example/views/fruits/details-layoutsDir.hbs +0 -3
- package/example/views/fruits/details.hbs +0 -4
- package/example/views/fruits/index-layoutsDir.hbs +0 -20
- package/example/views/fruits/index.hbs +0 -20
- package/example/views/index.hbs +0 -34
- package/example/views/layout/default.hbs +0 -13
- package/example/views/layout/fruit-details.hbs +0 -9
- package/example/views/layout/fruits.hbs +0 -6
- package/example/views/layout/html-struct.hbs +0 -21
- package/example/views/layout/veggie-details.hbs +0 -9
- package/example/views/layout/veggie.hbs +0 -6
- package/example/views/partials/scripts.hbs +0 -5
- package/example/views/partials/sub/comment.hbs +0 -1
- package/example/views/partials-other/other.hbs +0 -1
- package/example/views/replace.hbs +0 -6
- package/example/views/tos.txt +0 -3
- package/example/views/veggies/details.hbs +0 -1
- package/example/views/veggies.hbs +0 -17
- package/renovate.json +0 -6
- package/test/apps/async/index.js +0 -127
- package/test/apps/async/views/failer.hbs +0 -4
- package/test/apps/async/views/index.hbs +0 -16
- package/test/apps/async/views/layout.hbs +0 -1
- package/test/apps/i18n/index.js +0 -55
- package/test/apps/i18n/locales/en.json +0 -8
- package/test/apps/i18n/locales/fr.json +0 -8
- package/test/apps/i18n/views/index.hbs +0 -3
- package/test/asyncSpecs.js +0 -69
- package/test/cacheSpecs.js +0 -138
- package/test/customExtension.js +0 -36
- package/test/handlebarsSpecs.js +0 -95
- package/test/helperSpecs.js +0 -56
- package/test/helpers.js +0 -24
- package/test/i18nSpecs.js +0 -34
- package/test/issues/144/index.hbs +0 -1
- package/test/issues/153/index.hbs +0 -3
- package/test/issues/21/views/index.hbs +0 -1
- package/test/issues/21/views/layouts/default.hbs +0 -1
- package/test/issues/21/views/layouts/sub/child.hbs +0 -1
- package/test/issues/21/views/sub/relativeLayout.hbs +0 -1
- package/test/issues/21/views/sub/sub.hbs +0 -1
- package/test/issues/21/views/useLayoutInDir.hbs +0 -1
- package/test/issues/22/layout1.hbs +0 -1
- package/test/issues/22/layout2.hbs +0 -1
- package/test/issues/22/template.hbs +0 -1
- package/test/issues/23/empty.hbs +0 -0
- package/test/issues/23/emptyComment.hbs +0 -1
- package/test/issues/23/emptyPartial.hbs +0 -1
- package/test/issues/23/index.hbs +0 -4
- package/test/issues/23/layout.hbs +0 -1
- package/test/issues/23/partials/custom/comment-only.hbs +0 -1
- package/test/issues/23/partials/custom/empty.hbs +0 -0
- package/test/issues/23/partials/hello.hbs +0 -1
- package/test/issues/49/error.hbs +0 -1
- package/test/issues/49/front/error.hbs +0 -1
- package/test/issues/49/index.hbs +0 -2
- package/test/issues/49/layouts/default.hbs +0 -1
- package/test/issues/49/partial.hbs +0 -1
- package/test/issues/49/partials/partial-error.hbs +0 -1
- package/test/issues/53/default.hbs +0 -15
- package/test/issues/53/index.hbs +0 -7
- package/test/issues/53/partials/.gitkeep +0 -0
- package/test/issues/59/index.hbs +0 -2
- package/test/issues/62/basic.hbs +0 -2
- package/test/issues/62/block.hbs +0 -11
- package/test/issues/73/index.hbs +0 -5
- package/test/issues/73/partials/partial.hbs +0 -6
- package/test/issues/76/mypartial.hbs +0 -0
- package/test/issues/84/index.hbs +0 -1
- package/test/issues/84/partials/abc/def/ghi/test.hbs +0 -1
- package/test/issues.js +0 -476
- package/test/layoutSpecs.js +0 -118
- package/test/localTemplateOptions/data-access-template.hbs +0 -1
- package/test/localTemplateOptions/template.hbs +0 -1
- package/test/localTemplateOptions.js +0 -127
- package/test/multiple.js +0 -119
- package/test/nonExpress.js +0 -37
- package/test/optionsSpecs.js +0 -24
- package/test/views/beautify/expected.hbs +0 -9
- package/test/views/beautify/index.hbs +0 -2
- package/test/views/customExtension/layout.server.view.html +0 -1
- package/test/views/customExtension/partialsDir/partial1.server.view.html +0 -1
- package/test/views/customExtension/partialsDir/partial2.server.view.html +0 -1
- package/test/views/customExtension/partialsDir/subs/subPartial1.server.view.html +0 -1
- package/test/views/customExtension/partialsDir/subs/subPartial2.server.view.html +0 -1
- package/test/views/customExtension/template.server.view.html +0 -5
- package/test/views/disableLayoutDirective/aside.hbs +0 -1
- package/test/views/disableLayoutDirective/index.hbs +0 -2
- package/test/views/disableLayoutDirective/layouts/default.hbs +0 -1
- package/test/views/helpers/home/async.hbs +0 -6
- package/test/views/helpers/home/index.hbs +0 -3
- package/test/views/helpers/layouts/default.hbs +0 -1
- package/test/views/multiple/views1/collide.hbs +0 -1
- package/test/views/multiple/views1/error.hbs +0 -1
- package/test/views/multiple/views1/test1.hbs +0 -1
- package/test/views/multiple/views2/collide.hbs +0 -1
- package/test/views/multiple/views2/error.hbs +0 -1
- package/test/views/multiple/views2/test2.hbs +0 -1
- package/test/views/viewsDir/layouts/default.hbs +0 -1
- package/test/views/viewsDir/sub/directive.hbs +0 -2
- package/test/views/viewsDir/sub/lay.hbs +0 -1
package/test/apps/async/index.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var express = require('express');
|
|
4
|
-
var cookieParser = require('cookie-parser');
|
|
5
|
-
var fs = require('fs');
|
|
6
|
-
var path = require('path');
|
|
7
|
-
var url = require('url');
|
|
8
|
-
|
|
9
|
-
var pages = [
|
|
10
|
-
{
|
|
11
|
-
id: 1,
|
|
12
|
-
title: 'Title 1'
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
id: 2,
|
|
16
|
-
title: 'Title 2'
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
id: 3,
|
|
20
|
-
title: 'Title 3'
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
var comments = [
|
|
25
|
-
{
|
|
26
|
-
id: 1,
|
|
27
|
-
page: 1,
|
|
28
|
-
subject: 'Title 1 Comment 1',
|
|
29
|
-
auther: 'JT'
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: 2,
|
|
33
|
-
page: 1,
|
|
34
|
-
subject: 'Title 1 Comment 2',
|
|
35
|
-
auther: 'Anna'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: 3,
|
|
39
|
-
page: 1,
|
|
40
|
-
subject: 'Title 1 Comment 3',
|
|
41
|
-
auther: 'Jane'
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
id: 4,
|
|
45
|
-
page: 1,
|
|
46
|
-
subject: 'Title 1 Comment 4',
|
|
47
|
-
auther: 'Bob'
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
id: 5,
|
|
51
|
-
page: 4,
|
|
52
|
-
subject: 'This should not show!',
|
|
53
|
-
auther: 'Jill'
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
|
|
57
|
-
function getRandomNumber(min, max) {
|
|
58
|
-
return Math.random() * (max - min) + min;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function create(hbs, env) {
|
|
62
|
-
if (env) process.env.NODE_ENV = env;
|
|
63
|
-
var app = express();
|
|
64
|
-
var viewsDir = path.join(__dirname, 'views');
|
|
65
|
-
|
|
66
|
-
// Hook in express-hbs and tell it where known directories reside
|
|
67
|
-
app.engine('hbs', hbs.express4({
|
|
68
|
-
defaultLayout: path.join(viewsDir, 'layout.hbs'),
|
|
69
|
-
restrictLayoutsTo: viewsDir
|
|
70
|
-
}));
|
|
71
|
-
app.set('view engine', 'hbs');
|
|
72
|
-
app.set('views', viewsDir);
|
|
73
|
-
|
|
74
|
-
app.use(cookieParser());
|
|
75
|
-
|
|
76
|
-
app.get('/', function (req, res) {
|
|
77
|
-
res.render('index', {
|
|
78
|
-
message: 'Hello,',
|
|
79
|
-
username: req.cookies.user
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
app.get('/fail', function (req, res) {
|
|
84
|
-
res.render('failer');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
hbs.registerAsyncHelper('user', function(username, resultcb) {
|
|
88
|
-
setTimeout(function() {
|
|
89
|
-
resultcb(username);
|
|
90
|
-
}, getRandomNumber(100, 900))
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
hbs.registerAsyncHelper('pages', function(options, resultcb) {
|
|
94
|
-
var self = this;
|
|
95
|
-
setTimeout(function() {
|
|
96
|
-
var result = [];
|
|
97
|
-
for(var i = 0; i < pages.length; i++) {
|
|
98
|
-
options.data.page = pages[i];
|
|
99
|
-
result.push(options.fn.call(self, pages[i], options));
|
|
100
|
-
}
|
|
101
|
-
resultcb(result.join(''));
|
|
102
|
-
}, getRandomNumber(100, 900))
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
hbs.registerAsyncHelper('comments', function(options, resultcb) {
|
|
106
|
-
var self = this;
|
|
107
|
-
setTimeout(function() {
|
|
108
|
-
var result = [];
|
|
109
|
-
for(var i = 0; i < comments.length; i++) {
|
|
110
|
-
if (options.hash.page === comments[i].page) {
|
|
111
|
-
result.push(options.fn(comments[i]));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
resultcb(result.join(''));
|
|
115
|
-
}, getRandomNumber(100, 300))
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
hbs.registerAsyncHelper('failer', function(_, resultcb) {
|
|
119
|
-
setTimeout(function() {
|
|
120
|
-
resultcb(options.fn());
|
|
121
|
-
}, 100);
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
return app;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
exports.create = create;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{{#contentFor "title"}}
|
|
2
|
-
{{message}} {{{user username}}}
|
|
3
|
-
{{/contentFor}}
|
|
4
|
-
<span id="text">This should welcome {{username}}.</span>
|
|
5
|
-
<div class="pages">
|
|
6
|
-
{{#pages filter="tags:test"}}
|
|
7
|
-
<div class="page">
|
|
8
|
-
<span class="title">{{title}}</title>
|
|
9
|
-
<div class="top-comments">
|
|
10
|
-
{{#comments top="3" page=id}}
|
|
11
|
-
<span class="subject">{{subject}}</span>-<span class="auther">{{auther}}</span>
|
|
12
|
-
{{/comments}}
|
|
13
|
-
</div>
|
|
14
|
-
</div>
|
|
15
|
-
{{/pages}}
|
|
16
|
-
</div>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<html><title>{{{block "title"}}}</title><body>{{{body}}}</body></html>
|
package/test/apps/i18n/index.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This example is intended to show a cookie usage in express setup
|
|
3
|
-
* with handlebars (hbs) template engine and also to be run
|
|
4
|
-
* as integration test for concurrency issues.
|
|
5
|
-
*
|
|
6
|
-
* Please remove setTimeout(), if you intend to use it as a blueprint!
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function create(hbs, env) {
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
if (env) process.env.NODE_ENV = env;
|
|
15
|
-
|
|
16
|
-
var express = require('express');
|
|
17
|
-
var cookieParser = require('cookie-parser');
|
|
18
|
-
var app = express();
|
|
19
|
-
var fs = require('fs');
|
|
20
|
-
var path = require('path');
|
|
21
|
-
var viewsDir = __dirname + '/views';
|
|
22
|
-
var i18n = require('i18n');
|
|
23
|
-
var url = require('url');
|
|
24
|
-
|
|
25
|
-
// minimal config
|
|
26
|
-
i18n.configure({
|
|
27
|
-
locales: ['en', 'fr'],
|
|
28
|
-
cookie: 'locale',
|
|
29
|
-
directory: __dirname + '/locales'
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// Hook in express-hbs and tell it where known directories reside
|
|
33
|
-
app.engine('hbs', hbs.express3({
|
|
34
|
-
i18n: i18n,
|
|
35
|
-
restrictLayoutsTo: viewsDir
|
|
36
|
-
}));
|
|
37
|
-
app.set('view engine', 'hbs');
|
|
38
|
-
app.set('views', viewsDir);
|
|
39
|
-
|
|
40
|
-
// you'll need cookies
|
|
41
|
-
app.use(cookieParser());
|
|
42
|
-
|
|
43
|
-
// init i18n module for this loop
|
|
44
|
-
app.use(i18n.init);
|
|
45
|
-
|
|
46
|
-
app.get('/', function (req, res) {
|
|
47
|
-
res.render('index', {
|
|
48
|
-
array: [1, 2]
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
return app;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
exports.create = create;
|
package/test/asyncSpecs.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
'use stirct';
|
|
2
|
-
|
|
3
|
-
var request = require('supertest');
|
|
4
|
-
var assert = require('assert');
|
|
5
|
-
var hbs = require('..');
|
|
6
|
-
var asyncApp = require('./apps/async');
|
|
7
|
-
var resolver = require('../lib/resolver');
|
|
8
|
-
|
|
9
|
-
function makeUserRequest(app, user, cb) {
|
|
10
|
-
request(app)
|
|
11
|
-
.get('/')
|
|
12
|
-
.set('Cookie', 'user=' + user)
|
|
13
|
-
.end(function(err, res) {
|
|
14
|
-
if (err) cb(err);
|
|
15
|
-
if (res.text.search('Hello, ' + user) <= 0) {
|
|
16
|
-
return cb(new Error('Wrong template send for user ' + user + ': ' + res.text), user);
|
|
17
|
-
}
|
|
18
|
-
return cb(null, user, res.text);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function requestAll(app, users, cb) {
|
|
23
|
-
var status = {};
|
|
24
|
-
for(var i = 0; i < users.length; i++) {
|
|
25
|
-
status[users[i]] = 'Pending';
|
|
26
|
-
makeUserRequest(app, users[i], function(err, user) {
|
|
27
|
-
if (err) {
|
|
28
|
-
status[user] = 'Error: ' + err.message;
|
|
29
|
-
} else {
|
|
30
|
-
status[user] = 'Completed'
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
var checkTimer = setInterval(function() {
|
|
35
|
-
for(var i = 0; i < users.length; i++) {
|
|
36
|
-
if (status[users[i]] === 'Pending') {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
clearInterval(checkTimer);
|
|
41
|
-
cb(status);
|
|
42
|
-
}, 100);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
describe('async', function() {
|
|
46
|
-
it('should render all async helpers', function(done) {
|
|
47
|
-
var app = asyncApp.create(hbs.create(), 'production');
|
|
48
|
-
requestAll(app, ['jt','anna','joe','jeff','jane'], function(results) {
|
|
49
|
-
assert.equal(results.jt, 'Completed');
|
|
50
|
-
assert.equal(results.anna, 'Completed');
|
|
51
|
-
assert.equal(results.joe, 'Completed');
|
|
52
|
-
assert.equal(results.jeff, 'Completed');
|
|
53
|
-
assert.equal(results.jane, 'Completed');
|
|
54
|
-
done();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should render nested async helpers', function(done) {
|
|
59
|
-
var app = asyncApp.create(hbs.create(), 'production');
|
|
60
|
-
makeUserRequest(app, 'jt', function(err, user, results) {
|
|
61
|
-
if (err) {
|
|
62
|
-
return done(err);
|
|
63
|
-
}
|
|
64
|
-
assert.equal(false, resolver.hasResolvers(results));
|
|
65
|
-
assert.equal(-1, results.search('This should not show!'))
|
|
66
|
-
done();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
package/test/cacheSpecs.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
var request = require('supertest');
|
|
2
|
-
var path = require('path');
|
|
3
|
-
var rewire = require('rewire');
|
|
4
|
-
var assert = require('assert');
|
|
5
|
-
var fs = require('fs');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Creates instance of example app using an injected version of express-hbs to track the number of times a
|
|
10
|
-
* file is read. Additionally, the $NODE_ENV environment variable may be set.
|
|
11
|
-
*
|
|
12
|
-
* @param env
|
|
13
|
-
* @returns {{app: hbs, readCounts: {}}}
|
|
14
|
-
*/
|
|
15
|
-
function createApp(env) {
|
|
16
|
-
var readCounts = {};
|
|
17
|
-
var hbs = rewire('../lib/hbs');
|
|
18
|
-
hbs.__set__('fs', {
|
|
19
|
-
readFileSync: function(filename, encoding) {
|
|
20
|
-
if (typeof readCounts[filename] === 'undefined') {
|
|
21
|
-
readCounts[filename] = 1;
|
|
22
|
-
} else {
|
|
23
|
-
readCounts[filename] += 1;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return fs.readFileSync(filename, encoding);
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
readFile: function(filename, encoding, cb) {
|
|
30
|
-
if (typeof readCounts[filename] === 'undefined') {
|
|
31
|
-
readCounts[filename] = 1;
|
|
32
|
-
} else {
|
|
33
|
-
readCounts[filename] += 1;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
fs.readFile(filename, encoding, cb);
|
|
37
|
-
},
|
|
38
|
-
existsSync: function(filename, encoding) {
|
|
39
|
-
return fs.existsSync(filename, encoding);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// used mocked hbs in example
|
|
44
|
-
var example = require('../example/app');
|
|
45
|
-
var app = example.create(hbs, env);
|
|
46
|
-
return {app: app, readCounts: readCounts};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
describe('express-hbs', function() {
|
|
51
|
-
describe('cache', function() {
|
|
52
|
-
|
|
53
|
-
it('should not cache layout in `development`', function(done) {
|
|
54
|
-
var mock = createApp('development');
|
|
55
|
-
|
|
56
|
-
request(mock.app)
|
|
57
|
-
.get('/')
|
|
58
|
-
.end(function(err) {
|
|
59
|
-
assert.ifError(err);
|
|
60
|
-
|
|
61
|
-
request(mock.app)
|
|
62
|
-
.get('/')
|
|
63
|
-
.expect(/DEFAULT LAYOUT/)
|
|
64
|
-
.end(function(err) {
|
|
65
|
-
assert.ifError(err);
|
|
66
|
-
|
|
67
|
-
var filename = path.resolve(__dirname, '../example/views/layout/default.hbs');
|
|
68
|
-
assert.equal(mock.readCounts[filename], 2);
|
|
69
|
-
done();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should cache layout in `production` reading file once', function(done) {
|
|
75
|
-
var mock = createApp('production');
|
|
76
|
-
|
|
77
|
-
// reads layout from fs once
|
|
78
|
-
request(mock.app)
|
|
79
|
-
.get('/')
|
|
80
|
-
.end(function(err) {
|
|
81
|
-
assert.ifError(err);
|
|
82
|
-
|
|
83
|
-
request(mock.app)
|
|
84
|
-
.get('/')
|
|
85
|
-
.expect(/DEFAULT LAYOUT/)
|
|
86
|
-
.end(function(err, res) {
|
|
87
|
-
assert.ifError(err);
|
|
88
|
-
|
|
89
|
-
var filename = path.resolve(__dirname, '../example/views/layout/default.hbs');
|
|
90
|
-
assert.equal(mock.readCounts[filename], 1);
|
|
91
|
-
done();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should not cache partials in `development`', function(done) {
|
|
97
|
-
var mock = createApp('development');
|
|
98
|
-
|
|
99
|
-
request(mock.app)
|
|
100
|
-
.get('/veggies')
|
|
101
|
-
.expect(/just a comment/)
|
|
102
|
-
.end(function(err) {
|
|
103
|
-
assert.ifError(err);
|
|
104
|
-
request(mock.app)
|
|
105
|
-
.get('/veggies')
|
|
106
|
-
.expect(/just a comment/)
|
|
107
|
-
.end(function(err) {
|
|
108
|
-
assert.ifError(err);
|
|
109
|
-
|
|
110
|
-
var filename = path.resolve(__dirname, '../example/views/partials/sub/comment.hbs');
|
|
111
|
-
assert.equal(mock.readCounts[filename], 2);
|
|
112
|
-
done();
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should cache partials in `production', function (done) {
|
|
118
|
-
var mock = createApp('production');
|
|
119
|
-
|
|
120
|
-
request(mock.app)
|
|
121
|
-
.get('/veggies')
|
|
122
|
-
.expect(/just a comment/)
|
|
123
|
-
.end(function(err) {
|
|
124
|
-
assert.ifError(err);
|
|
125
|
-
request(mock.app)
|
|
126
|
-
.get('/veggies')
|
|
127
|
-
.expect(/just a comment/)
|
|
128
|
-
.end(function(err) {
|
|
129
|
-
assert.ifError(err);
|
|
130
|
-
|
|
131
|
-
var filename = path.resolve(__dirname, '../example/views/partials/sub/comment.hbs');
|
|
132
|
-
assert.equal(mock.readCounts[filename], 1);
|
|
133
|
-
done();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|
package/test/customExtension.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var assert = require('assert');
|
|
3
|
-
var hbs = require('..');
|
|
4
|
-
var path = require('path');
|
|
5
|
-
var H = require('./helpers');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// MEANJS is using custom extension .server.view.html instead of .hbs
|
|
9
|
-
// https://github.com/meanjs/mean
|
|
10
|
-
describe('custom extension for partials view', function() {
|
|
11
|
-
var dirname = path.join(__dirname, 'views/customExtension');
|
|
12
|
-
var render = hbs.create().express4({
|
|
13
|
-
extname: '.server.view.html',
|
|
14
|
-
partialsDir: dirname + '/partialsDir',
|
|
15
|
-
restrictLayoutsTo: dirname
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should allow rendering multiple partials with custom extension', function(done) {
|
|
19
|
-
function check(err, html) {
|
|
20
|
-
assert.ifError(err);
|
|
21
|
-
assert.equal(
|
|
22
|
-
'<html>' +
|
|
23
|
-
'<subpartial>1</subpartial>' +
|
|
24
|
-
'<partial>1</partial>' +
|
|
25
|
-
'<subpartial>2</subpartial>' +
|
|
26
|
-
'<partial>2</partial>' +
|
|
27
|
-
'</html>',
|
|
28
|
-
H.stripWs(html));
|
|
29
|
-
done();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var options = {cache: true, settings: {views: dirname }};
|
|
33
|
-
render(dirname + '/template.server.view.html', options, check);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
});
|
package/test/handlebarsSpecs.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
var request = require('supertest');
|
|
2
|
-
var assert = require('assert');
|
|
3
|
-
var hbs = require('..');
|
|
4
|
-
|
|
5
|
-
describe('express-hbs', function() {
|
|
6
|
-
|
|
7
|
-
describe('defaults', function() {
|
|
8
|
-
var app;
|
|
9
|
-
|
|
10
|
-
beforeEach(function() {
|
|
11
|
-
var example = require('../example/app');
|
|
12
|
-
app = example.create(hbs.create());
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
it('should render using default layout', function(done) {
|
|
17
|
-
request(app)
|
|
18
|
-
.get('/')
|
|
19
|
-
.expect(/DEFAULT LAYOUT/, done);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should render layout declared in markup', function(done) {
|
|
23
|
-
request(app)
|
|
24
|
-
.get('/fruits')
|
|
25
|
-
.expect(/DECLARATIVE LAYOUT/, done);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should render nested declarative layouts correctly', function(done) {
|
|
29
|
-
request(app)
|
|
30
|
-
.get('/fruits/apple')
|
|
31
|
-
.expect(/DECLARATIVE LAYOUT/)
|
|
32
|
-
.expect(/NESTED LAYOUT/, done);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should render layout specified as locals', function(done) {
|
|
36
|
-
request(app)
|
|
37
|
-
.get('/veggies')
|
|
38
|
-
.expect(/PROGRAMMATIC LAYOUT/, done);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should render nested layouts correctly when first layout is specified as locals', function(done) {
|
|
42
|
-
request(app)
|
|
43
|
-
.get('/veggies/carrot')
|
|
44
|
-
.expect(/PROGRAMMATIC LAYOUT/)
|
|
45
|
-
.expect(/NESTED LAYOUT/, done);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should render partial', function(done) {
|
|
49
|
-
request(app)
|
|
50
|
-
.get('/veggies')
|
|
51
|
-
.expect(/jquery\.js/)
|
|
52
|
-
.expect(/Other partial/, done);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should render sub partial', function(done) {
|
|
56
|
-
request(app)
|
|
57
|
-
.get('/veggies')
|
|
58
|
-
.expect(/just a comment/, done);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should render block', function(done) {
|
|
62
|
-
request(app)
|
|
63
|
-
.get('/')
|
|
64
|
-
.expect(/color: blue/, done);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should render block default content', function(done) {
|
|
68
|
-
request(app)
|
|
69
|
-
.get('/')
|
|
70
|
-
.expect(/Default block content/, done);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should render block content instead of default content when contentFor is declared', function(done) {
|
|
74
|
-
request(app)
|
|
75
|
-
.get('/replace')
|
|
76
|
-
.expect(/Non-default block content/, done);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should replace {{body}}', function(done) {
|
|
80
|
-
request(app)
|
|
81
|
-
.get('/')
|
|
82
|
-
.expect(/Vegetables/, done);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('instances', function() {
|
|
88
|
-
it('should create isolated instances', function() {
|
|
89
|
-
var hbs2 = hbs.create();
|
|
90
|
-
var hbs3 = hbs.create();
|
|
91
|
-
|
|
92
|
-
assert(hbs !== hbs2 && hbs !== hbs3 && hbs2 !== hbs3);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
package/test/helperSpecs.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
var assert = require('assert');
|
|
2
|
-
var hbs = require('..');
|
|
3
|
-
var H = require('./helpers');
|
|
4
|
-
|
|
5
|
-
describe('helpers', function() {
|
|
6
|
-
|
|
7
|
-
describe('sync', function() {
|
|
8
|
-
var dirname = __dirname + '/views/helpers';
|
|
9
|
-
|
|
10
|
-
function sync(s, options) {
|
|
11
|
-
return new hbs.SafeString("-sync-" + s);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
it ('should register functions', function(done) {
|
|
15
|
-
var hb = hbs.create();
|
|
16
|
-
hb.registerHelper("sync", sync);
|
|
17
|
-
var render = hb.express3({
|
|
18
|
-
viewsDir: dirname,
|
|
19
|
-
restrictLayoutsTo: dirname
|
|
20
|
-
});
|
|
21
|
-
var locals = H.createLocals('express3', dirname);
|
|
22
|
-
|
|
23
|
-
render(dirname + '/home/index.hbs', locals, function(err, html) {
|
|
24
|
-
assert.equal('<default>index-sync-index</default>', H.stripWs(html));
|
|
25
|
-
done();
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('async', function() {
|
|
31
|
-
var dirname = __dirname + '/views/helpers';
|
|
32
|
-
it ('should register functions', function(done) {
|
|
33
|
-
var hb = hbs.create();
|
|
34
|
-
function async(s, cb) {
|
|
35
|
-
setTimeout(function() {
|
|
36
|
-
cb(new hb.SafeString("-async-" + s));
|
|
37
|
-
}, Math.floor((Math.random()*10)+1));
|
|
38
|
-
}
|
|
39
|
-
hb.registerAsyncHelper("async", async);
|
|
40
|
-
|
|
41
|
-
var render = hb.express3({
|
|
42
|
-
viewsDir: dirname,
|
|
43
|
-
restrictLayoutsTo: dirname
|
|
44
|
-
});
|
|
45
|
-
var locals = H.createLocals('express3', dirname);
|
|
46
|
-
|
|
47
|
-
render(dirname + '/home/async.hbs', locals, function(err, html) {
|
|
48
|
-
assert.equal('<default>asynctemplate-async-foo-async-bar-async-bah-async-baz</default>', H.stripWs(html));
|
|
49
|
-
done();
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
});
|
package/test/helpers.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
function stripWs(s) {
|
|
2
|
-
return s.replace(/\s+/g, '');
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function createLocals(which, viewsDir, locals) {
|
|
6
|
-
if (!locals) locals = {};
|
|
7
|
-
var opts = {};
|
|
8
|
-
if (which === 'express3' || which === 'express4') {
|
|
9
|
-
opts.settings = {
|
|
10
|
-
views: viewsDir
|
|
11
|
-
};
|
|
12
|
-
opts.cache = process.env.NODE_ENV === 'production';
|
|
13
|
-
for (var k in locals) {
|
|
14
|
-
if (!locals.hasOwnProperty(k)) continue;
|
|
15
|
-
opts[k] = locals[k];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return opts;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = {
|
|
22
|
-
createLocals: createLocals,
|
|
23
|
-
stripWs: stripWs
|
|
24
|
-
};
|
package/test/i18nSpecs.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
var request = require('supertest');
|
|
2
|
-
var assert = require('assert');
|
|
3
|
-
var hbs = require('..');
|
|
4
|
-
|
|
5
|
-
describe('i18n', function() {
|
|
6
|
-
var app;
|
|
7
|
-
|
|
8
|
-
beforeEach(function() {
|
|
9
|
-
var apper = require('./apps/i18n');
|
|
10
|
-
app = apper.create(hbs.create());
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should render en', function(done) {
|
|
14
|
-
request(app)
|
|
15
|
-
.get('/')
|
|
16
|
-
.set('Cookie', 'locale=en')
|
|
17
|
-
.end(function(req, res) {
|
|
18
|
-
var expected = '<span id="text">text to test</span>\n<br>\n<span class="each">1 cat</span><span class="each">2 cats</span>';
|
|
19
|
-
assert.equal(res.text, expected);
|
|
20
|
-
done();
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should render fr', function(done) {
|
|
25
|
-
request(app)
|
|
26
|
-
.get('/')
|
|
27
|
-
.set('Cookie', 'locale=fr')
|
|
28
|
-
.end(function(req, res) {
|
|
29
|
-
var expected = '<span id="text">Texte à tester</span>\n<br>\n<span class="chaque">1 chat</span><span class="chaque">2 chats</span>';
|
|
30
|
-
assert.equal(res.text, expected);
|
|
31
|
-
done();
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<div>{{special_string}}</div>
|