Fix bugs with helpers accessing scoped data

This commit is contained in:
Jocelyn Badgley (Twipped) 2020-03-02 20:28:25 -08:00
parent 640c3ac1a8
commit 065dd4ad79

View File

@ -192,19 +192,19 @@ class Injectables {
markdown () {
const self = this;
return function (...args) {
const { fn } = args.pop();
const { fn, data } = args.pop();
let contents;
if (fn) {
contents = stripIndent(fn(this));
contents = stripIndent(fn(data));
} else {
let tpath = args.shift();
tpath = self._parsePath(tpath, this.local, 'md');
tpath = self._parsePath(tpath, data.root.local, 'md');
contents = self._template(tpath);
}
contents = markdown('full', contents, this);
contents = markdown('full', contents, data);
return new handlebars.SafeString(contents);
};
@ -213,12 +213,12 @@ class Injectables {
import () {
const self = this;
return function (tpath, ...args) {
const { hash } = args.pop();
const { hash, data } = args.pop();
const value = args.shift();
const context = handlebars.createFrame(value || this);
const context = handlebars.createFrame(value || data);
Object.assign(context, hash || {});
tpath = self._parsePath(tpath, this.local, 'hbs');
tpath = self._parsePath(tpath, data.root.local, 'hbs');
try {
const contents = self._template(tpath, handlebars.compile)(context);
@ -233,8 +233,8 @@ class Injectables {
icon () {
const self = this;
return function (name, ...args) {
const { hash } = args.pop();
const tpath = path.join(this.local.root, 'svg', name + '.svg');
const { hash, data } = args.pop();
const tpath = path.join(data.root.local.root, 'svg', name + '.svg');
try {
const contents = self._template(tpath, (s) =>