mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-12 00:50:02 +00:00
Refactor the list widget to get rid of some hacks
As promised.
This commit is contained in:
parent
51394e50e8
commit
0b1f0a5fab
@ -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();
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
title: $:/core/ui/TiddlerFields
|
||||
|
||||
<table class="tw-view-field-table"><tbody><$list filter="[is[current]fields[]sort[title]] -text" template="$:/core/ui/TiddlerFieldTemplate" hackCurrentTiddler=true/>
|
||||
<table class="tw-view-field-table"><tbody><$list filter="[is[current]fields[]sort[title]] -text" template="$:/core/ui/TiddlerFieldTemplate" variable="listItem"/>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -4,5 +4,5 @@ modifier: JeremyRuston
|
||||
\define frame-classes()
|
||||
tw-tiddler-frame $(missingTiddlerClass)$ $(shadowTiddlerClass)$ $(systemTiddlerClass)$
|
||||
\end
|
||||
<div class=<<frame-classes>>><$list filter="[is[shadow]!has[draft.of]tag[$:/tags/ViewTemplate]] [!is[shadow]!has[draft.of]tag[$:/tags/ViewTemplate]]" hackTemplate=true/>
|
||||
<div class=<<frame-classes>>><$list filter="[is[shadow]!has[draft.of]tag[$:/tags/ViewTemplate]] [!is[shadow]!has[draft.of]tag[$:/tags/ViewTemplate]]" variable="listItem"><$transclude tiddler=<<listItem>>/></$list>
|
||||
</div>
|
||||
|
@ -3,5 +3,5 @@ title: $:/snippets/allfields
|
||||
\define renderfield(title)
|
||||
<tr class="tw-view-field"><td class="tw-view-field-name">''$title$'':</td><td class="tw-view-field-value">//{{$:/docs/fields/$title$}}//</td></tr>
|
||||
\end
|
||||
<table class="tw-view-field-table"><tbody><$list filter="[fields[]sort[title]]"><$macrocall $name="renderfield" title=<<listItem>>/></$list>
|
||||
<table class="tw-view-field-table"><tbody><$list filter="[fields[]sort[title]]" variable="listItem"><$macrocall $name="renderfield" title=<<listItem>>/></$list>
|
||||
</tbody></table>
|
||||
|
@ -449,7 +449,7 @@ describe("Widget module", function() {
|
||||
var wiki = new $tw.Wiki();
|
||||
// Add some tiddlers
|
||||
wiki.addTiddlers([
|
||||
{title: "$:/myTemplate", text: "<$tiddler tiddler=<<listItem>>><$view field='title'/></$tiddler>"},
|
||||
{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("<p>TiddlerFourTiddlerOneTiddlerThreeTiddlerTwo</p>");
|
||||
expect(wrapper.innerHTML).toBe("<p>(TiddlerFour)(TiddlerOne)(TiddlerThree)(TiddlerTwo)</p>");
|
||||
});
|
||||
|
||||
it("should deal with the list widget and empty lists", function() {
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user