Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.idea
31 changes: 30 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,36 @@ function handlebars(data, opts) {
var registerPartial = function (filename, base) {
if (!isHandlebars(filename)) { return; }
var name = partialName(filename, base);
var template = fs.readFileSync(filename, 'utf8');
var template;

if(typeof opts.debugMode === "object") {
var startComment = "";
var endComment = "";
var logContext = "";
var logRootContext = "";
var logContextHelper = function(context) {
return new handlebars.Handlebars.SafeString(JSON.stringify(context))
};

if(typeof opts.debugMode.start === "string") {
startComment = opts.debugMode.start.replace("{{partial}}", name);
}

if(typeof opts.debugMode.end === "string") {
endComment = opts.debugMode.end.replace("{{partial}}", name);
}

if(typeof opts.debugMode.logContext === "string") {
var logHelperName = "logHelper_" + Date.now();
hb.registerHelper(logHelperName, logContextHelper);
logContext = opts.debugMode.logContext.replace("{{context}}", "{{" + logHelperName + " .}}");
}

template = startComment + logContext + fs.readFileSync(filename, 'utf8') + endComment;

} else {
template = fs.readFileSync(filename, 'utf8');
}

hb.registerPartial(name, template);
};
Expand Down
Loading