Login   Register  
Icontem

File: tests/utils.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Aliaksandr Astashenkau  >  Templ  >  tests/utils.js  >  Download  
File: tests/utils.js
Role: Auxiliary script
Content type: text/plain
Description: JS utils
Class: Templ
Processes templates embedded in the pages
Author: By
Last change:
Date: 2011-07-01 05:05
Size: 672 bytes
 

Contents

Class file image Download
var doubleEncode = false;

var _ = {
	encode: function(str) {
		return str.replace(/&/g,"&").
		replace(/</g,"&lt;").
		replace(/>/g,"&gt;");
	},

	parseData: function(str) {
		return eval('(' + str + ')');
	},

	el: function(str) {
		return document.getElementById(str);
	}
};

window.onload = function() {
	var template = _.el('tpl_example').innerHTML;
	var data = _.parseData(_.el('data').innerHTML);
	var output = Templ(template, data);

	_.el('template').innerHTML = !doubleEncode ? _.encode(template.replace(/^\n/, '')) : template.replace(/^\n/, '');
	_.el('output').innerHTML = !doubleEncode ? _.encode(output.replace(/^\n/, '')) : output.replace(/^\n/, '');
};