<commit_before>define(['./smpl.string', './smpl.utils'], function(smpl) {
	smpl.tpl = {};
	
	smpl.tpl.Template = function (name, blocks) {
		this.name = name;
		this.blocks = {
			toInit: blocks
		}
	};

	smpl.tpl.Template.prototype.init = function(blocks, partial) {
		delete this.blocks.toInit;
		if (typeof blocks === 'string') {
			smpl.tpl.utils.make(this, blocks);
			blocks = this.blocks;
		}
		if (!partial) {
			for (var blkId in blocks) {
				if (typeof blocks[blkId]  === 'string') {
					this.blocks[blkId] = new Function(blocks[blkId]);
				}
			}
		}
	};

	smpl.tpl.Template.prototype.set = function(key, value) {
		this.data[key] = value;
	};

	smpl.tpl.Template.prototype.retrieve = function(blkId) {
		blkId = blkId || smpl.tpl.utils.MAIN;
		blk = this.parsedBlocks[blkId];
		if (blk) {
			delete this.parsedBlocks[blkId]
			return blk.join('');
		} else {
			return '';
		}
	};

	smpl.tpl.Template.prototype.reset = function(blkId) {
		if (!this.blocks[smpl.tpl.utils.MAIN]) {
			this.init(this.blocks.toInit);
		}
		this.data = {};
		this.parsedBlocks = {};
		return this;
	};

	smpl.tpl.Template.prototype.parseBlock = function(blkId) {
		var str = this.blocks[blkId].call(this);
		this.parsedBlocks[blkId] = this.parsedBlocks[blkId] || [];
		this.parsedBlocks[blkId].push(str);
	};

	smpl.tpl.Template.prototype.parse = function() {
		this.reset();
		this.onParse.apply(this, arguments);
		this.parseBlock(smpl.tpl.utils.MAIN);
		return this;
	};

	smpl.tpl.Template.prototype.load = function(container, display) {
		if (typeof container === 'string') {
			container = document.getElementById(container);
		}
		if (container) {
			display = display || container.style.display;
			container.style.display = 'none';
			container.innerHTML = this.retrieve();
			this.onLoad && this.onLoad();
			container.style.display = display;
		}
	};

	smpl.tpl.Template.prototype.onParse = function(pfx, obj) {
		this.set(pfx, obj);
	};


	smpl.tpl.utils = {};
	smpl.tpl.utils.libraries = {};
	smpl.tpl.utils.registerLibrary = function(libName, library) {
		smpl.tpl.utils.libraries[libName] = library;
	};
	smpl.tpl.utils.retrieveWidget = function(libName) {
		var lib = smpl.tpl.utils.libraries[libName];
		if (lib) {
			lib.retrieveWidget.apply(lib, arguments.slice(1));
		}
	};

	smpl.tpl.utils.MAIN = '_main';
	smpl.tpl.utils.make = function (tpl, txt) {
		var l = txt.length,
			pos = 0,
			startPos = 0,
			stack = [],
			newpos;
		tpl.blocks = {};
		this.processToken(tpl, stack, {type: 'BEGIN', txt: this.MAIN});
		while (pos < l) {
			var chr = txt.charAt(pos++);
			if (chr === '\\' && '\\{'.indexOf(txt.charAt(pos)) !== -1) { // skip escaped \ and {
				++pos;
			} else if (chr === '<' && txt.charAt(pos) === '!' && txt.charAt(pos + 1) === '-' && txt.charAt(pos + 2) === '-') { // <!-- (BEGIN|END): [-\w]+ --> block
				newpos = txt.indexOf('-->', pos + 3);
				if (newpos !== -1) {
					var m = /^\s+(BEGIN|END):\s+([-\w]+)\s+$/.exec(txt.substring(pos + 3, newpos));<commit_msg>[Templates] allow to register instances in global scope for use like onclick="{$me}".<commit_after>define(['./smpl.string', './smpl.utils'], function(smpl) {
	smpl.tpl = {};
	
	smpl.tpl.Template = function (name, blocks) {
		this.name = name;
		this.blocks = {
			toInit: blocks
		}
	};

	smpl.tpl.Template.prototype.init = function(blocks, partial) {
		delete this.blocks.toInit;
		if (typeof blocks === 'string') {
			smpl.tpl.utils.make(this, blocks);
			blocks = this.blocks;
		}
		if (!partial) {
			for (var blkId in blocks) {
				if (typeof blocks[blkId]  === 'string') {
					this.blocks[blkId] = new Function(blocks[blkId]);
				}
			}
		}
		if (smpl.tpl.globalObj) {
			this.__globalKey = '_' + smpl.utils.uniq();
			smpl.tpl.globalObj[this.__globalKey] = this;
			this.__globalKey = smpl.tpl.globalKey + '.' + this.__globalKey;
		}
	};

	smpl.tpl.Template.prototype.set = function(key, value) {
		this.data[key] = value;
	};

	smpl.tpl.Template.prototype.retrieve = function(blkId) {
		blkId = blkId || smpl.tpl.utils.MAIN;
		blk = this.parsedBlocks[blkId];
		if (blk) {
			delete this.parsedBlocks[blkId]
			return blk.join('');
		} else {
			return '';
		}
	};

	smpl.tpl.Template.prototype.reset = function(blkId) {
		if (!this.blocks[smpl.tpl.utils.MAIN]) {
			this.init(this.blocks.toInit);
		}
		this.data = {
			me: this.__globalKey
		};
		this.parsedBlocks = {};
		return this;
	};

	smpl.tpl.Template.prototype.parseBlock = function(blkId) {
		var str = this.blocks[blkId].call(this);
		this.parsedBlocks[blkId] = this.parsedBlocks[blkId] || [];
		this.parsedBlocks[blkId].push(str);
	};

	smpl.tpl.Template.prototype.parse = function() {
		this.reset();
		this.onParse.apply(this, arguments);
		this.parseBlock(smpl.tpl.utils.MAIN);
		return this;
	};

	smpl.tpl.Template.prototype.load = function(container, display) {
		if (typeof container === 'string') {
			container = document.getElementById(container);
		}
		if (container) {
			display = display || container.style.display;
			container.style.display = 'none';
			container.innerHTML = this.retrieve();
			this.onLoad && this.onLoad(container, display);
			container.style.display = display;
		}
	};

	smpl.tpl.Template.prototype.onParse = function(pfx, obj) {
		this.set(pfx, obj);
	};

	smpl.tpl.globalRepo = {};
	smpl.tpl.enableGlobal = function(key, obj) {
		if (key) {
			smpl.tpl.globalKey = key;
			smpl.tpl.globalObj = obj;
		} else {
			if (typeof window === 'object' && window.smpl === smpl) {
				smpl.tpl.globalKey = 'window.tpl.globalRepo';
				smpl.tpl.globalObj = window.tpl.globalRepo;
			}
		}
		return !!smpl.tpl.globalKey;
	};
	
	smpl.tpl.utils = {};
	smpl.tpl.utils.libraries = {};
	smpl.tpl.utils.registerLibrary = function(libName, library) {
		smpl.tpl.utils.libraries[libName] = library;
	};
	smpl.tpl.utils.retrieveWidget = function(libName) {
		var lib = smpl.tpl.utils.libraries[libName];
		if (lib) {
			lib.retrieveWidget.apply(lib, arguments.slice(1));
		}
	};

	smpl.tpl.utils.MAIN = '_main';
	smpl.tpl.utils.make = function (tpl, txt) {
		var l = txt.length,
			pos = 0,
			startPos = 0,
			stack = [],
			newpos;
		tpl.blocks = {};
		this.processToken(tpl, stack, {type: 'BEGIN', txt: this.MAIN});
		while (pos < l) {
			var chr = txt.charAt(pos++);
			if (chr === '\\' && '\\{'.indexOf(txt.charAt(pos)) !== -1) { // skip escaped \ and {
				++pos;
			} else if (chr === '<' && txt.charAt(pos) === '!' && txt.charAt(pos + 1) === '-' && txt.charAt(pos + 2) === '-') { // <!-- (BEGIN|END): [-\w]+ --> block
				newpos = txt.indexOf('-->', pos + 3);
				if (newpos !== -1) {
					var m = /^\s+(BEGIN|END):\s+([-\w]+)\s+$/.exec(txt.substring(pos + 3, newpos));
{'fraction_non_alphanumeric': 0.19666966696669666, 'fraction_numerical': 0.0027002700270027003, 'mean_word_length': 3.2847043701799485, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6294758', 'n_tokens_mistral': 2754, 'n_tokens_neox': 2537, 'n_words': 419}