mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-02-20 00:49:50 +00:00
Compare commits
1 Commits
master
...
yet-more-m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
add7f26f04 |
@@ -24,7 +24,7 @@ exports.cascade = function(operationSubFunction,options) {
|
||||
}
|
||||
var output = filterFnList[index](options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",{defaultValue:""})
|
||||
"..currentTiddler": widget.getVariable("currentTiddler","")
|
||||
}));
|
||||
if(output.length !== 0) {
|
||||
result = output[0];
|
||||
|
||||
@@ -18,7 +18,7 @@ exports.filter = function(operationSubFunction,options) {
|
||||
results.each(function(title) {
|
||||
var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",{defaultValue:""}),
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",""),
|
||||
"index": "" + index,
|
||||
"revIndex": "" + (results.length - 1 - index),
|
||||
"length": "" + results.length
|
||||
|
||||
@@ -20,7 +20,7 @@ exports.map = function(operationSubFunction,options) {
|
||||
$tw.utils.each(inputTitles,function(title) {
|
||||
var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",{defaultValue:""}),
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",""),
|
||||
"index": "" + index,
|
||||
"revIndex": "" + (inputTitles.length - 1 - index),
|
||||
"length": "" + inputTitles.length
|
||||
|
||||
@@ -17,7 +17,7 @@ exports.reduce = function(operationSubFunction,options) {
|
||||
results.each(function(title) {
|
||||
var list = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",{defaultValue:""}),
|
||||
"..currentTiddler": widget.getVariable("currentTiddler"),
|
||||
"index": "" + index,
|
||||
"revIndex": "" + (results.length - 1 - index),
|
||||
"length": "" + results.length,
|
||||
|
||||
@@ -24,7 +24,7 @@ exports.sort = function(operationSubFunction,options) {
|
||||
results.each(function(title) {
|
||||
var key = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",{defaultValue:""})
|
||||
"..currentTiddler": widget.getVariable("currentTiddler")
|
||||
}));
|
||||
sortKeys.push(key[0] || "");
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ exports.filter = function(source,operator,options) {
|
||||
source(function(tiddler,title) {
|
||||
var list = filterFn.call(options.wiki,options.wiki.makeTiddlerIterator([title]),options.widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": options.widget.getVariable("currentTiddler",{defaultValue:""})
|
||||
"..currentTiddler": options.widget.getVariable("currentTiddler","")
|
||||
}));
|
||||
if((list.length > 0) === target) {
|
||||
results.push(title);
|
||||
|
||||
@@ -24,4 +24,4 @@ exports.variables = function(source,operator,options) {
|
||||
}
|
||||
}
|
||||
return names.sort();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -329,43 +329,48 @@ Widget.prototype.getStateQualifier = function(name) {
|
||||
/*
|
||||
Make a fake widget with specified variables, suitable for variable lookup in filters. Each variable can be a string or an array of strings
|
||||
*/
|
||||
Widget.prototype.makeFakeWidgetWithVariables = function(vars = {}) {
|
||||
const self = this;
|
||||
|
||||
const fakeWidget = {
|
||||
getVariableInfo(name,opts = {}) {
|
||||
if(name in vars) {
|
||||
const value = vars[name];
|
||||
return Array.isArray(value)
|
||||
? { text: value[0], resultList: value }
|
||||
: { text: value, resultList: [value] };
|
||||
}
|
||||
opts = opts || {};
|
||||
opts.variables = Object.assign({}, vars, opts.variables || {});
|
||||
return self.getVariableInfo(name, opts);
|
||||
Widget.prototype.makeFakeWidgetWithVariables = function(variables) {
|
||||
var self = this,
|
||||
variables = variables || {};
|
||||
return {
|
||||
getVariable: function(name,opts) {
|
||||
if($tw.utils.hop(variables,name)) {
|
||||
var value = variables[name];
|
||||
if($tw.utils.isArray(value)) {
|
||||
return value[0];
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
} else {
|
||||
opts = opts || {};
|
||||
opts.variables = $tw.utils.extend({},variables,opts.variables);
|
||||
return self.getVariable(name,opts);
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
getVariable(name,opts) {
|
||||
return this.getVariableInfo(name, opts).text;
|
||||
getVariableInfo: function(name,opts) {
|
||||
if($tw.utils.hop(variables,name)) {
|
||||
var value = variables[name];
|
||||
if($tw.utils.isArray(value)) {
|
||||
return {
|
||||
text: value[0],
|
||||
resultList: value
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
text: value,
|
||||
resultList: [value]
|
||||
};
|
||||
}
|
||||
} else {
|
||||
opts = opts || {};
|
||||
opts.variables = $tw.utils.extend({},variables,opts.variables);
|
||||
return self.getVariableInfo(name,opts);
|
||||
};
|
||||
},
|
||||
|
||||
resolveVariableParameters: self.resolveVariableParameters,
|
||||
wiki: self.wiki,
|
||||
makeFakeWidgetWithVariables: self.makeFakeWidgetWithVariables,
|
||||
|
||||
get variables() {
|
||||
// Merge parent vars via prototype-like delegation
|
||||
return Object.create(self.variables || {},
|
||||
Object.keys(vars).reduce((acc, key) => {
|
||||
acc[key] = { value: vars[key], enumerable: true, configurable: true };
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
}
|
||||
resolveVariableParameters: self.resolveVariableParameters,
|
||||
wiki: self.wiki
|
||||
};
|
||||
|
||||
return fakeWidget;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
title: Functions/VariableLeakage
|
||||
description: Variables from filter runs or functions should not pollute widget
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\function myvar(element) [<element>]
|
||||
\function call(element) [[myvar]is[variable]then<element>]
|
||||
|
||||
<<call abc>>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>abc</p>
|
||||
@@ -1,14 +0,0 @@
|
||||
title: Functions/VariableEnumeration
|
||||
description: Variables should be enumerable within functions
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\function list-vars() [variables[]]
|
||||
|
||||
<$text text={{{ [function[list-vars]count[]compare:number:gt[0]then[yes]] }}}/>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>yes</p>
|
||||
@@ -36,56 +36,13 @@ type: text/vnd.tiddlywiki
|
||||
</h2>
|
||||
<table class="tc-view-field-table">
|
||||
<tbody>
|
||||
<$list filter="[all[current]fields[]sort[title]] -title -text" template="$:/core/ui/TiddlerFieldTemplate" variable="listItem"/>
|
||||
<$list filter="[all[current]fields[]sort[title]] -title" template="$:/core/ui/TiddlerFieldTemplate" variable="listItem"/>
|
||||
</tbody>
|
||||
</table>
|
||||
<$codeblock code={{{ [<currentTiddler>get[text]] }}}/>
|
||||
</div>
|
||||
</$tiddler>
|
||||
\end
|
||||
|
||||
\procedure .demo-tiddler(tidText)
|
||||
\procedure create-tiddler-actions()
|
||||
<$action-setmultiplefields $tiddler=<<title>> $fields="[<jsonTiddler>jsonindexes[0]sort[]]" $values="[<jsonTiddler>jsonindexes[0]sort[]] :map[<jsonTiddler>jsonget[0],<currentTiddler>]"/>
|
||||
\end create-tiddler-actions
|
||||
<$let
|
||||
jsonTiddler={{{ [<tidText>deserialize[application/x-tiddler]] }}}
|
||||
title={{{ [<jsonTiddler>jsonget[0],[title]] }}}
|
||||
>
|
||||
<div class="doc-tiddler-fields">
|
||||
<h2>
|
||||
<$link to=<<title>>>
|
||||
<$text text=<<title>>/>
|
||||
</$link>
|
||||
</h2>
|
||||
<table class="tc-view-field-table">
|
||||
<tbody>
|
||||
<$list filter="[<jsonTiddler>jsonindexes[0]sort[]] -title -text" variable="listItem">
|
||||
<tr class="tc-view-field">
|
||||
<td class="tc-view-field-name">
|
||||
<$text text=<<listItem>>/>
|
||||
</td>
|
||||
<td class="tc-view-field-value">
|
||||
<$text text={{{ [<jsonTiddler>jsonget[0],<listItem>] }}}/>
|
||||
</td>
|
||||
</tr>
|
||||
</$list>
|
||||
</tbody>
|
||||
</table>
|
||||
<$codeblock code={{{ [<jsonTiddler>jsonget[0],[text]] }}}/>
|
||||
<div>
|
||||
<%if [<title>has[title]] %>
|
||||
The tiddler '<$link to=<<title>>><$text text=<<title>>/></$link>' already exists
|
||||
<%else%>
|
||||
<$button actions=<<create-tiddler-actions>> class="tc-btn-big-green">
|
||||
Create this tiddler
|
||||
</$button>
|
||||
<%endif%>
|
||||
</div>
|
||||
</div>
|
||||
</$let>
|
||||
\end
|
||||
|
||||
\function .mtitle(_) [<_>] Macro +[join[ ]]
|
||||
\function .otitle(_) [<_>] Operator +[join[ ]]
|
||||
\function .vtitle(_) [<_>] Variable +[join[ ]]
|
||||
|
||||
Reference in New Issue
Block a user