mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 01:47:35 +00:00
refactor(util) render, ownRender
This commit is contained in:
parent
927b14c080
commit
3013386eef
1 changed files with 25 additions and 25 deletions
50
lib/util.js
50
lib/util.js
|
|
@ -565,42 +565,42 @@
|
|||
|
||||
/**
|
||||
* function render template with view
|
||||
* @pTempl
|
||||
* @pView
|
||||
* @templ
|
||||
* @view
|
||||
*/
|
||||
this.render = function(pTempl, pView) {
|
||||
var lRet = Util.ownRender(pTempl, pView);
|
||||
this.render = function(templ, view) {
|
||||
var ret,
|
||||
SPACES = '\\s*',
|
||||
symbols = ['{{' + SPACES, SPACES + '}}'];
|
||||
|
||||
ret = Util.ownRender(templ, view, symbols);
|
||||
|
||||
return lRet;
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* function render template with view and own symbols
|
||||
* @pTempl
|
||||
* @pView
|
||||
* @pSymbols
|
||||
* @templ
|
||||
* @view
|
||||
* @symbols
|
||||
*/
|
||||
this.ownRender = function(pTempl, pView, pSymbols) {
|
||||
var SPACES = '\\s*';
|
||||
|
||||
if (!pSymbols)
|
||||
pSymbols = ['{{' + SPACES, SPACES + '}}'];
|
||||
|
||||
var lRet = pTempl,
|
||||
lFirstChar,
|
||||
lSecondChar;
|
||||
this.ownRender = function(templ, view, symbols) {
|
||||
var str, param, expr,
|
||||
ret = templ,
|
||||
firstChar,
|
||||
secondChar;
|
||||
|
||||
lFirstChar = pSymbols[0];
|
||||
lSecondChar = pSymbols[1] || lFirstChar;
|
||||
firstChar = symbols[0];
|
||||
secondChar = symbols[1] || firstChar;
|
||||
|
||||
for(var lVar in pView) {
|
||||
var lStr = pView[lVar];
|
||||
lStr = Util.exec(lStr) || lStr;
|
||||
|
||||
lRet = Util.replaceStr(lRet, lFirstChar + lVar + lSecondChar, lStr, true);
|
||||
for (param in view) {
|
||||
str = view[param];
|
||||
str = Util.exec(str) || str;
|
||||
expr = firstChar + param + secondChar;
|
||||
ret = Util.replaceStr(ret, expr, str, true);
|
||||
}
|
||||
|
||||
return lRet;
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue