-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from allouis/add-support-for-dynamic-template…
…-options-v1x Adds support for local template options
- Loading branch information
Showing
6 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
"dependencies": { | ||
"handlebars": "4.0.13", | ||
"js-beautify": "1.6.8", | ||
"lodash": "4.17.11", | ||
"readdirp": "2.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
var path = require('path'); | ||
var hbs = require('..'); | ||
var H = require('./helpers'); | ||
|
||
describe('local template options', function () { | ||
var dirname = path.join(__dirname, 'localTemplateOptions'); | ||
|
||
describe('express3', function () { | ||
|
||
it('merges res.locals._templateOptions with the self._templateOptions', function (done) { | ||
var instance = hbs.create(); | ||
var render = instance.express3({}); | ||
instance.updateTemplateOptions({ | ||
data: { | ||
greeting: 'Hello,', | ||
firstName: 'Freddy', | ||
lastName: 'Krueger' | ||
} | ||
}); | ||
|
||
var locals = H.createLocals('express3', dirname, { | ||
_templateOptions: { | ||
data: { | ||
lastName: 'Mercury' | ||
} | ||
} | ||
}); | ||
|
||
render(path.join(dirname, 'template.hbs'), locals, function (err, html) { | ||
assert.ifError(err); | ||
assert.strictEqual(H.stripWs(html), H.stripWs('Hello, Freddy Mercury')); | ||
done(err); | ||
}); | ||
}); | ||
|
||
it('removes _templateOptions from the locals data', function (done) { | ||
var instance = hbs.create(); | ||
var render = instance.express3({}); | ||
instance.updateTemplateOptions({ | ||
data: { | ||
greeting: 'Hello,', | ||
firstName: 'Freddy', | ||
lastName: 'Krueger' | ||
} | ||
}); | ||
|
||
var locals = H.createLocals('express3', dirname, { | ||
_templateOptions: { | ||
data: { | ||
lastName: 'Mercury' | ||
} | ||
} | ||
}); | ||
|
||
render(path.join(dirname, 'data-access-template.hbs'), locals, function (err, html) { | ||
assert.ifError(err); | ||
assert.strictEqual(H.stripWs(html), H.stripWs('')); | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('express4', function () { | ||
|
||
it('merges res.locals._templateOptions with the self._templateOptions', function (done) { | ||
var instance = hbs.create(); | ||
var render = instance.express4({}); | ||
instance.updateTemplateOptions({ | ||
data: { | ||
greeting: 'Hello,', | ||
firstName: 'Freddy', | ||
lastName: 'Krueger' | ||
} | ||
}); | ||
|
||
var locals = H.createLocals('express4', dirname, { | ||
_templateOptions: { | ||
data: { | ||
lastName: 'Mercury' | ||
} | ||
} | ||
}); | ||
|
||
render(path.join(dirname, 'template.hbs'), locals, function (err, html) { | ||
assert.ifError(err); | ||
assert.strictEqual(H.stripWs(html), H.stripWs('Hello, Freddy Mercury')); | ||
done(err); | ||
}); | ||
}); | ||
|
||
it('removes _templateOptions from the locals data', function (done) { | ||
var instance = hbs.create(); | ||
var render = instance.express3({}); | ||
instance.updateTemplateOptions({ | ||
data: { | ||
greeting: 'Hello,', | ||
firstName: 'Freddy', | ||
lastName: 'Krueger' | ||
} | ||
}); | ||
|
||
var locals = H.createLocals('express3', dirname, { | ||
_templateOptions: { | ||
data: { | ||
lastName: 'Mercury' | ||
} | ||
} | ||
}); | ||
|
||
render(path.join(dirname, 'data-access-template.hbs'), locals, function (err, html) { | ||
assert.ifError(err); | ||
assert.strictEqual(H.stripWs(html), H.stripWs('')); | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{_templateOptions.data.greeting}} {{_templateOptions.data.firstName}} {{_templateOptions.data.lastName}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{@greeting}} {{@firstName}} {{@lastName}} |