mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-06-26 23:22:55 +00:00
Require $$ for custom widgets, and that overridden JS widgets must exist
See https://github.com/Jermolene/TiddlyWiki5/pull/6666#issuecomment-1133637763
This commit is contained in:
parent
bbd9e2f243
commit
e50101322f
@ -93,9 +93,6 @@ exports.parseTag = function(source,pos,options) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
node.tag = token.match[1];
|
node.tag = token.match[1];
|
||||||
if(node.tag.slice(1).indexOf("$") !== -1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(node.tag.charAt(0) === "$") {
|
if(node.tag.charAt(0) === "$") {
|
||||||
node.type = node.tag.substr(1);
|
node.type = node.tag.substr(1);
|
||||||
}
|
}
|
||||||
|
@ -435,10 +435,14 @@ options include:
|
|||||||
Widget.prototype.makeChildWidget = function(parseTreeNode,options) {
|
Widget.prototype.makeChildWidget = function(parseTreeNode,options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
options = options || {};
|
options = options || {};
|
||||||
// Check whether this node type is defined by a custom macro definition
|
// Check whether this node type is defined by a custom widget definition
|
||||||
var variableDefinitionName = "$" + parseTreeNode.type,
|
var variableDefinitionName = "$" + parseTreeNode.type,
|
||||||
variableInfo = this.variables[variableDefinitionName];
|
variableInfo = this.variables[variableDefinitionName],
|
||||||
if(!parseTreeNode.isNotRemappable && variableInfo && variableInfo.value && variableInfo.isWidgetDefinition) {
|
isOverrideable = function() {
|
||||||
|
// Widget is overrideable if it has a double dollar user defined name, or if it is an existing JS widget
|
||||||
|
return parseTreeNode.type.charAt(0) === "$" || !!self.widgetClasses[parseTreeNode.type];
|
||||||
|
};
|
||||||
|
if(!parseTreeNode.isNotRemappable && isOverrideable() && variableInfo && variableInfo.value && variableInfo.isWidgetDefinition) {
|
||||||
var newParseTreeNode = {
|
var newParseTreeNode = {
|
||||||
type: "transclude",
|
type: "transclude",
|
||||||
children: [
|
children: [
|
||||||
|
@ -12,15 +12,15 @@ title: Output
|
|||||||
title: Actions
|
title: Actions
|
||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<!-- Define the <$action-mywidget> widget by defining a transcludable variable with that name -->
|
<!-- Define the <$$action-mywidget> widget by defining a transcludable variable with that name -->
|
||||||
\widget $action-mywidget(one:'Jaguar')
|
\widget $$action-mywidget(one:'Jaguar')
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<$action-setfield $tiddler="Result" $field="text" $value=<<one>>/>
|
<$action-setfield $tiddler="Result" $field="text" $value=<<one>>/>
|
||||||
\end
|
\end
|
||||||
|
|
||||||
<$action-mywidget one="Dingo">
|
<$$action-mywidget one="Dingo">
|
||||||
Crocodile
|
Crocodile
|
||||||
</$action-mywidget>
|
</$$action-mywidget>
|
||||||
+
|
+
|
||||||
title: ExpectedResult
|
title: ExpectedResult
|
||||||
|
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
title: Transclude/CustomWidget/Fail
|
||||||
|
description: Custom widget failed definition
|
||||||
|
type: text/vnd.tiddlywiki-multiple
|
||||||
|
tags: [[$:/tags/wiki-test-spec]]
|
||||||
|
|
||||||
|
title: Output
|
||||||
|
|
||||||
|
\whitespace trim
|
||||||
|
<!-- Attempt to define the <$non-existent-widget> widget by defining a transcludable variable with that name -->
|
||||||
|
\widget $non-existent-widget(one:'Jaguar')
|
||||||
|
\whitespace trim
|
||||||
|
<$text text=<<one>>/>
|
||||||
|
<$slot $name="ts-body">
|
||||||
|
Whale
|
||||||
|
</$slot>
|
||||||
|
\end
|
||||||
|
<$non-existent-widget one="Dingo">
|
||||||
|
Crocodile
|
||||||
|
</$non-existent-widget>
|
||||||
|
<$non-existent-widget one="BumbleBee">
|
||||||
|
Squirrel
|
||||||
|
</$non-existent-widget>
|
||||||
|
+
|
||||||
|
title: ExpectedResult
|
||||||
|
|
||||||
|
<p>Undefined widget 'non-existent-widget'Undefined widget 'non-existent-widget'</p>
|
@ -12,20 +12,20 @@ title: Output
|
|||||||
title: TiddlerOne
|
title: TiddlerOne
|
||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<!-- Define the <$mywidget> widget by defining a transcludable variable with that name -->
|
<!-- Define the <$$mywidget> widget by defining a transcludable variable with that name -->
|
||||||
\widget $mywidget(one:'Jaguar')
|
\widget $$mywidget(one:'Jaguar')
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<$text text=<<one>>/>
|
<$text text=<<one>>/>
|
||||||
<$slot $name="ts-body">
|
<$slot $name="ts-body">
|
||||||
Whale
|
Whale
|
||||||
</$slot>
|
</$slot>
|
||||||
\end
|
\end
|
||||||
<$mywidget one="Dingo">
|
<$$mywidget one="Dingo">
|
||||||
Crocodile
|
Crocodile
|
||||||
</$mywidget>
|
</$$mywidget>
|
||||||
<$mywidget one="BumbleBee">
|
<$$mywidget one="BumbleBee">
|
||||||
Squirrel
|
Squirrel
|
||||||
</$mywidget>
|
</$$mywidget>
|
||||||
+
|
+
|
||||||
title: ExpectedResult
|
title: ExpectedResult
|
||||||
|
|
||||||
|
@ -12,17 +12,17 @@ title: Output
|
|||||||
title: TiddlerOne
|
title: TiddlerOne
|
||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<!-- Redefine the <$mywidget> widget by defining a transcludable variable with that name -->
|
<!-- Redefine the <$$mywidget> widget by defining a transcludable variable with that name -->
|
||||||
\widget $mywidget($variable:'Jaguar')
|
\widget $$mywidget($variable:'Jaguar')
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<$text text=<<$variable>>/>
|
<$text text=<<$variable>>/>
|
||||||
<$slot $name="ts-body">
|
<$slot $name="ts-body">
|
||||||
Whale
|
Whale
|
||||||
</$slot>
|
</$slot>
|
||||||
\end
|
\end
|
||||||
<$mywidget $variable="Dingo">
|
<$$mywidget $variable="Dingo">
|
||||||
Crocodile
|
Crocodile
|
||||||
</$mywidget>
|
</$$mywidget>
|
||||||
+
|
+
|
||||||
title: ExpectedResult
|
title: ExpectedResult
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user