mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-03-12 14:38:10 +00:00
Switch testcase widget to use an intrinsic template
Makes things much simpler
This commit is contained in:
parent
88f4ad0efd
commit
2cf0423401
@ -1,68 +0,0 @@
|
|||||||
/*\
|
|
||||||
title: $:/core/modules/widgets/testcase-transclude.js
|
|
||||||
type: application/javascript
|
|
||||||
module-type: widget
|
|
||||||
|
|
||||||
Widget to transclude a tiddler from a test case
|
|
||||||
|
|
||||||
\*/
|
|
||||||
(function(){
|
|
||||||
|
|
||||||
/*jslint node: true, browser: true */
|
|
||||||
/*global $tw: false */
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var Widget = require("$:/core/modules/widgets/widget.js").widget,
|
|
||||||
TestCaseWidget = require("$:/core/modules/widgets/testcase.js").testcase;
|
|
||||||
|
|
||||||
var TestCaseTranscludeWidget = function(parseTreeNode,options) {
|
|
||||||
this.initialise(parseTreeNode,options);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Inherit from the base widget class
|
|
||||||
*/
|
|
||||||
TestCaseTranscludeWidget.prototype = new Widget();
|
|
||||||
|
|
||||||
/*
|
|
||||||
Render this widget into the DOM
|
|
||||||
*/
|
|
||||||
TestCaseTranscludeWidget.prototype.render = function(parent,nextSibling) {
|
|
||||||
this.parentDomNode = parent;
|
|
||||||
this.computeAttributes();
|
|
||||||
this.execute();
|
|
||||||
// Find the parent testcase
|
|
||||||
var pointer = this.parentWidget;
|
|
||||||
while(pointer && !(pointer instanceof TestCaseWidget)) {
|
|
||||||
pointer = pointer.parentWidget;
|
|
||||||
}
|
|
||||||
// Render the transclusion
|
|
||||||
if(pointer && pointer.testcaseRenderTiddler) {
|
|
||||||
pointer.testcaseRenderTiddler(parent,nextSibling,this.testcaseTranscludeTiddler,this.testcaseTranscludeMode)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Compute the internal state of the widget
|
|
||||||
*/
|
|
||||||
TestCaseTranscludeWidget.prototype.execute = function() {
|
|
||||||
this.testcaseTranscludeTiddler = this.getAttribute("tiddler");
|
|
||||||
this.testcaseTranscludeMode = this.getAttribute("mode");
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
|
||||||
*/
|
|
||||||
TestCaseTranscludeWidget.prototype.refresh = function(changedTiddlers) {
|
|
||||||
var changedAttributes = this.computeAttributes();
|
|
||||||
if($tw.utils.count(changedAttributes) > 0) {
|
|
||||||
this.refreshSelf();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
exports["testcase-transclude"] = TestCaseTranscludeWidget;
|
|
||||||
|
|
||||||
})();
|
|
@ -1,68 +0,0 @@
|
|||||||
/*\
|
|
||||||
title: $:/core/modules/widgets/testcase-view.js
|
|
||||||
type: application/javascript
|
|
||||||
module-type: widget
|
|
||||||
|
|
||||||
Widget to render a plain text view of a tiddler from a test case
|
|
||||||
|
|
||||||
\*/
|
|
||||||
(function(){
|
|
||||||
|
|
||||||
/*jslint node: true, browser: true */
|
|
||||||
/*global $tw: false */
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var Widget = require("$:/core/modules/widgets/widget.js").widget,
|
|
||||||
TestCaseWidget = require("$:/core/modules/widgets/testcase.js").testcase;
|
|
||||||
|
|
||||||
var TestCaseViewWidget = function(parseTreeNode,options) {
|
|
||||||
this.initialise(parseTreeNode,options);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Inherit from the base widget class
|
|
||||||
*/
|
|
||||||
TestCaseViewWidget.prototype = new Widget();
|
|
||||||
|
|
||||||
/*
|
|
||||||
Render this widget into the DOM
|
|
||||||
*/
|
|
||||||
TestCaseViewWidget.prototype.render = function(parent,nextSibling) {
|
|
||||||
this.parentDomNode = parent;
|
|
||||||
this.computeAttributes();
|
|
||||||
this.execute();
|
|
||||||
// Find the parent testcase
|
|
||||||
var pointer = this.parentWidget;
|
|
||||||
while(pointer && !(pointer instanceof TestCaseWidget)) {
|
|
||||||
pointer = pointer.parentWidget;
|
|
||||||
}
|
|
||||||
// Render the transclusion
|
|
||||||
if(pointer && pointer.testcaseRawTiddler) {
|
|
||||||
pointer.testcaseRawTiddler(parent,nextSibling,this.testcaseViewTiddler,this.testcaseViewField)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Compute the internal state of the widget
|
|
||||||
*/
|
|
||||||
TestCaseViewWidget.prototype.execute = function() {
|
|
||||||
this.testcaseViewTiddler = this.getAttribute("tiddler");
|
|
||||||
this.testcaseViewField = this.getAttribute("field","text");
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
|
||||||
*/
|
|
||||||
TestCaseViewWidget.prototype.refresh = function(changedTiddlers) {
|
|
||||||
var changedAttributes = this.computeAttributes();
|
|
||||||
if($tw.utils.count(changedAttributes) > 0) {
|
|
||||||
this.refreshSelf();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
exports["testcase-view"] = TestCaseViewWidget;
|
|
||||||
|
|
||||||
})();
|
|
@ -47,6 +47,8 @@ TestCaseWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
this.contentRoot.render(this.contentContainer,null);
|
this.contentRoot.render(this.contentContainer,null);
|
||||||
// Create a wiki
|
// Create a wiki
|
||||||
this.testcaseWiki = new $tw.Wiki();
|
this.testcaseWiki = new $tw.Wiki();
|
||||||
|
// Always load the core plugin
|
||||||
|
this.testcaseWiki.addTiddler(this.wiki.getTiddler("$:/core"));
|
||||||
// Load tiddlers from child data widgets
|
// Load tiddlers from child data widgets
|
||||||
var tiddlers = [];
|
var tiddlers = [];
|
||||||
this.findChildrenDataWidgets(this.contentRoot.children,"data",function(widget) {
|
this.findChildrenDataWidgets(this.contentRoot.children,"data",function(widget) {
|
||||||
@ -68,32 +70,13 @@ TestCaseWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
testcaseInfoData.tiddlers[title] = Object.keys(tiddler.fields);
|
testcaseInfoData.tiddlers[title] = Object.keys(tiddler.fields);
|
||||||
});
|
});
|
||||||
this.setVariable("testcaseInfo",JSON.stringify(testcaseInfoData));
|
this.setVariable("testcaseInfo",JSON.stringify(testcaseInfoData));
|
||||||
// Render children from the template
|
// Render the page root template of the subwiki
|
||||||
this.renderChildren(parent,nextSibling);
|
var rootWidget = this.testcaseWiki.makeTranscludeWidget(this.testcaseTemplate,{document: this.document, parseAsInline: false, parentWidget: this});
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Render a test case
|
|
||||||
*/
|
|
||||||
TestCaseWidget.prototype.testcaseRenderTiddler = function(parent,nextSibling,title,mode) {
|
|
||||||
var self = this;
|
|
||||||
// Parse and render a tiddler
|
|
||||||
var rootWidget = this.testcaseWiki.makeTranscludeWidget(title,{document: this.document, parseAsInline: mode === "inline", parentWidget: this});
|
|
||||||
rootWidget.render(parent,nextSibling);
|
rootWidget.render(parent,nextSibling);
|
||||||
};
|
// Trap changes in the wiki and refresh the rendering
|
||||||
|
this.testcaseWiki.addEventListener("change",function(changes) {
|
||||||
/*
|
rootWidget.refresh(changes,parent,nextSibling);
|
||||||
View a test case tiddler in plain text
|
});
|
||||||
*/
|
|
||||||
TestCaseWidget.prototype.testcaseRawTiddler = function(parent,nextSibling,title,field) {
|
|
||||||
var self = this;
|
|
||||||
// Render a text widget with the text of a tiddler
|
|
||||||
var text="",
|
|
||||||
tiddler = this.testcaseWiki.getTiddler(title);
|
|
||||||
if(tiddler) {
|
|
||||||
text = tiddler.getFieldString(field,"");
|
|
||||||
}
|
|
||||||
parent.insertBefore(this.document.createTextNode(text),nextSibling);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -101,18 +84,6 @@ Compute the internal state of the widget
|
|||||||
*/
|
*/
|
||||||
TestCaseWidget.prototype.execute = function() {
|
TestCaseWidget.prototype.execute = function() {
|
||||||
this.testcaseTemplate = this.getAttribute("template","$:/core/ui/testcases/DefaultTemplate");
|
this.testcaseTemplate = this.getAttribute("template","$:/core/ui/testcases/DefaultTemplate");
|
||||||
// Make child widgets
|
|
||||||
var parseTreeNodes = [{
|
|
||||||
type: "transclude",
|
|
||||||
attributes: {
|
|
||||||
tiddler: {
|
|
||||||
name: "tiddler",
|
|
||||||
type: "string",
|
|
||||||
value: this.testcaseTemplate
|
|
||||||
}
|
|
||||||
},
|
|
||||||
isBlock: true}];
|
|
||||||
this.makeChildWidgets(parseTreeNodes);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -124,7 +95,7 @@ TestCaseWidget.prototype.refresh = function(changedTiddlers) {
|
|||||||
this.refreshSelf();
|
this.refreshSelf();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return this.refreshChildren(changedTiddlers);
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,16 +6,16 @@ title: $:/core/ui/testcases/DefaultTemplate
|
|||||||
>
|
>
|
||||||
<div class="tc-testcase-wrapper">
|
<div class="tc-testcase-wrapper">
|
||||||
<div class="tc-testcase-header">
|
<div class="tc-testcase-header">
|
||||||
<h2><$testcase-transclude tiddler="Description" mode="inline"/></h2>
|
<h2><$transclude tiddler="Description" mode="inline"/></h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="tc-testcase-panes">
|
<div class="tc-testcase-panes">
|
||||||
<div class="tc-testcase-source">
|
<div class="tc-testcase-source">
|
||||||
<$macrocall $name="tabs" tabsList="[<testcaseInfo>jsonindexes[tiddlers]] -Description -ExpectedResult -[has[plugin-type]]" state=<<state>> default="Output" template="$:/core/ui/testcases/DefaultTemplate/Source"/>
|
<$macrocall $name="tabs" tabsList="[all[tiddlers]sort[]] -Description -ExpectedResult -[has[plugin-type]]" state=<<state>> default="Output" template="$:/core/ui/testcases/DefaultTemplate/Source"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="tc-testcase-divider">
|
<div class="tc-testcase-divider">
|
||||||
</div>
|
</div>
|
||||||
<div class="tc-testcase-output">
|
<div class="tc-testcase-output">
|
||||||
<$testcase-transclude tiddler="Output"/>
|
<$transclude tiddler="Output"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
title: $:/core/ui/testcases/DefaultTemplate/Source
|
title: $:/core/ui/testcases/DefaultTemplate/Source
|
||||||
|
|
||||||
<$list filter="[<testcaseInfo>jsonget[tiddlers],<currentTab>] -text -title +[limit[1]]" variable="ignore">
|
<$list filter="[<currentTab>fields[]] -text +[limit[1]]" variable="ignore">
|
||||||
<table class="tc-field-table">
|
<table class="tc-field-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><th>Field</th><th>Value</th></tr>
|
<tr><th>Field</th><th>Value</th></tr>
|
||||||
<$list filter="[<testcaseInfo>jsonget[tiddlers],<currentTab>] -text -title" variable="fieldName">
|
<$list filter="[<currentTab>fields[]sort[]] -text" variable="fieldName">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<$text text=<<fieldName>>/>
|
<$text text=<<fieldName>>/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<$testcase-view tiddler=<<currentTab>> field=<<fieldName>>/>
|
<$view tiddler=<<currentTab>> field=<<fieldName>>/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</$list>
|
</$list>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</$list>
|
</$list>
|
||||||
<pre><$testcase-view tiddler=<<currentTab>>/></pre>
|
<pre><$view tiddler=<<currentTab>>/></pre>
|
||||||
|
@ -37,6 +37,24 @@ Retrieves photographs of a particular user, identified by their user ID.
|
|||||||
|userID |ID of the user of whom to retrieve photos (eg 35468148136@N01) |
|
|userID |ID of the user of whom to retrieve photos (eg 35468148136@N01) |
|
||||||
|photoTiddlerTemplate |Optional title of tiddler specifying field values for the created photo tiddlers |
|
|photoTiddlerTemplate |Optional title of tiddler specifying field values for the created photo tiddlers |
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
<$testcase>
|
||||||
|
<$data $tiddler="$:/plugins/tiddlywiki/geospatial"/>
|
||||||
|
<$data title="Description" text="Get photographs from album"/>
|
||||||
|
<$data title="Output" text="""<$button>
|
||||||
|
<$macrocall $name="flickr-get-album-items" albumID="72157630297432522"/>
|
||||||
|
Get photos from album
|
||||||
|
</$button>
|
||||||
|
|
||||||
|
<$geomap
|
||||||
|
state=<<qualify "$:/state/demo-map">>
|
||||||
|
markers="[all[tiddlers+shadows]tag[$:/tags/FlickrPhoto]]"
|
||||||
|
/>
|
||||||
|
"""/>
|
||||||
|
|
||||||
|
</$testcase>
|
||||||
|
|
||||||
!!! `flickr-get-group-items` macro
|
!!! `flickr-get-group-items` macro
|
||||||
|
|
||||||
Retrieves photographs from a group, identified by the group ID.
|
Retrieves photographs from a group, identified by the group ID.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user