1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-24 10:37:20 +00:00

Refactor transclude widget before uberfying it

This commit is contained in:
jeremy@jermolene.com 2022-04-30 09:30:25 +01:00
parent f78e1f6f7d
commit c4991fff9e

View File

@ -37,13 +37,48 @@ TranscludeWidget.prototype.render = function(parent,nextSibling) {
Compute the internal state of the widget Compute the internal state of the widget
*/ */
TranscludeWidget.prototype.execute = function() { TranscludeWidget.prototype.execute = function() {
// Get our parameters // Get our attributes into properties of the widget object
this.collectAttributes();
// Get the parse tree nodes that we are transcluding
var target = this.getTransclusionTarget(),
parseTreeNodes = target.parseTreeNodes;
this.sourceText = target.source;
this.sourceType = target.type;
// Set context variables for recursion detection
var recursionMarker = this.makeRecursionMarker();
if(this.recursionMarker === "yes") {
this.setVariable("transclusion",recursionMarker);
}
// Check for recursion
if(target.parser) {
if(this.parentWidget && this.parentWidget.hasVariable("transclusion",recursionMarker)) {
parseTreeNodes = [{type: "element", tag: "span", attributes: {
"class": {type: "string", value: "tc-error"}
}, children: [
{type: "text", text: $tw.language.getString("Error/RecursiveTransclusion")}
]}];
}
}
// Construct the child widgets
this.makeChildWidgets(parseTreeNodes);
};
/*
Collect the attributes we need, in the process determining whether we're being used in legacy mode
*/
TranscludeWidget.prototype.collectAttributes = function() {
this.transcludeTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); this.transcludeTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
this.transcludeSubTiddler = this.getAttribute("subtiddler"); this.transcludeSubTiddler = this.getAttribute("subtiddler");
this.transcludeField = this.getAttribute("field"); this.transcludeField = this.getAttribute("field");
this.transcludeIndex = this.getAttribute("index"); this.transcludeIndex = this.getAttribute("index");
this.transcludeMode = this.getAttribute("mode"); this.transcludeMode = this.getAttribute("mode");
this.recursionMarker = this.getAttribute("recursionMarker","yes"); this.recursionMarker = this.getAttribute("recursionMarker","yes");
};
/*
Get transcluded parse tree nodes as an object {parser:,text:,type:}
*/
TranscludeWidget.prototype.getTransclusionTarget = function() {
// Parse the text reference // Parse the text reference
var parseAsInline = !this.parseTreeNode.isBlock; var parseAsInline = !this.parseTreeNode.isBlock;
if(this.transcludeMode === "inline") { if(this.transcludeMode === "inline") {
@ -58,27 +93,22 @@ TranscludeWidget.prototype.execute = function() {
{ {
parseAsInline: parseAsInline, parseAsInline: parseAsInline,
subTiddler: this.transcludeSubTiddler subTiddler: this.transcludeSubTiddler
}), });
parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children;
this.sourceText = parser ? parser.source : null;
this.parserType = parser? parser.type : null;
// Set context variables for recursion detection
var recursionMarker = this.makeRecursionMarker();
if(this.recursionMarker === "yes") {
this.setVariable("transclusion",recursionMarker);
}
// Check for recursion
if(parser) { if(parser) {
if(this.parentWidget && this.parentWidget.hasVariable("transclusion",recursionMarker)) { return {
parseTreeNodes = [{type: "element", tag: "span", attributes: { parser: parser,
"class": {type: "string", value: "tc-error"} parseTreeNodes: parser.tree,
}, children: [ text: parser.source,
{type: "text", text: $tw.language.getString("Error/RecursiveTransclusion")} type: parser.type
]}]; };
} } else {
return {
parser: null,
parseTreeNodes: this.parseTreeNode.children,
text: null,
type: null
};
} }
// Construct the child widgets
this.makeChildWidgets(parseTreeNodes);
}; };
/* /*