mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
added easy template renderrer Util.render
This commit is contained in:
parent
a8d3da2dc3
commit
258fb11669
3 changed files with 49 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -550,6 +550,7 @@ var CloudCommander, Util,
|
|||
return lRet;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Функция создаёт елемент style и записывает туда стили
|
||||
* @param pParams_o - структура параметров, заполняеться таким
|
||||
|
|
|
|||
46
lib/util.js
46
lib/util.js
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue