includes/clientside/static/template-compiler.js
changeset 1269 35986c6b2150
parent 1227 bdac73ed481e
child 1280 871f17a0d27d
equal deleted inserted replaced
1268:57f3857a8161 1269:35986c6b2150
     6 	this.tpl_code    = text;
     6 	this.tpl_code    = text;
     7 	this.tpl_strings = new Object();
     7 	this.tpl_strings = new Object();
     8 	this.tpl_bool    = new Object();
     8 	this.tpl_bool    = new Object();
     9 	this.assign_vars = __tpAssignVars;
     9 	this.assign_vars = __tpAssignVars;
    10 	this.assign_bool = __tpAssignBool;
    10 	this.assign_bool = __tpAssignBool;
       
    11 	this.fetch_hook  = __tpFetchHook;
    11 	this.run         = __tpRun;
    12 	this.run         = __tpRun;
    12 }
    13 }
    13 
    14 
    14 window.__tpAssignVars = function(vars)
    15 window.__tpAssignVars = function(vars)
    15 {
    16 {
    57 	code = code.replace(/\{lang:([a-z0-9_]+)\}/g, "' + $lang.get('$1') + '");
    58 	code = code.replace(/\{lang:([a-z0-9_]+)\}/g, "' + $lang.get('$1') + '");
    58 	code = code.replace(/\<!-- IFSET ([A-z0-9_-]+) --\>([\s\S]*?)\<!-- BEGINELSE \1 --\>([\s\S]*?)\<!-- END \1 --\>/ig, "' + ( ( typeof(this.tpl_strings['$1']) == 'string' ) ? '$2' : '$3' ) + '");
    59 	code = code.replace(/\<!-- IFSET ([A-z0-9_-]+) --\>([\s\S]*?)\<!-- BEGINELSE \1 --\>([\s\S]*?)\<!-- END \1 --\>/ig, "' + ( ( typeof(this.tpl_strings['$1']) == 'string' ) ? '$2' : '$3' ) + '");
    59 	code = code.replace(/\<!-- IFSET ([A-z0-9_-]+) --\>([\s\S]*?)\<!-- END \1 --\>/ig, "' + ( ( typeof(this.tpl_strings['$1']) == 'string' ) ? '$2' : '' ) + '");
    60 	code = code.replace(/\<!-- IFSET ([A-z0-9_-]+) --\>([\s\S]*?)\<!-- END \1 --\>/ig, "' + ( ( typeof(this.tpl_strings['$1']) == 'string' ) ? '$2' : '' ) + '");
    60 	code = code.replace(/\<!-- BEGIN ([A-z0-9_-]+) --\>([\s\S]*?)\<!-- BEGINELSE \1 --\>([\s\S]*?)\<!-- END \1 --\>/ig, "' + ( ( this.tpl_bool['$1'] == true ) ? '$2' : '$3' ) + '");
    61 	code = code.replace(/\<!-- BEGIN ([A-z0-9_-]+) --\>([\s\S]*?)\<!-- BEGINELSE \1 --\>([\s\S]*?)\<!-- END \1 --\>/ig, "' + ( ( this.tpl_bool['$1'] == true ) ? '$2' : '$3' ) + '");
    61 	code = code.replace(/\<!-- BEGIN ([A-z0-9_-]+) --\>([\s\S]*?)\<!-- END \1 --\>/ig, "' + ( ( this.tpl_bool['$1'] == true ) ? '$2' : '' ) + '");
    62 	code = code.replace(/\<!-- BEGIN ([A-z0-9_-]+) --\>([\s\S]*?)\<!-- END \1 --\>/ig, "' + ( ( this.tpl_bool['$1'] == true ) ? '$2' : '' ) + '");
       
    63 	code = code.replace(/\<!-- HOOK ([A-z0-9_-]+) --\>/ig, "' + this.fetch_hook('$1') + '");
    62 	return code;
    64 	return code;
    63 }
    65 }
    64 
    66 
    65 window.__tpExtractVars = function(code)
    67 window.__tpExtractVars = function(code)
    66 {
    68 {
    77 	code = '( { ' + code + ' "________null________" : false } )';
    79 	code = '( { ' + code + ' "________null________" : false } )';
    78 	vars = eval(code);
    80 	vars = eval(code);
    79 	return vars;
    81 	return vars;
    80 }
    82 }
    81 
    83 
       
    84 window.__tpFetchHook = function(hookid)
       
    85 {
       
    86 	var _ob = '';
       
    87 	window.Template = this;
       
    88 	window.Echo = function(h)
       
    89 	{
       
    90 		_ob += h;
       
    91 	}
       
    92 	eval(setHook('thook_' + hookid));
       
    93 	window.Echo = window.Template = false;
       
    94 	return _ob;
       
    95 }
       
    96