-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Passing in template name to dust compile.
This will ensure when context.getTemplateName is called in a base template the appropriate name is available
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
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
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,2 @@ | ||
<p>{user.name}</p> | ||
{@templateName/} |
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,38 @@ | ||
/*eslint-env node, mocha */ | ||
var cons = require('../../'); | ||
var fs = require('fs'); | ||
|
||
// var should = require('should'); | ||
|
||
exports.test = function(name) { | ||
var user = { name: 'Tobi' }; | ||
|
||
describe(name, function(){ | ||
// Use case: return upper case string. | ||
it('should support fetching template name from the context', function(done) { | ||
var viewsDir = 'test/fixtures/' + name; | ||
var templatePath = viewsDir + '/user_template_name.' + name; | ||
var str = fs.readFileSync(templatePath).toString(); | ||
|
||
var locals = { | ||
user: user, | ||
views: viewsDir, | ||
filename: templatePath | ||
}; | ||
|
||
if (name === 'dust') { | ||
var dust = require('dustjs-helpers'); | ||
dust.helpers.templateName = function(chunk, context, bodies, params) { | ||
return chunk.write(context.getTemplateName()); | ||
}; | ||
cons.requires.dust = dust; | ||
} | ||
|
||
cons[name].render(str, locals, function(err, html){ | ||
if (err) return done(err); | ||
html.should.eql('<p>Tobi</p>user_template_name'); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}; |