diff --git a/core/modules/new_widgets/list.js b/core/modules/new_widgets/list.js index 7b58af661..522c1f104 100755 --- a/core/modules/new_widgets/list.js +++ b/core/modules/new_widgets/list.js @@ -44,6 +44,7 @@ ListWidget.prototype.execute = function() { // Get our attributes this.template = this.getAttribute("template"); this.editTemplate = this.getAttribute("editTemplate"); + this.variableName = this.getAttribute("variable","currentTiddler"); // Compose the list elements this.list = this.getTiddlerList(); var members = [], @@ -88,27 +89,20 @@ ListWidget.prototype.makeItemTemplate = function(title) { template = this.editTemplate; } // Compose the transclusion of the template - if(this.hasAttribute("hackTemplate")) { - templateTree = [{type: "transclude", attributes: {tiddler: {type: "string", value: title}}}]; + if(template) { + templateTree = [{type: "transclude", attributes: {tiddler: {type: "string", value: template}}}]; } else { - if(template) { - templateTree = [{type: "transclude", attributes: {tiddler: {type: "string", value: template}}}]; + if(this.parseTreeNode.children && this.parseTreeNode.children.length > 0) { + templateTree = this.parseTreeNode.children; } else { - if(this.parseTreeNode.children && this.parseTreeNode.children.length > 0) { - templateTree = this.parseTreeNode.children; - } else { - // Default template is a link to the title - templateTree = [{type: "element", tag: this.parseTreeNode.isBlock ? "div" : "span", children: [{type: "link", attributes: {to: {type: "string", value: title}}, children: [ - {type: "text", text: title} - ]}]}]; - } - } - if(!this.hasAttribute("hackCurrentTiddler")) { - templateTree = [{type: "tiddler", attributes: {tiddler: {type: "string", value: title}}, children: templateTree}] + // Default template is a link to the title + templateTree = [{type: "element", tag: this.parseTreeNode.isBlock ? "div" : "span", children: [{type: "link", attributes: {to: {type: "string", value: title}}, children: [ + {type: "text", text: title} + ]}]}]; } } // Return the list item - return {type: "listitem", itemTitle: title, children: templateTree}; + return {type: "listitem", itemTitle: title, variableName: this.variableName, children: templateTree}; }; /* @@ -242,7 +236,7 @@ Compute the internal state of the widget */ ListItemWidget.prototype.execute = function() { // Set the current list item title - this.setVariable("listItem",this.parseTreeNode.itemTitle); + this.setVariable(this.parseTreeNode.variableName,this.parseTreeNode.itemTitle); // Construct the child widgets this.makeChildWidgets(); }; diff --git a/core/ui/TiddlerFields.tid b/core/ui/TiddlerFields.tid index 2f5689dc4..897615dd0 100644 --- a/core/ui/TiddlerFields.tid +++ b/core/ui/TiddlerFields.tid @@ -1,5 +1,5 @@ title: $:/core/ui/TiddlerFields -<$list filter="[is[current]fields[]sort[title]] -text" template="$:/core/ui/TiddlerFieldTemplate" hackCurrentTiddler=true/> +
<$list filter="[is[current]fields[]sort[title]] -text" template="$:/core/ui/TiddlerFieldTemplate" variable="listItem"/>
diff --git a/core/ui/ViewTemplate.tid b/core/ui/ViewTemplate.tid index a68b3f591..c9f2dadca 100644 --- a/core/ui/ViewTemplate.tid +++ b/core/ui/ViewTemplate.tid @@ -4,5 +4,5 @@ modifier: JeremyRuston \define frame-classes() tw-tiddler-frame $(missingTiddlerClass)$ $(shadowTiddlerClass)$ $(systemTiddlerClass)$ \end -
>><$list filter="[is[shadow]!has[draft.of]tag[$:/tags/ViewTemplate]] [!is[shadow]!has[draft.of]tag[$:/tags/ViewTemplate]]" hackTemplate=true/> +
>><$list filter="[is[shadow]!has[draft.of]tag[$:/tags/ViewTemplate]] [!is[shadow]!has[draft.of]tag[$:/tags/ViewTemplate]]" variable="listItem"><$transclude tiddler=<>/>
diff --git a/core/wiki/allfields.tid b/core/wiki/allfields.tid index 0b3ef765a..214b61e0a 100644 --- a/core/wiki/allfields.tid +++ b/core/wiki/allfields.tid @@ -3,5 +3,5 @@ title: $:/snippets/allfields \define renderfield(title) ''$title$''://{{$:/docs/fields/$title$}}// \end -<$list filter="[fields[]sort[title]]"><$macrocall $name="renderfield" title=<>/> +
<$list filter="[fields[]sort[title]]" variable="listItem"><$macrocall $name="renderfield" title=<>/>
diff --git a/editions/test/tiddlers/tests/test-widget.js b/editions/test/tiddlers/tests/test-widget.js index c5a201e89..e970a6d4b 100755 --- a/editions/test/tiddlers/tests/test-widget.js +++ b/editions/test/tiddlers/tests/test-widget.js @@ -449,7 +449,7 @@ describe("Widget module", function() { var wiki = new $tw.Wiki(); // Add some tiddlers wiki.addTiddlers([ - {title: "$:/myTemplate", text: "<$tiddler tiddler=<>><$view field='title'/>"}, + {title: "$:/myTemplate", text: "(<$view field='title'/>)"}, {title: "TiddlerOne", text: "Jolly Old World"}, {title: "TiddlerTwo", text: "Worldly Old Jelly"}, {title: "TiddlerThree", text: "Golly Gosh"}, @@ -462,7 +462,7 @@ describe("Widget module", function() { var wrapper = renderWidgetNode(widgetNode); //console.log(require("util").inspect(widgetNode,{depth:8,colors:true})); // Test the rendering - expect(wrapper.innerHTML).toBe("

TiddlerFourTiddlerOneTiddlerThreeTiddlerTwo

"); + expect(wrapper.innerHTML).toBe("

(TiddlerFour)(TiddlerOne)(TiddlerThree)(TiddlerTwo)

"); }); it("should deal with the list widget and empty lists", function() { diff --git a/editions/tw5.com/tiddlers/widgets/ListWidget.tid b/editions/tw5.com/tiddlers/widgets/ListWidget.tid index 75e731d43..e2cd9528a 100644 --- a/editions/tw5.com/tiddlers/widgets/ListWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ListWidget.tid @@ -24,16 +24,13 @@ The content of the `<$list>` widget is an optional template to use for rendering |filter |The TiddlerFilter to display | |template |The title of a template tiddler for rendering each tiddler in the list | |editTemplate |An alternative template to use for DraftTiddlers in edit mode | +|variable |The [[widget variable|WidgetVariables]] name to be assigned the title of each tiddler in the list. Defaults to ''currentTiddler'' | |emptyMessage |Message to be displayed when the list is empty | |listview |Optional name of module responsible for animating/processing the list | |history |The title of the tiddler containing the navigation history | -|hackTemplate |If this attribute is present then the list items are directly transcluded without altering the current tiddler or using a template | -|hackCurrentTiddler |If this attribute is present then the template is directly transcluded without altering the current tiddler | //`listview` and `history` are temporarily unimplemented // -//`hackTemplate` and `hackCurrentTiddler` are temporary hacks that will be removed// - !! Handling edit mode The `<$list>` widget can optionally render draft tiddlers through a different template tiddler than ordinary tiddlers -- see DraftMechanism for a discussion of how this capability is used.