added easy template renderrer Util.render

This commit is contained in:
coderaiser 2013-01-17 10:50:21 -05:00
parent a8d3da2dc3
commit 258fb11669
3 changed files with 49 additions and 0 deletions

View file

@ -89,6 +89,8 @@ clicked on menu item.
* Added ability to read storage modules information from menu module.
* Added easy template renderrer system Util.render.
2012.12.12, Version 0.1.8

View file

@ -550,6 +550,7 @@ var CloudCommander, Util,
return lRet;
},
/**
* Функция создаёт елемент style и записывает туда стили
* @param pParams_o - структура параметров, заполняеться таким

View file

@ -135,6 +135,13 @@ Util = exports || {};
return pStr.replace(pSubStr,'');
};
/**
* function replase pFrom to pTo in pStr
* @pStr
* @pFrom
* @pTo
*/
Util.replaceStr = function(pStr, pFrom, pTo){
var lRet;
@ -144,6 +151,45 @@ Util = exports || {};
return lRet;
};
/**
* function render template with view
* @pTempl
* @pView
*/
Util.render = function(pTempl, pView){
var lRet = Util.ownRender(pTempl, pView, ['{', '}']);
return lRet;
};
/**
* function render template with view and own symbols
* @pTempl
* @pView
* @pSymbols
*/
Util.ownRender = function(pTempl, pView, pSymbols){
if(!pSymbols)
pSymbols = ['{', '}'];
var lRet = pTempl,
lFirstChar,
lSecondChar;
lFirstChar = pSymbols[0];
lSecondChar = pSymbols[1] || lFirstChar;
for(var lVar in pView){
var lStr = pView[lVar];
lStr = Util.exec(lStr) || lStr;
lRet = Util.replaceStr(lRet, lFirstChar + lVar + lSecondChar, lStr);
}
return lRet;
};
/**
* invoke a couple of functions in paralel
*