mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-14 11:15:41 +00:00
Importvariables should skip parameters widgets
This commit is contained in:
parent
5bcf7b9edd
commit
f78e1f6f7d
@ -49,38 +49,40 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
|||||||
var parser = widgetPointer.wiki.parseTiddler(title,{parseAsInline:true});
|
var parser = widgetPointer.wiki.parseTiddler(title,{parseAsInline:true});
|
||||||
if(parser) {
|
if(parser) {
|
||||||
var parseTreeNode = parser.tree[0];
|
var parseTreeNode = parser.tree[0];
|
||||||
while(parseTreeNode && parseTreeNode.type === "set") {
|
while(parseTreeNode && ["set","parameters"].indexOf(parseTreeNode.type) !== -1) {
|
||||||
var node = {
|
if(parseTreeNode.type === "set") {
|
||||||
type: "set",
|
var node = {
|
||||||
attributes: parseTreeNode.attributes,
|
type: "set",
|
||||||
params: parseTreeNode.params,
|
attributes: parseTreeNode.attributes,
|
||||||
isMacroDefinition: parseTreeNode.isMacroDefinition
|
params: parseTreeNode.params,
|
||||||
};
|
isMacroDefinition: parseTreeNode.isMacroDefinition
|
||||||
if (parseTreeNode.isMacroDefinition) {
|
};
|
||||||
// Macro definitions can be folded into
|
if (parseTreeNode.isMacroDefinition) {
|
||||||
// current widget instead of adding
|
// Macro definitions can be folded into
|
||||||
// another link to the chain.
|
// current widget instead of adding
|
||||||
var widget = widgetPointer.makeChildWidget(node);
|
// another link to the chain.
|
||||||
widget.computeAttributes();
|
var widget = widgetPointer.makeChildWidget(node);
|
||||||
widget.execute();
|
widget.computeAttributes();
|
||||||
// We SHALLOW copy over all variables
|
widget.execute();
|
||||||
// in widget. We can't use
|
// We SHALLOW copy over all variables
|
||||||
// $tw.utils.assign, because that copies
|
// in widget. We can't use
|
||||||
// up the prototype chain, which we
|
// $tw.utils.assign, because that copies
|
||||||
// don't want.
|
// up the prototype chain, which we
|
||||||
$tw.utils.each(Object.keys(widget.variables), function(key) {
|
// don't want.
|
||||||
widgetPointer.variables[key] = widget.variables[key];
|
$tw.utils.each(Object.keys(widget.variables), function(key) {
|
||||||
});
|
widgetPointer.variables[key] = widget.variables[key];
|
||||||
} else {
|
});
|
||||||
widgetPointer.children = [widgetPointer.makeChildWidget(node)];
|
} else {
|
||||||
// No more regenerating children for
|
widgetPointer.children = [widgetPointer.makeChildWidget(node)];
|
||||||
// this widget. If it needs to refresh,
|
// No more regenerating children for
|
||||||
// it'll do so along with the the whole
|
// this widget. If it needs to refresh,
|
||||||
// importvariable tree.
|
// it'll do so along with the the whole
|
||||||
if (widgetPointer != this) {
|
// importvariable tree.
|
||||||
widgetPointer.makeChildWidgets = function(){};
|
if (widgetPointer != this) {
|
||||||
|
widgetPointer.makeChildWidgets = function(){};
|
||||||
|
}
|
||||||
|
widgetPointer = widgetPointer.children[0];
|
||||||
}
|
}
|
||||||
widgetPointer = widgetPointer.children[0];
|
|
||||||
}
|
}
|
||||||
parseTreeNode = parseTreeNode.children && parseTreeNode.children[0];
|
parseTreeNode = parseTreeNode.children && parseTreeNode.children[0];
|
||||||
}
|
}
|
||||||
|
@ -683,7 +683,7 @@ describe("Widget module", function() {
|
|||||||
expect(wrapper.innerHTML).toBe("<p>New value</p>");
|
expect(wrapper.innerHTML).toBe("<p>New value</p>");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should can mix setWidgets and macros when importing", function() {
|
it("should support mixed setWidgets and macros when importing", function() {
|
||||||
var wiki = new $tw.Wiki();
|
var wiki = new $tw.Wiki();
|
||||||
// Add some tiddlers
|
// Add some tiddlers
|
||||||
wiki.addTiddlers([
|
wiki.addTiddlers([
|
||||||
@ -699,6 +699,20 @@ describe("Widget module", function() {
|
|||||||
expect(wrapper.innerHTML).toBe("<p>Aval Bval Cval</p>");
|
expect(wrapper.innerHTML).toBe("<p>Aval Bval Cval</p>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should skip parameters widgets when importing", function() {
|
||||||
|
var wiki = new $tw.Wiki();
|
||||||
|
// Add some tiddlers
|
||||||
|
wiki.addTiddlers([
|
||||||
|
{title: "B", text: "<$parameters bee=nothing><$set name='B' value='Bval'>\n\ndummy text</$set></$parameters>"},
|
||||||
|
]);
|
||||||
|
var text = "\\import B\n<<B>>";
|
||||||
|
var widgetNode = createWidgetNode(parseText(text,wiki),wiki);
|
||||||
|
// Render the widget node to the DOM
|
||||||
|
var wrapper = renderWidgetNode(widgetNode);
|
||||||
|
// Test the rendering
|
||||||
|
expect(wrapper.innerHTML).toBe("<p>Bval</p>");
|
||||||
|
});
|
||||||
|
|
||||||
it("can have more than one macroDef variable imported", function() {
|
it("can have more than one macroDef variable imported", function() {
|
||||||
var wiki = new $tw.Wiki();
|
var wiki = new $tw.Wiki();
|
||||||
wiki.addTiddlers([
|
wiki.addTiddlers([
|
||||||
|
Loading…
Reference in New Issue
Block a user