mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-12 03:00:28 +00:00
revert variables and getvariables - use jsonvariable instead
This commit is contained in:
parent
8907a5d7d6
commit
fd5a3b5586
@ -16,18 +16,9 @@ Filter operator for replacing input values by the value of the variable with the
|
|||||||
Export our filter function
|
Export our filter function
|
||||||
*/
|
*/
|
||||||
exports.getvariable = function(source,operator,options) {
|
exports.getvariable = function(source,operator,options) {
|
||||||
var results = [],
|
var results = [];
|
||||||
operand = operator.operand || "text",
|
|
||||||
widget = options.widget;
|
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
var variable = widget.getVariableInfo(title, {}),
|
results.push(options.widget.getVariable(title) || "");
|
||||||
text = "";
|
|
||||||
if(operand === "text") {
|
|
||||||
text = variable.text;
|
|
||||||
} else if((operand === "value") && variable.srcVariable) {
|
|
||||||
text = variable.srcVariable.value;
|
|
||||||
}
|
|
||||||
results.push(text || "");
|
|
||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
@ -16,58 +16,17 @@ Filter operator for returning the names of the active variables
|
|||||||
Export our filter function
|
Export our filter function
|
||||||
*/
|
*/
|
||||||
exports.variables = function(source,operator,options) {
|
exports.variables = function(source,operator,options) {
|
||||||
var operands = [];
|
|
||||||
$tw.utils.each(operator.operands,function(operand,index){
|
|
||||||
operands.push({
|
|
||||||
name: (index + 1).toString(),
|
|
||||||
value: operand
|
|
||||||
});
|
|
||||||
});
|
|
||||||
var names = [],
|
var names = [],
|
||||||
sort,
|
widget = options.widget;
|
||||||
widget = options.widget,
|
|
||||||
included = (operands[0].value) ? operands[0].value : "var fn proc macro widget";
|
|
||||||
// all will overwrite
|
|
||||||
included = ((included.indexOf("all") !== -1)) ? "var fn proc macro widget" : included;
|
|
||||||
|
|
||||||
// variableTemplate = (operands.length > 1 && operands[1]) ? operands[1].value : "$type$ $name$($params$) $firstLine$";
|
|
||||||
|
|
||||||
switch(operator.suffix) {
|
|
||||||
case "raw":
|
|
||||||
sort = false;
|
|
||||||
break;
|
|
||||||
case "alphabetical": // the fallthrough is intentional. "alphabetical" is default
|
|
||||||
default:
|
|
||||||
sort = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
while(widget && !widget.hasOwnProperty("variables")) {
|
while(widget && !widget.hasOwnProperty("variables")) {
|
||||||
widget = widget.parentWidget;
|
widget = widget.parentWidget;
|
||||||
}
|
}
|
||||||
if(widget && widget.variables) {
|
if(widget && widget.variables) {
|
||||||
for(var variable in widget.variables) {
|
for(var variable in widget.variables) {
|
||||||
var varInfo = widget.getVariableInfo(variable, {});
|
names.push(variable);
|
||||||
|
|
||||||
// varInfo.name = variable;
|
|
||||||
// variable = $tw.utils.formatVariableString(variableTemplate, varInfo);
|
|
||||||
|
|
||||||
if( ((included.indexOf("fn") !== -1) && varInfo.srcVariable.isFunctionDefinition ) ||
|
|
||||||
((included.indexOf("proc") !== -1) && varInfo.srcVariable.isProcedureDefinition ) ||
|
|
||||||
((included.indexOf("macro") !== -1) && varInfo.srcVariable.isMacroDefinition ) ||
|
|
||||||
((included.indexOf("widget") !== -1) && varInfo.srcVariable.isWidgetDefinition ) )
|
|
||||||
{
|
|
||||||
names.push(variable);
|
|
||||||
} else if((included.indexOf("var") !== -1) && !varInfo.srcVariable.isFunctionDefinition && !varInfo.srcVariable.isProcedureDefinition && !varInfo.srcVariable.isMacroDefinition && !varInfo.srcVariable.isWidgetDefinition )
|
|
||||||
{
|
|
||||||
names.push(variable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(sort) {
|
return names.sort();
|
||||||
return names.sort();
|
|
||||||
} else {
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user