mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-30 13:29:56 +00:00
Use \widget for custom widget definitions, and remove need for angle brackets
Need to do some refactoring of all those isFunctionDefinition/isProcedureDefinition/isWidgetDefinition flags into a single property
This commit is contained in:
parent
904e30a0e2
commit
36cf50aa96
@ -3,7 +3,7 @@ title: $:/core/modules/parsers/wikiparser/rules/fnprocdef.js
|
|||||||
type: application/javascript
|
type: application/javascript
|
||||||
module-type: wikirule
|
module-type: wikirule
|
||||||
|
|
||||||
Wiki pragma rule for function and procedure definitions
|
Wiki pragma rule for function, procedure and widget definitions
|
||||||
|
|
||||||
```
|
```
|
||||||
\function name(param:defaultvalue,param2:defaultvalue)
|
\function name(param:defaultvalue,param2:defaultvalue)
|
||||||
@ -13,6 +13,10 @@ definition text
|
|||||||
\procedure name(param:defaultvalue,param2:defaultvalue)
|
\procedure name(param:defaultvalue,param2:defaultvalue)
|
||||||
definition text
|
definition text
|
||||||
\end
|
\end
|
||||||
|
|
||||||
|
\widget $mywidget(param:defaultvalue,param2:defaultvalue)
|
||||||
|
definition text
|
||||||
|
\end
|
||||||
```
|
```
|
||||||
|
|
||||||
\*/
|
\*/
|
||||||
@ -31,7 +35,7 @@ Instantiate parse rule
|
|||||||
exports.init = function(parser) {
|
exports.init = function(parser) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
// Regexp to match
|
// Regexp to match
|
||||||
this.matchRegExp = /^\\(function|procedure)\s+([^(\s]+)(\(\s*([^)]*)\))?(\s*\r?\n)?/mg;
|
this.matchRegExp = /^\\(function|procedure|widget)\s+([^(\s]+)(\(\s*([^)]*)\))?(\s*\r?\n)?/mg;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -94,6 +98,8 @@ exports.parse = function() {
|
|||||||
parseTreeNodes[0].isFunctionDefinition = true;
|
parseTreeNodes[0].isFunctionDefinition = true;
|
||||||
} else if(this.match[1] === "procedure") {
|
} else if(this.match[1] === "procedure") {
|
||||||
parseTreeNodes[0].isProcedureDefinition = true;
|
parseTreeNodes[0].isProcedureDefinition = true;
|
||||||
|
} else if(this.match[1] === "widget") {
|
||||||
|
parseTreeNodes[0].isWidgetDefinition = true;
|
||||||
}
|
}
|
||||||
return parseTreeNodes;
|
return parseTreeNodes;
|
||||||
};
|
};
|
||||||
|
@ -57,7 +57,8 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
|||||||
params: parseTreeNode.params,
|
params: parseTreeNode.params,
|
||||||
isMacroDefinition: parseTreeNode.isMacroDefinition,
|
isMacroDefinition: parseTreeNode.isMacroDefinition,
|
||||||
isFunctionDefinition: parseTreeNode.isFunctionDefinition,
|
isFunctionDefinition: parseTreeNode.isFunctionDefinition,
|
||||||
isProcedureDefinition: parseTreeNode.isProcedureDefinition
|
isProcedureDefinition: parseTreeNode.isProcedureDefinition,
|
||||||
|
isWidgetDefinition: parseTreeNode.isWidgetDefinition
|
||||||
};
|
};
|
||||||
if (parseTreeNode.isMacroDefinition || parseTreeNode.isProcedureDefinition) {
|
if (parseTreeNode.isMacroDefinition || parseTreeNode.isProcedureDefinition) {
|
||||||
// Macro definitions can be folded into
|
// Macro definitions can be folded into
|
||||||
|
@ -54,6 +54,8 @@ SetWidget.prototype.execute = function() {
|
|||||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isFunctionDefinition: true});
|
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isFunctionDefinition: true});
|
||||||
} else if(this.parseTreeNode.isProcedureDefinition) {
|
} else if(this.parseTreeNode.isProcedureDefinition) {
|
||||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isProcedureDefinition: true});
|
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isProcedureDefinition: true});
|
||||||
|
} else if(this.parseTreeNode.isWidgetDefinition) {
|
||||||
|
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isWidgetDefinition: true});
|
||||||
} else {
|
} else {
|
||||||
this.setVariable(this.setName,this.getValue());
|
this.setVariable(this.setName,this.getValue());
|
||||||
}
|
}
|
||||||
|
@ -185,8 +185,8 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(parser) {
|
if(parser) {
|
||||||
// Add parameters widget for procedures
|
// Add parameters widget for procedures and custom widgets
|
||||||
if(srcVariable.isProcedureDefinition) {
|
if(srcVariable.isProcedureDefinition || srcVariable.isWidgetDefinition) {
|
||||||
parser = {
|
parser = {
|
||||||
tree: [
|
tree: [
|
||||||
{
|
{
|
||||||
|
@ -94,6 +94,7 @@ isMacroDefinition: true if the variable is set via a \define macro pragma (and h
|
|||||||
options includes:
|
options includes:
|
||||||
isProcedureDefinition: true if the variable is set via a \procedure pragma (and hence should not have variable substitution performed)
|
isProcedureDefinition: true if the variable is set via a \procedure pragma (and hence should not have variable substitution performed)
|
||||||
isFunctionDefinition: true if the variable is set via a \function pragma (and hence should not have variable substitution performed)
|
isFunctionDefinition: true if the variable is set via a \function pragma (and hence should not have variable substitution performed)
|
||||||
|
isWidgetDefinition: true if the variable is set via a \widget pragma (and hence should not have variable substitution performed)
|
||||||
*/
|
*/
|
||||||
Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,options) {
|
Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
@ -102,7 +103,8 @@ Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,opti
|
|||||||
params: params,
|
params: params,
|
||||||
isMacroDefinition: !!isMacroDefinition,
|
isMacroDefinition: !!isMacroDefinition,
|
||||||
isFunctionDefinition: !!options.isFunctionDefinition,
|
isFunctionDefinition: !!options.isFunctionDefinition,
|
||||||
isProcedureDefinition: !!options.isProcedureDefinition
|
isProcedureDefinition: !!options.isProcedureDefinition,
|
||||||
|
isWidgetDefinition: !!options.isWidgetDefinition
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -434,8 +436,9 @@ 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 macro definition
|
||||||
var variableDefinitionName = "<$" + parseTreeNode.type + ">";
|
var variableDefinitionName = "$" + parseTreeNode.type,
|
||||||
if(!parseTreeNode.isNotRemappable && this.variables[variableDefinitionName] && this.variables[variableDefinitionName].value) {
|
variableInfo = this.variables[variableDefinitionName];
|
||||||
|
if(!parseTreeNode.isNotRemappable && variableInfo && variableInfo.value && variableInfo.isWidgetDefinition) {
|
||||||
var newParseTreeNode = {
|
var newParseTreeNode = {
|
||||||
type: "transclude",
|
type: "transclude",
|
||||||
children: [
|
children: [
|
||||||
|
@ -6,7 +6,7 @@ tags: [[$:/tags/wiki-test-spec]]
|
|||||||
title: Output
|
title: Output
|
||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
\procedure <$let>
|
\widget $let
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<$setmultiplevariables $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>addprefix[--]addsuffix[--]]">
|
<$setmultiplevariables $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>addprefix[--]addsuffix[--]]">
|
||||||
<$slot $name="ts-body"/>
|
<$slot $name="ts-body"/>
|
||||||
|
@ -13,7 +13,7 @@ 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 -->
|
||||||
\procedure <$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
|
||||||
|
@ -16,7 +16,7 @@ title: Output
|
|||||||
title: Definition
|
title: Definition
|
||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
\procedure <$codeblock>(code)
|
\widget $codeblock(code)
|
||||||
<$genesis $type="codeblock" $remappable="no" code={{{ [<code>addprefix[£]addsuffix[@]] }}}/>
|
<$genesis $type="codeblock" $remappable="no" code={{{ [<code>addprefix[£]addsuffix[@]] }}}/>
|
||||||
\end
|
\end
|
||||||
+
|
+
|
||||||
|
@ -17,7 +17,7 @@ title: TiddlerOne
|
|||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<!-- Redefine the <$transclude> widget by defining a transcludable variable with that name -->
|
<!-- Redefine the <$transclude> widget by defining a transcludable variable with that name -->
|
||||||
\procedure <$transclude>(one:'Jaguar')
|
\widget $transclude(one:'Jaguar')
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<$text text=<<one>>/>
|
<$text text=<<one>>/>
|
||||||
<$slot $name="body">
|
<$slot $name="body">
|
||||||
|
@ -13,7 +13,7 @@ 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 -->
|
||||||
\procedure <$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">
|
||||||
|
@ -13,10 +13,10 @@ title: TiddlerOne
|
|||||||
|
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<!-- Redefine the <$text> widget by defining a transcludable variable with that name -->
|
<!-- Redefine the <$text> widget by defining a transcludable variable with that name -->
|
||||||
\procedure <$text>(text:'Jaguar')
|
\widget $text(text:'Jaguar')
|
||||||
\whitespace trim
|
\whitespace trim
|
||||||
<$genesis $type="text" $remappable="no" text=<<text>>/>
|
<$genesis $type="text" $remappable="no" text=<<text>>/>
|
||||||
<$set name="<$text>" value="">
|
<$set name="$text" value="">
|
||||||
<$slot $name="ts-body">
|
<$slot $name="ts-body">
|
||||||
Whale
|
Whale
|
||||||
</$slot>
|
</$slot>
|
||||||
|
@ -13,7 +13,7 @@ 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 -->
|
||||||
\procedure <$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">
|
||||||
|
Loading…
Reference in New Issue
Block a user