mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Allow hbs widgets to access their parent state
This commit is contained in:
parent
01c6224ca5
commit
e980322ed6
@ -1,5 +1,11 @@
|
|||||||
function resolve(path) {
|
function resolve(path) {
|
||||||
return (path.indexOf('settings') === 0) ? `this.${path}` : path;
|
if (path.indexOf('settings') === 0) {
|
||||||
|
return `this.${path}`;
|
||||||
|
} else if (path.indexOf('parentState') === 0) {
|
||||||
|
return `attrs._${path}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mustacheValue(node, state) {
|
function mustacheValue(node, state) {
|
||||||
@ -8,7 +14,7 @@ function mustacheValue(node, state) {
|
|||||||
switch(path) {
|
switch(path) {
|
||||||
case 'attach':
|
case 'attach':
|
||||||
const widgetName = node.hash.pairs.find(p => p.key === "widget").value.value;
|
const widgetName = node.hash.pairs.find(p => p.key === "widget").value.value;
|
||||||
return `this.attach("${widgetName}", attrs, state)`;
|
return `this.attach("${widgetName}", state ? $.extend({}, attrs, { _parentState: state }) : attrs)`;
|
||||||
break;
|
break;
|
||||||
case 'yield':
|
case 'yield':
|
||||||
return `this.attrs.contents()`;
|
return `this.attrs.contents()`;
|
||||||
|
Loading…
Reference in New Issue
Block a user