mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 20:10:03 +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
|
||||
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)
|
||||
@ -13,6 +13,10 @@ definition text
|
||||
\procedure name(param:defaultvalue,param2:defaultvalue)
|
||||
definition text
|
||||
\end
|
||||
|
||||
\widget $mywidget(param:defaultvalue,param2:defaultvalue)
|
||||
definition text
|
||||
\end
|
||||
```
|
||||
|
||||
\*/
|
||||
@ -31,7 +35,7 @@ Instantiate parse rule
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// 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;
|
||||
} else if(this.match[1] === "procedure") {
|
||||
parseTreeNodes[0].isProcedureDefinition = true;
|
||||
} else if(this.match[1] === "widget") {
|
||||
parseTreeNodes[0].isWidgetDefinition = true;
|
||||
}
|
||||
return parseTreeNodes;
|
||||
};
|
||||
|
@ -57,7 +57,8 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
||||
params: parseTreeNode.params,
|
||||
isMacroDefinition: parseTreeNode.isMacroDefinition,
|
||||
isFunctionDefinition: parseTreeNode.isFunctionDefinition,
|
||||
isProcedureDefinition: parseTreeNode.isProcedureDefinition
|
||||
isProcedureDefinition: parseTreeNode.isProcedureDefinition,
|
||||
isWidgetDefinition: parseTreeNode.isWidgetDefinition
|
||||
};
|
||||
if (parseTreeNode.isMacroDefinition || parseTreeNode.isProcedureDefinition) {
|
||||
// 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});
|
||||
} else if(this.parseTreeNode.isProcedureDefinition) {
|
||||
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 {
|
||||
this.setVariable(this.setName,this.getValue());
|
||||
}
|
||||
|
@ -185,8 +185,8 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
|
||||
}
|
||||
}
|
||||
if(parser) {
|
||||
// Add parameters widget for procedures
|
||||
if(srcVariable.isProcedureDefinition) {
|
||||
// Add parameters widget for procedures and custom widgets
|
||||
if(srcVariable.isProcedureDefinition || srcVariable.isWidgetDefinition) {
|
||||
parser = {
|
||||
tree: [
|
||||
{
|
||||
|
@ -94,6 +94,7 @@ isMacroDefinition: true if the variable is set via a \define macro pragma (and h
|
||||
options includes:
|
||||
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)
|
||||
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) {
|
||||
options = options || {};
|
||||
@ -102,7 +103,8 @@ Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,opti
|
||||
params: params,
|
||||
isMacroDefinition: !!isMacroDefinition,
|
||||
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;
|
||||
options = options || {};
|
||||
// Check whether this node type is defined by a custom macro definition
|
||||
var variableDefinitionName = "<$" + parseTreeNode.type + ">";
|
||||
if(!parseTreeNode.isNotRemappable && this.variables[variableDefinitionName] && this.variables[variableDefinitionName].value) {
|
||||
var variableDefinitionName = "$" + parseTreeNode.type,
|
||||
variableInfo = this.variables[variableDefinitionName];
|
||||
if(!parseTreeNode.isNotRemappable && variableInfo && variableInfo.value && variableInfo.isWidgetDefinition) {
|
||||
var newParseTreeNode = {
|
||||
type: "transclude",
|
||||
children: [
|
||||
|
@ -6,7 +6,7 @@ tags: [[$:/tags/wiki-test-spec]]
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
\procedure <$let>
|
||||
\widget $let
|
||||
\whitespace trim
|
||||
<$setmultiplevariables $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>addprefix[--]addsuffix[--]]">
|
||||
<$slot $name="ts-body"/>
|
||||
|
@ -13,7 +13,7 @@ title: Actions
|
||||
|
||||
\whitespace trim
|
||||
<!-- 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
|
||||
<$action-setfield $tiddler="Result" $field="text" $value=<<one>>/>
|
||||
\end
|
||||
|
@ -16,7 +16,7 @@ title: Output
|
||||
title: Definition
|
||||
|
||||
\whitespace trim
|
||||
\procedure <$codeblock>(code)
|
||||
\widget $codeblock(code)
|
||||
<$genesis $type="codeblock" $remappable="no" code={{{ [<code>addprefix[£]addsuffix[@]] }}}/>
|
||||
\end
|
||||
+
|
||||
|
@ -17,7 +17,7 @@ title: TiddlerOne
|
||||
|
||||
\whitespace trim
|
||||
<!-- Redefine the <$transclude> widget by defining a transcludable variable with that name -->
|
||||
\procedure <$transclude>(one:'Jaguar')
|
||||
\widget $transclude(one:'Jaguar')
|
||||
\whitespace trim
|
||||
<$text text=<<one>>/>
|
||||
<$slot $name="body">
|
||||
|
@ -13,7 +13,7 @@ title: TiddlerOne
|
||||
|
||||
\whitespace trim
|
||||
<!-- Define the <$mywidget> widget by defining a transcludable variable with that name -->
|
||||
\procedure <$mywidget>(one:'Jaguar')
|
||||
\widget $mywidget(one:'Jaguar')
|
||||
\whitespace trim
|
||||
<$text text=<<one>>/>
|
||||
<$slot $name="ts-body">
|
||||
|
@ -13,10 +13,10 @@ title: TiddlerOne
|
||||
|
||||
\whitespace trim
|
||||
<!-- Redefine the <$text> widget by defining a transcludable variable with that name -->
|
||||
\procedure <$text>(text:'Jaguar')
|
||||
\widget $text(text:'Jaguar')
|
||||
\whitespace trim
|
||||
<$genesis $type="text" $remappable="no" text=<<text>>/>
|
||||
<$set name="<$text>" value="">
|
||||
<$set name="$text" value="">
|
||||
<$slot $name="ts-body">
|
||||
Whale
|
||||
</$slot>
|
||||
|
@ -13,7 +13,7 @@ title: TiddlerOne
|
||||
|
||||
\whitespace trim
|
||||
<!-- Redefine the <$mywidget> widget by defining a transcludable variable with that name -->
|
||||
\procedure <$mywidget>($variable:'Jaguar')
|
||||
\widget $mywidget($variable:'Jaguar')
|
||||
\whitespace trim
|
||||
<$text text=<<$variable>>/>
|
||||
<$slot $name="ts-body">
|
||||
|
Loading…
Reference in New Issue
Block a user