1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-25 17:40:29 +00:00

Extend testcase-view to be able to view other fields

This commit is contained in:
jeremy@jermolene.com 2023-04-11 17:59:35 +01:00
parent c348924838
commit 3c61e8679d
3 changed files with 13 additions and 4 deletions

View File

@ -38,7 +38,7 @@ TestCaseViewWidget.prototype.render = function(parent,nextSibling) {
}
// Render the transclusion
if(pointer && pointer.testcaseRawTiddler) {
pointer.testcaseRawTiddler(parent,nextSibling,this.testcaseViewTiddler)
pointer.testcaseRawTiddler(parent,nextSibling,this.testcaseViewTiddler,this.testcaseViewField)
}
};
@ -47,6 +47,7 @@ Compute the internal state of the widget
*/
TestCaseViewWidget.prototype.execute = function() {
this.testcaseViewTiddler = this.getAttribute("tiddler");
this.testcaseViewField = this.getAttribute("field","text");
};
/*

View File

@ -67,8 +67,11 @@ TestCaseWidget.prototype.render = function(parent,nextSibling) {
this.setVariable("transclusion",$tw.utils.hashString(this.testcaseWiki.getTiddlersAsJson("[all[tiddlers]]")));
// Generate a `testcaseInfo` variable that contains information about the subwiki in JSON format
var testcaseInfoData = {
titles: this.testcaseWiki.allTitles()
tiddlers: {} // Hashmap of tiddler titles mapped to array of field names
};
this.testcaseWiki.each(function(tiddler,title) {
testcaseInfoData.tiddlers[title] = Object.keys(tiddler.fields);
});
this.setVariable("testcaseInfo",JSON.stringify(testcaseInfoData));
// Render children from the template
this.renderChildren(parent,nextSibling);
@ -105,10 +108,14 @@ TestCaseWidget.prototype.testcaseRenderTiddler = function(parent,nextSibling,tit
/*
View a test case tiddler in plain text
*/
TestCaseWidget.prototype.testcaseRawTiddler = function(parent,nextSibling,title) {
TestCaseWidget.prototype.testcaseRawTiddler = function(parent,nextSibling,title,field) {
var self = this;
// Render a text widget with the text of a tiddler
var text = this.testcaseWiki.getTiddlerText(title);
var text="",
tiddler = this.testcaseWiki.getTiddler(title);
if(tiddler) {
text = tiddler.getFieldString(field,"");
}
parent.insertBefore(this.document.createTextNode(text),nextSibling);
};

View File

@ -15,3 +15,4 @@ The content of the `<$testcase-view>` widget is not displayed.
|!Attribute |!Description |
|<<.attr tiddler>> |Title of the tiddler to be displayed |
|<<.attr field>> |Optional field to be displayed (defaults to "text") |