// Copyright 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
/**
* @pageoverview Some logic for the jstemplates test pages.
*
* @author Steffen Meschkat (mesch@google.com)
*/
function elem(id) {
return document.getElementById(id);
}
/**
* Are we actively profiling JstProcessor?
* @type boolean
*/
var profiling = false;
logHtml = function(html) {
elem('log').innerHTML += html + '
';
};
/**
* Initializer for interactive test: copies the value from the actual
* template HTML into a text area to make the HTML source visible.
*/
function jsinit() {
elem('template').value = elem('tc').innerHTML;
}
/**
* Interactive test.
*
* @param {boolean} reprocess If true, reprocesses the output of the
* previous invocation.
*/
function jstest(reprocess) {
var jstext = elem('js').value;
var input = jsEval(jstext);
var t;
if (reprocess) {
t = elem('out');
} else {
elem('tc').innerHTML = elem('template').value;
t = jstGetTemplate('t');
elem('out').innerHTML = '';
elem('out').appendChild(t);
}
if (profiling) Profiler.reset();
jstProcess(new JsEvalContext(input), t);
if (profiling) Profiler.dump();
elem('html').value = elem('out').innerHTML;
}
/**
* Performance test: jst initial processing.
*
* @param {Object} data Test data to apply the template to.
*/
function perf1(data) {
elem('out').innerHTML = '';
var t = jstGetTemplate('t1');
elem('out').appendChild(t);
if (profiling) Profiler.reset();
jstProcess(new JsEvalContext(data), t);
if (profiling) Profiler.dump();
}
/**
* Performance test: jst reprocessing or previous processing output.
*
* @param {Object} data Test data to apply the template to.
*/
function perf1a(data) {
if (profiling) Profiler.reset();
jstProcess(new JsEvalContext(data), elemOrDie('out'));
if (profiling) Profiler.dump();
}
/**
* Performance test: jst initial processing, with display:none during
* processing.
*
* @param {Object} data Test data to apply the template to.
*/
function perf1b(data) {
var o = elem('out');
o.innerHTML = '';
var t = jstGetTemplate('t1');
o.appendChild(t);
displayNone(o);
if (profiling) Profiler.reset();
jstProcess(new JsEvalContext(data), t);
if (profiling) Profiler.dump();
displayDefault(o);
}
/**
* Performance test: create output procedurally as string and assign
* to innerHTML.
*
* @param {Object} data Test data to apply the template to.
*/
function perf2(data) {
var t = [];
t.push("
item | label | address |
---|---|---|
" + i + " | " + e.label + " | " + e.address + " |