Revision: e8736ec1349b
Author: Janne Härkönen <[email protected]>
Date: Mon Jun 20 01:13:00 2011
Log: compile templates dynamically, some cleanup
http://code.google.com/p/robotframework/source/detail?r=e8736ec1349b
Modified:
/src/robot/webcontent/log.html
/src/robot/webcontent/log.js
/src/robot/webcontent/report.html
/src/robot/webcontent/view.js
=======================================
--- /src/robot/webcontent/log.html Fri Jun 17 06:31:25 2011
+++ /src/robot/webcontent/log.html Mon Jun 20 01:13:00 2011
@@ -1,7 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta http-equiv="Content-Type" content="text/x-jquery-tmpl;
charset=utf-8" />
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
@@ -38,8 +38,7 @@
removeJavaScriptDisabledWarning();
$(document).ready(function(){
var topsuite = window.testdata.suite();
- window.templates = initTemplates();
- addHeader(topsuite.name, 'Log');
+ initLayout(topsuite.name, 'Log');
addStatistics();
addErrors();
addTestExecutionLog(topsuite);
@@ -54,8 +53,8 @@
function addErrors() {
var errors = window.testdata.errors();
if (errors.length) {
- $.tmpl(window.templates.errorHeader).appendTo($('body'));
- $.tmpl(window.templates.error, errors).appendTo($('#error_table'));
+ $.tmpl('errorHeaderTemplate').appendTo($('body'));
+ $.tmpl('errorTemplate', errors).appendTo($('#error_table'));
}
}
@@ -83,29 +82,15 @@
function addTestExecutionLog(main) {
$('<h2>Test Execution Log</h2>').appendTo($('body'));
- var root = $.tmpl(window.templates.suite, main);
+ var root = $.tmpl('suiteTemplate', main);
root.appendTo($('body'));
if (main.status == "pass") {
$("#"+main.id+"_unfoldlink").click();
}
}
-
-function initTemplates() {
- return {
- totalStatRow: $('#total_statistics_row').template(),
- tagStatRow: $('#tag_statistics_row').template(),
- suiteStatRow: $('#suite_statistics_row').template(),
- errorHeader: $('#error_header_template').template(),
- error: $('#error_template').template(),
- suite: $('#suite_template').template(),
- test: $('#test_template').template(),
- keyword: $('#keyword_template').template(),
- message: $('#message_template').template(),
- };
-};
</script>
-<script type="text/html" id="total_statistics_row">
+<script type="text/x-jquery-tmpl" id="totalStatisticsRowTemplate">
<tr>
<td class="col_stat_name">
<div class="stat_name">
@@ -116,7 +101,7 @@
</tr>
</script>
-<script type="text/html" id="tag_statistics_row">
+<script type="text/x-jquery-tmpl" id="tagStatisticsRowTemplate">
<tr>
<td class="col_stat_name">
<div class="stat_name">
@@ -133,7 +118,7 @@
</tr>
</script>
-<script type="text/html" id="suite_statistics_row">
+<script type="text/x-jquery-tmpl" id="suiteStatisticsRowTemplate">
<tr>
<td class="col_stat_name">
<div class="stat_name">
@@ -144,12 +129,12 @@
</tr>
</script>
-<script type="text/html" id="error_header_template">
+<script type="text/x-jquery-tmpl" id="errorHeaderTemplate">
<h2>Test Execution Errors</h2>
<table class="errors" id="error_table"></table>
</script>
-<script type="text/html" id="error_template">
+<script type="text/x-jquery-tmpl" id="errorTemplate">
<tr>
<td class="time">
{{if link}}
@@ -164,7 +149,7 @@
</tr>
</script>
-<script type="text/html" id="suite_template">
+<script type="text/x-jquery-tmpl" id="suiteTemplate">
<table class="suite" id="${id}">
<tr>
<td>
@@ -194,7 +179,7 @@
<!-- TODO: Link (href) to source should be relative -->
<tr><th>Source:</th><td><a
href="${source}">${source}</a></td></tr>
<tr><th>Start / End / Elapsed:</th><td>${times.startTime} /
${times.endTime} / ${times.elapsedTime}</td></tr>
-
<tr><th>Status:</th><td>{{tmpl($data) '#stats_message_partial_template'}}</td></tr>
+
<tr><th>Status:</th><td>{{tmpl($data) 'suiteStatusMessageTemplate'}}</td></tr>
{{if message}}
<tr><th>Message:</th><td>${message}</td></tr>
{{/if}}
@@ -205,11 +190,7 @@
</table>
</script>
-<script type="text/html" id="stats_message_partial_template">
-${critical} critical test, ${criticalPassed} passed, <span
class="${criticalFailureClass}">${criticalFailed} failed</span><br
/>${total} test total, ${totalPassed} passed, <span
class="${totalFailureClass}">${totalFailed} failed</span>
-</script>
-
-<script type="text/html" id="test_template">
+<script type="text/x-jquery-tmpl" id="testTemplate">
<table class="test" id="${id}">
<tr>
<td>
@@ -254,7 +235,7 @@
</table>
</script>
-<script type="text/html" id="keyword_template">
+<script type="text/x-jquery-tmpl" id="keywordTemplate">
<table class="keyword" id="${id}">
<tr>
<td>
@@ -286,7 +267,7 @@
</table>
</script>
-<script type="text/html" id="message_template">
+<script type="text/x-jquery-tmpl" id="messageTemplate">
<table class="messages">
<tr>
<td class="time">${shortTime()}</td>
=======================================
--- /src/robot/webcontent/log.js Fri Jun 10 00:57:56 2011
+++ /src/robot/webcontent/log.js Mon Jun 20 01:13:00 2011
@@ -1,39 +1,29 @@
function openSuite(suiteId) {
- function populator(suite, childElement){
- addElements(suite.keyword, window.templates.keyword, childElement);
- addElements(suite.suite, window.templates.suite, childElement);
- addElements(suite.test, window.templates.test, childElement);
- }
- openElement(suiteId, populator);
+ openElement(suiteId, ['keyword', 'suite', 'test']);
}
function openTest(testId) {
- function populator(test, childElement){
- addElements(test.keyword, window.templates.keyword, childElement);
- }
- openElement(testId, populator);
+ openElement(testId, ['keyword']);
}
function openKeyword(kwId) {
- function populator(keyword, childElement){
- addElements(keyword.keyword, window.templates.keyword,
childElement);
- addElements(keyword.message, window.templates.message,
childElement);
- }
- openElement(kwId, populator);
+ openElement(kwId, ['keyword', 'message']);
}
-function addElements(elems, template, target){
+function addElements(elems, templateName, target){
for (var i = 0; elems(i); i++) {
- $.tmpl(template, elems(i)).appendTo(target);
+ $.tmpl(templateName, elems(i)).appendTo(target);
}
}
-function openElement(elementId, populator){
+function openElement(elementId, childrenNames){
var childElement = $("#"+elementId+"_children");
childElement.show();
if (!childElement.hasClass("populated")) {
- element = window.testdata.find(elementId);
- populator(element, childElement);
+ var element = window.testdata.find(elementId);
+ $.map(childrenNames, function (childName) {
+ addElements(element[childName], childName + 'Template',
childElement);
+ });
childElement.addClass("populated");
}
$('#'+elementId+'_foldlink').show();
=======================================
--- /src/robot/webcontent/report.html Fri Jun 17 06:31:25 2011
+++ /src/robot/webcontent/report.html Mon Jun 20 01:13:00 2011
@@ -1,7 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta http-equiv="Content-Type" content="text/x-jquery-tmpl;
charset=utf-8" />
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
@@ -37,8 +37,7 @@
$(document).ready(function () {
var topsuite = window.testdata.suite();
setBackground(topsuite);
- window.templates = initTemplates();
- addHeader(topsuite.name, 'Report');
+ initLayout(topsuite.name, 'Report');
addSummary(topsuite);
addStatistics();
if (window.location.hash) {
@@ -51,7 +50,7 @@
function addSummary(topsuite) {
var opts = {logURL: window.settings.logURL};
- $.tmpl(window.templates.summaryTable, topsuite,
opts).insertAfter($('#header_div'));
+ $.tmpl('summaryTableTemplate', topsuite,
opts).insertAfter($('#header_div'));
}
function showTotalsTab() {
@@ -69,24 +68,24 @@
function renderTotalSelector(linkTarget) {
emptyDetails();
var args = {linkTarget: linkTarget, totals_tab_status: 'tab_selected'};
- $.tmpl(window.templates.detailsHeader,
args).appendTo('#test_details_container');
-
$.tmpl(window.templates.totalDetailsSelector).appendTo('#test_details_container');
+ $.tmpl('detailsHeaderTemplate',
args).appendTo('#test_details_container');
+
$.tmpl('totalDetailsSelectorTemplate').appendTo('#test_details_container');
}
function renderTagsSelector(linkTarget) {
emptyDetails();
var args = {linkTarget: linkTarget, tags_tab_status: 'tab_selected'};
var tagstats = {tags: window.testdata.statistics().tag};
- $.tmpl(window.templates.detailsHeader,
args).appendTo('#test_details_container');
- $.tmpl(window.templates.tagDetailsSelector,
tagstats).appendTo('#test_details_container');
+ $.tmpl('detailsHeaderTemplate',
args).appendTo('#test_details_container');
+ $.tmpl('tagDetailsSelectorTemplate',
tagstats).appendTo('#test_details_container');
}
function renderSuiteSelector(linkTarget) {
emptyDetails();
var args = {linkTarget: linkTarget, suites_tab_status: 'tab_selected'};
var suitestats = {suites: window.testdata.statistics().suite};
- $.tmpl(window.templates.detailsHeader,
args).appendTo('#test_details_container');
- $.tmpl(window.templates.suiteDetailsSelector,
suitestats).appendTo('#test_details_container');
+ $.tmpl('detailsHeaderTemplate',
args).appendTo('#test_details_container');
+ $.tmpl('suiteDetailsSelectorTemplate',
suitestats).appendTo('#test_details_container');
}
function emptyDetails(){
@@ -124,7 +123,7 @@
var stat = window.testdata.statistics().total[1];
var tests = getTotalTests(type)
stat.totalTime = calculateTotalTime(tests);
- $.tmpl(window.templates.tagOrTotalDetails,
stat).appendTo('#details_header');
+ $.tmpl('tagOrTotalDetailsTemplate', stat).appendTo('#details_header');
drawTestDetailsTable(tests);
}
@@ -133,19 +132,19 @@
if (tag) {
tag.totalTime = calculateTotalTime(tests);
}
- $.tmpl(window.templates.tagOrTotalDetails,
tag).appendTo('#details_header');
+ $.tmpl('tagOrTotalDetailsTemplate', tag).appendTo('#details_header');
drawTestDetailsTable(tests);
}
function renderDetailsBySuite(name) {
var suite = testdata.suite().findSuiteByName(name);
var opts = {logURL: window.settings.logURL};
- $.tmpl(window.templates.suiteDetails, suite,
opts).appendTo('#details_header');
+ $.tmpl('suiteDetailsTemplate', suite,
opts).appendTo('#details_header');
drawTestDetailsTable(suite.allTests());
}
function drawTestDetailsTable(tests) {
-
$.tmpl(window.templates.testDetailsTable).appendTo('#test_details_container');
+ $.tmpl('testDetailsTableTemplate').appendTo('#test_details_container');
window.tasks = tests;
iterateDetails();
}
@@ -241,7 +240,7 @@
return;
}
var elements = pop_upto(window.tasks, 50);
- $.tmpl(window.templates.testDetailsRow, elements, {logURL:
window.settings.logURL}).appendTo('#tests_detail_table');
+ $.tmpl('testDetailsTableRowTemplate', elements, {logURL:
window.settings.logURL}).appendTo('#tests_detail_table');
if(window.tasks.length > 0)
setTimeout("iterateDetails()", 0);
}
@@ -252,26 +251,9 @@
result.push(list.shift());
return result;
}
-
-function initTemplates() {
- return {
- summaryTable: $('#summary_table').template(),
- totalStatRow: $('#total_statistics_row').template(),
- tagStatRow: $('#tag_statistics_row').template(),
- suiteStatRow: $('#suite_statistics_row').template(),
- detailsHeader: $('#details_header').template(),
- totalDetailsSelector: $('#total_details_selector').template(),
- tagDetailsSelector: $('#tag_details_selector').template(),
- suiteDetailsSelector: $('#suite_details_selector').template(),
- tagOrTotalDetails: $('#tag_or_total_details').template(),
- suiteDetails: $('#suite_details').template(),
- testDetailsTable: $('#test_details_table').template(),
- testDetailsRow: $('#report_test_details_row').template()
- };
-}
</script>
-<script type="text/html" id="summary_table">
+<script type="text/x-jquery-tmpl" id="summaryTableTemplate">
<h2>Summary Information</h2>
<table class="details">
<tr>
@@ -289,12 +271,12 @@
<tr><th>${$index}:</th><td>{{html $value}}</td></tr>
{{/each}}
{{if times.startTime() != 'N/A'}}
- <tr><th>Start Time:</th><td>${times.startTime}</td></tr>
+ <tr><th>Start Time:</th><td>${times.startTime}</td></tr>
{{/if}}
{{if times.endTime() != 'N/A'}}
- <tr><th>End Time:</th><td>${times.endTime}</td></tr>
+ <tr><th>End Time:</th><td>${times.endTime}</td></tr>
{{/if}}
- <tr><th>Elapsed Time:</th><td>${times.elapsedTime}</td></tr>
+ <tr><th>Elapsed Time:</th><td>${times.elapsedTime}</td></tr>
{{if $item.logURL}}
<tr>
<th>Log File:</th>
@@ -304,7 +286,7 @@
</table>
</script>
-<script type="text/html" id="total_statistics_row">
+<script type="text/x-jquery-tmpl" id="totalStatisticsRowTemplate">
<tr>
<td class="col_stat_name">
<div class="stat_name">
@@ -315,7 +297,7 @@
</tr>
</script>
-<script type="text/html" id="tag_statistics_row">
+<script type="text/x-jquery-tmpl" id="tagStatisticsRowTemplate">
<tr>
<td class="col_stat_name">
<div class="stat_name">
@@ -332,7 +314,7 @@
</tr>
</script>
-<script type="text/html" id="suite_statistics_row">
+<script type="text/x-jquery-tmpl" id="suiteStatisticsRowTemplate">
<tr>
<td class="col_stat_name">
<div class="stat_name">
@@ -344,7 +326,7 @@
</script>
-<script type="text/html" id="details_header">
+<script type="text/x-jquery-tmpl" id="detailsHeaderTemplate">
<h2 id="${linkTarget}">Test Details</h2>
<ul id="detail_tabs">
<li class="${totals_tab_status}"><a href="#totals"
onclick="showTotalsTab();">Totals</a></li>
@@ -353,7 +335,7 @@
</ul>
</script>
-<script type="text/html" id="total_details_selector">
+<script type="text/x-jquery-tmpl" id="totalDetailsSelectorTemplate">
<table class="details" id="details_header">
<tr id="selector">
<th>Type:</th>
@@ -367,7 +349,7 @@
</table>
</script>
-<script type="text/html" id="tag_details_selector">
+<script type="text/x-jquery-tmpl" id="tagDetailsSelectorTemplate">
<table class="details" id="details_header">
<tr id="selector">
<th>Name:</th>
@@ -383,7 +365,7 @@
</table>
</script>
-<script type="text/html" id="suite_details_selector">
+<script type="text/x-jquery-tmpl" id="suiteDetailsSelectorTemplate">
<table class="details" id="details_header">
<tr id="selector">
<th>Name:</th>
@@ -399,7 +381,7 @@
</table>
</script>
-<script type="text/html" id="tag_or_total_details">
+<script type="text/x-jquery-tmpl" id="tagOrTotalDetailsTemplate">
{{if doc}}
<tr>
<th>Documentation:</th>
@@ -428,7 +410,7 @@
</tr>
</script>
-<script type="text/html" id="suite_details">
+<script type="text/x-jquery-tmpl" id="suiteDetailsTemplate">
{{if $item.logURL}}
<tr>
<th>Log Link:</th>
@@ -446,7 +428,7 @@
{{/each}}
<tr>
<th>Status:</th>
- <td>{{tmpl($data) '#stats_message_partial_template'}}</td>
+ <td>{{tmpl($data) 'suiteStatusMessageTemplate'}}</td>
</tr>
{{if message}}
<tr>
@@ -464,11 +446,7 @@
</tr>
</script>
-<script type="text/html" id="stats_message_partial_template">
-${critical} critical test, ${criticalPassed} passed, <span
class="${criticalFailureClass}">${criticalFailed} failed</span><br
/>${total} test total, ${totalPassed} passed, <span
class="${totalFailureClass}">${totalFailed} failed</span>
-</script>
-
-<script type="text/html" id="test_details_table">
+<script type="text/x-jquery-tmpl" id="testDetailsTableTemplate">
<table id="tests_detail_table">
<tr>
<th class="col_name">Name</th>
@@ -482,7 +460,7 @@
</table>
</script>
-<script type="text/html" id="report_test_details_row">
+<script type="text/x-jquery-tmpl" id="testDetailsTableRowTemplate">
<tr class="test_row">
{{if $item.logURL}}
<td class="col_name"><a href="${$item.logURL}#test_${fullname}"
id="test_${fullname}" title="${fullname}"><span
class="parent_name">${parentName}</span>${name}</a></td>
=======================================
--- /src/robot/webcontent/view.js Fri Jun 17 06:31:25 2011
+++ /src/robot/webcontent/view.js Mon Jun 20 01:13:00 2011
@@ -2,9 +2,25 @@
$('#javascript_disabled').remove();
}
-function addHeader(suiteName, type) {
+function initLayout(suiteName, type) {
+ parseTemplates();
+ setTitle(suiteName, type);
+ addHeader();
+ addReportOrLogLink(type);
+}
+
+function parseTemplates() {
+ $('script[type="text/x-jquery-tmpl"]').map(function (idx, elem) {
+ $.template(elem.id, elem.text);
+ });
+}
+
+function setTitle(suiteName, type) {
var givenTitle = window.settings.title;
document.title = givenTitle ? givenTitle : suiteName + " Test " + type;
+}
+
+function addHeader() {
var generatedAgoMillis = window.testdata.generated().getTime();
var template =
'<div id="generated">' +
@@ -18,7 +34,6 @@
generated: window.output.generatedTimestamp,
generatedAgo: util.createGeneratedAgoString(generatedAgoMillis)
}).appendTo($('#header_div'));
- addReportOrLogLink(type);
}
function addReportOrLogLink(myType) {
@@ -65,14 +80,14 @@
if (tableName == 'tag' && stats.length == 0)
renderStatTable(tableName, 'no_tags_row');
else {
- var templateName = tableName + 'StatRow';
- renderStatTable(tableName, window.templates[templateName], stats);
+ var templateName = tableName + 'StatisticsRowTemplate';
+ renderStatTable(tableName, templateName, stats);
}
}
-function renderStatTable(tableName, template, stats) {
+function renderStatTable(tableName, templateName, stats) {
var tableId = "#" + tableName + "_stats";
- $.tmpl(template, stats).appendTo($(tableId));
+ $.tmpl(templateName , stats).appendTo($(tableId));
}
$.template("stat_columns",
@@ -98,3 +113,12 @@
'</td>' +
'</tr>'
);
+
+$.template('suiteStatusMessageTemplate',
+ '${critical} critical test, ' +
+ '${criticalPassed} passed, ' +
+ '<span class="${criticalFailureClass}">${criticalFailed}
failed</span><br />' +
+ '${total} test total, ' +
+ '${totalPassed} passed, ' +
+ '<span class="${totalFailureClass}">${totalFailed} failed</span>'
+);