integrate tests into doc panel (fixes #782)
This commit is contained in:
parent
afb9b2f6c2
commit
9c044300ef
1 changed files with 105 additions and 27 deletions
|
@ -6,14 +6,18 @@ Ox.DocPanel <f> Documentation Panel
|
||||||
options <o> Options object
|
options <o> Options object
|
||||||
collapsible <b|false> If true, the list can be collabsed
|
collapsible <b|false> If true, the list can be collabsed
|
||||||
element <e> Default content
|
element <e> Default content
|
||||||
files <a|[]> Files to parse for docs
|
files <a|[]> Files to parse for docs (alternative to items option)
|
||||||
getModule <f> Returns module for given item
|
getModule <f> Returns module for given item
|
||||||
getSection <f> Returns section for given item
|
getSection <f> Returns section for given item
|
||||||
items <a|[]> Array of doc items (alternative to files options)
|
items <a|[]> Array of doc items (alternative to files option)
|
||||||
path <s|''> Path prefix
|
path <s|''> Path prefix
|
||||||
replace <[[]]|[]> See Ox.SyntaxHighlighter
|
replace <[[]]|[]> See Ox.SyntaxHighlighter
|
||||||
resizable <b|true> If true, list is resizable
|
resizable <b|true> If true, list is resizable
|
||||||
resize <a|[128, 256, 384]> List resize positions
|
resize <a|[128, 256, 384]> List resize positions
|
||||||
|
runTests <b|false> If true, run tests
|
||||||
|
selected <s|''> Id of the selected item
|
||||||
|
showTests <b|false> If true, show test results in list
|
||||||
|
showTooltips <b|false> If true, show test result tooltips in list
|
||||||
size <s|256> Default list size
|
size <s|256> Default list size
|
||||||
self <o> Shared private variable
|
self <o> Shared private variable
|
||||||
load <!> Fires once all docs are loaded
|
load <!> Fires once all docs are loaded
|
||||||
|
@ -39,8 +43,11 @@ Ox.DocPanel = function(options, self) {
|
||||||
replace: [],
|
replace: [],
|
||||||
resizable: false,
|
resizable: false,
|
||||||
resize: [128, 256, 384],
|
resize: [128, 256, 384],
|
||||||
|
runTests: false,
|
||||||
selected: '',
|
selected: '',
|
||||||
size: 256
|
showTests: false,
|
||||||
|
showTooltips: false,
|
||||||
|
size: 256,
|
||||||
})
|
})
|
||||||
.options(options || {})
|
.options(options || {})
|
||||||
.update({
|
.update({
|
||||||
|
@ -49,6 +56,8 @@ Ox.DocPanel = function(options, self) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.results = {};
|
||||||
|
|
||||||
self.$list = Ox.Element();
|
self.$list = Ox.Element();
|
||||||
self.$page = Ox.Element();
|
self.$page = Ox.Element();
|
||||||
|
|
||||||
|
@ -77,10 +86,49 @@ Ox.DocPanel = function(options, self) {
|
||||||
}), function(docItems) {
|
}), function(docItems) {
|
||||||
self.options.items = docItems;
|
self.options.items = docItems;
|
||||||
renderList();
|
renderList();
|
||||||
|
self.options.runTests && runTests();
|
||||||
that.triggerEvent('load', {items: docItems});
|
that.triggerEvent('load', {items: docItems});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
renderList();
|
renderList();
|
||||||
|
self.options.runTests && runTests();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIcon(id, expanded) {
|
||||||
|
var $icon = null, results = self.results[id];
|
||||||
|
if (!Ox.isEmpty(self.results)) {
|
||||||
|
$icon = Ox.Theme.getColorImage(
|
||||||
|
'symbol' + (expanded === true ? 'Down' : expanded === false ? 'Right' : 'Center'),
|
||||||
|
!results ? 'none' : results.failed === 0 ? 'passed' : 'failed',
|
||||||
|
self.options.showTooltips ? getTooltip(results) : null
|
||||||
|
);
|
||||||
|
} else if (!Ox.endsWith(id, '/')) {
|
||||||
|
$icon = $('<img>').attr({src: Ox.UI.getImageURL('symbolCenter')});
|
||||||
|
}
|
||||||
|
return $icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getItemByName(name) {
|
||||||
|
var item = {};
|
||||||
|
Ox.forEach(self.options.items, function(v) {
|
||||||
|
if (v.name == name) {
|
||||||
|
item = v;
|
||||||
|
Ox.Break();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTooltip(results) {
|
||||||
|
return results
|
||||||
|
? results.passed + ' test'
|
||||||
|
+ (results.passed == 1 ? '' : 's') + ' passed'
|
||||||
|
+ (results.failed
|
||||||
|
? ', ' + results.failed + ' test'
|
||||||
|
+ (results.failed == 1 ? '' : 's') + ' failed'
|
||||||
|
: ''
|
||||||
|
)
|
||||||
|
: 'No tests';
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseFiles(callback) {
|
function parseFiles(callback) {
|
||||||
|
@ -98,12 +146,12 @@ Ox.DocPanel = function(options, self) {
|
||||||
function renderList() {
|
function renderList() {
|
||||||
var treeItems = [];
|
var treeItems = [];
|
||||||
self.options.items.forEach(function(docItem) {
|
self.options.items.forEach(function(docItem) {
|
||||||
var moduleIndex, sectionIndex;
|
var moduleIndex, results, sectionIndex;
|
||||||
docItem.module = self.options.getModule(docItem);
|
docItem.module = self.options.getModule(docItem);
|
||||||
moduleIndex = Ox.getIndexById(treeItems, '_' + docItem.module);
|
moduleIndex = Ox.getIndexById(treeItems, docItem.module + '/');
|
||||||
if (moduleIndex == -1) {
|
if (moduleIndex == -1) {
|
||||||
treeItems.push({
|
treeItems.push({
|
||||||
id: '_' + docItem.module,
|
id: docItem.module + '/',
|
||||||
items: [],
|
items: [],
|
||||||
title: docItem.module
|
title: docItem.module
|
||||||
});
|
});
|
||||||
|
@ -113,11 +161,11 @@ Ox.DocPanel = function(options, self) {
|
||||||
if (docItem.section) {
|
if (docItem.section) {
|
||||||
sectionIndex = Ox.getIndexById(
|
sectionIndex = Ox.getIndexById(
|
||||||
treeItems[moduleIndex].items,
|
treeItems[moduleIndex].items,
|
||||||
'_' + docItem.module + '_' + docItem.section
|
docItem.module + '/' + docItem.section + '/'
|
||||||
);
|
);
|
||||||
if (sectionIndex == -1) {
|
if (sectionIndex == -1) {
|
||||||
treeItems[moduleIndex].items.push({
|
treeItems[moduleIndex].items.push({
|
||||||
id: '_' + docItem.module + '_' + docItem.section,
|
id: docItem.module + '/' + docItem.section + '/',
|
||||||
items: [],
|
items: [],
|
||||||
title: docItem.section
|
title: docItem.section
|
||||||
});
|
});
|
||||||
|
@ -129,7 +177,9 @@ Ox.DocPanel = function(options, self) {
|
||||||
? treeItems[moduleIndex].items[sectionIndex]
|
? treeItems[moduleIndex].items[sectionIndex]
|
||||||
: treeItems[moduleIndex]
|
: treeItems[moduleIndex]
|
||||||
).items.push({
|
).items.push({
|
||||||
id: docItem.name,
|
id: docItem.module + '/' + (
|
||||||
|
docItem.section ? docItem.section + '/' : ''
|
||||||
|
) + docItem.name,
|
||||||
title: docItem.name
|
title: docItem.name
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -141,42 +191,70 @@ Ox.DocPanel = function(options, self) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
self.$list = Ox.TreeList({
|
self.$list = Ox.TreeList({
|
||||||
|
icon: self.options.showTests
|
||||||
|
? getIcon
|
||||||
|
: Ox.UI.getImageURL('symbolCenter'),
|
||||||
items: treeItems,
|
items: treeItems,
|
||||||
selected: self.options.selected
|
selected: self.options.selected
|
||||||
? [self.options.selected] : '',
|
? [self.options.selected] : '',
|
||||||
width: self.options.size - Ox.UI.SCROLLBAR_SIZE
|
width: self.options.size
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
select: function(data) {
|
select: function(data) {
|
||||||
selectItem(data.ids.length ? data.ids[0] : '')
|
selectItem(data.ids.length ? data.ids[0] : '')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
that.$element.replaceElement(0, self.$list);
|
self.$panel.replaceElement(0, self.$list);
|
||||||
selectItem(self.options.selected);
|
selectItem(self.options.selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getItemByName(name) {
|
function runTests() {
|
||||||
var item = {};
|
setTimeout(function() {
|
||||||
Ox.forEach(self.options.items, function(v) {
|
Ox.load({Geo: {}, Image: {}, Unicode: {}}, function() {
|
||||||
if (v.name == name) {
|
Ox.test(self.options.items, function(results) {
|
||||||
item = v;
|
results.forEach(function(result) {
|
||||||
Ox.Break();
|
var item = getItemByName(result.name),
|
||||||
}
|
passed = result.passed ? 'passed' : 'failed';
|
||||||
|
item.tests[Ox.indexOf(item.tests, function(test) {
|
||||||
|
return test.statement == result.statement;
|
||||||
|
})] = result;
|
||||||
|
['', item.module + '/'].concat(
|
||||||
|
item.section ? item.module + '/' + item.section + '/' : [],
|
||||||
|
item.module + '/' + (item.section ? item.section + '/' : '') + item.name
|
||||||
|
).forEach(function(key) {
|
||||||
|
self.results[key] = self.results[key] || {passed: 0, failed: 0};
|
||||||
|
self.results[key][passed]++;
|
||||||
});
|
});
|
||||||
return item;
|
});
|
||||||
|
renderList();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectItem(id) {
|
function selectItem(id) {
|
||||||
|
var item, name;
|
||||||
|
if (id && !Ox.contains(id, '/')) {
|
||||||
|
name = id;
|
||||||
|
item = getItemByName(name);
|
||||||
|
id = item ? item.module + '/' + (
|
||||||
|
item.section ? item.section + '/' : ''
|
||||||
|
) + item.name : '';
|
||||||
|
}
|
||||||
if (id) {
|
if (id) {
|
||||||
self.options.selected = id;
|
self.options.selected = id;
|
||||||
if (self.options.selected[0] != '_') {
|
if (!Ox.endsWith(self.options.selected, '/')) {
|
||||||
self.$list.options({selected: [id]});
|
if (!item) {
|
||||||
|
name = self.options.selected.split('/').slice(-1);
|
||||||
|
item = getItemByName(name);
|
||||||
|
}
|
||||||
|
self.$list.options({selected: [self.options.selected]});
|
||||||
self.$page = Ox.DocPage({
|
self.$page = Ox.DocPage({
|
||||||
item: getItemByName(self.options.selected),
|
item: item,
|
||||||
replace: self.options.replace
|
replace: self.options.replace
|
||||||
});
|
});
|
||||||
that.$element.replaceElement(1, self.$page);
|
that.$element.replaceElement(1, self.$page);
|
||||||
that.triggerEvent('select', {id: self.options.selected});
|
that.triggerEvent('select', {id: name});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.$page.empty().append(self.options.element);
|
self.$page.empty().append(self.options.element);
|
||||||
|
@ -184,9 +262,9 @@ Ox.DocPanel = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortByTitle(a, b) {
|
function sortByTitle(a, b) {
|
||||||
return a.title < b.title ? -1
|
var a = Ox.stripTags(a.title).toLowerCase(),
|
||||||
: a.title > b.title ? 1
|
b = Ox.stripTags(b.title).toLowerCase();
|
||||||
: 0;
|
return a < b ? -1 : a > b ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
|
Loading…
Reference in a new issue