1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 20:10:03 +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:
jeremy@jermolene.com 2022-05-21 15:47:19 +01:00
parent bbd9e2f243
commit e50101322f
6 changed files with 47 additions and 20 deletions

View File

@ -93,9 +93,6 @@ exports.parseTag = function(source,pos,options) {
return null;
}
node.tag = token.match[1];
if(node.tag.slice(1).indexOf("$") !== -1) {
return null;
}
if(node.tag.charAt(0) === "$") {
node.type = node.tag.substr(1);
}

View File

@ -435,10 +435,14 @@ options include:
Widget.prototype.makeChildWidget = function(parseTreeNode,options) {
var self = this;
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,
variableInfo = this.variables[variableDefinitionName];
if(!parseTreeNode.isNotRemappable && variableInfo && variableInfo.value && variableInfo.isWidgetDefinition) {
variableInfo = this.variables[variableDefinitionName],
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 = {
type: "transclude",
children: [

View File

@ -12,15 +12,15 @@ title: Output
title: Actions
\whitespace trim
<!-- Define the <$action-mywidget> widget by defining a transcludable variable with that name -->
\widget $action-mywidget(one:'Jaguar')
<!-- Define the <$$action-mywidget> widget by defining a transcludable variable with that name -->
\widget $$action-mywidget(one:'Jaguar')
\whitespace trim
<$action-setfield $tiddler="Result" $field="text" $value=<<one>>/>
\end
<$action-mywidget one="Dingo">
<$$action-mywidget one="Dingo">
Crocodile
</$action-mywidget>
</$$action-mywidget>
+
title: ExpectedResult

View File

@ -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>

View File

@ -12,20 +12,20 @@ title: Output
title: TiddlerOne
\whitespace trim
<!-- Define the <$mywidget> widget by defining a transcludable variable with that name -->
\widget $mywidget(one:'Jaguar')
<!-- Define the <$$mywidget> widget by defining a transcludable variable with that name -->
\widget $$mywidget(one:'Jaguar')
\whitespace trim
<$text text=<<one>>/>
<$slot $name="ts-body">
Whale
</$slot>
\end
<$mywidget one="Dingo">
<$$mywidget one="Dingo">
Crocodile
</$mywidget>
<$mywidget one="BumbleBee">
</$$mywidget>
<$$mywidget one="BumbleBee">
Squirrel
</$mywidget>
</$$mywidget>
+
title: ExpectedResult

View File

@ -12,17 +12,17 @@ title: Output
title: TiddlerOne
\whitespace trim
<!-- Redefine the <$mywidget> widget by defining a transcludable variable with that name -->
\widget $mywidget($variable:'Jaguar')
<!-- Redefine the <$$mywidget> widget by defining a transcludable variable with that name -->
\widget $$mywidget($variable:'Jaguar')
\whitespace trim
<$text text=<<$variable>>/>
<$slot $name="ts-body">
Whale
</$slot>
\end
<$mywidget $variable="Dingo">
<$$mywidget $variable="Dingo">
Crocodile
</$mywidget>
</$$mywidget>
+
title: ExpectedResult