-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#50 add placeholder handlebars helper
- Loading branch information
Showing
5 changed files
with
56 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var fs = require('fs'); | ||
var hbs = require('hbs'); | ||
var path = require('path'); | ||
var cfg = require('../../app/core/config.js'); | ||
var utils = require('../core/utils'); | ||
|
||
module.exports = function () { | ||
|
||
try { | ||
var context = arguments[arguments.length - 1]; | ||
var name = 'string' === typeof arguments[0] ? arguments[0] : context.hash.name; | ||
var templateFile = 'string' === typeof arguments[1] ? arguments[1] : context.hash.template; | ||
|
||
if(!name) { | ||
throw new Error('Placeholder name parameter not set'); | ||
} | ||
|
||
if(!templateFile) { | ||
throw new Error('Placeholder template parameter not set'); | ||
} | ||
|
||
templateFile += '.' + cfg.nitro.view_file_extension; | ||
|
||
var templatePath = path.join( | ||
cfg.nitro.base_path, | ||
cfg.nitro.placeholders_directory, | ||
name, | ||
templateFile); | ||
|
||
if (utils.fileExistsSync(templatePath)) { | ||
return new hbs.handlebars.SafeString( | ||
hbs.handlebars.compile( | ||
fs.readFileSync(templatePath, 'utf8') | ||
)(context) | ||
); | ||
} | ||
|
||
throw new Error('Placeholder ' + templatePath + ' not found.'); | ||
|
||
} | ||
catch (e) { | ||
return utils.logAndRenderError(e); | ||
} | ||
}; |
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
Empty file.