mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
feature(util) rm ownRender
This commit is contained in:
parent
f0eb586e38
commit
a81d2e3c42
1 changed files with 8 additions and 32 deletions
40
lib/util.js
40
lib/util.js
|
|
@ -363,52 +363,28 @@
|
|||
return regExp;
|
||||
};
|
||||
|
||||
/**
|
||||
* function render template with view
|
||||
* @templ
|
||||
* @view
|
||||
*/
|
||||
this.render = function(templ, view) {
|
||||
var ret,
|
||||
NOT_ESCAPE = true,
|
||||
SPACES = '\\s*',
|
||||
symbols = ['{{' + SPACES, SPACES + '}}'];
|
||||
|
||||
ret = Util.ownRender(templ, view, symbols, NOT_ESCAPE);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* function render template with view and own symbols
|
||||
*
|
||||
* @param templ
|
||||
* @param view
|
||||
* @param symbols
|
||||
* @param notEscape
|
||||
*/
|
||||
this.ownRender = function(templ, view, symbols, notEscape) {
|
||||
var str, expr,
|
||||
ret = templ,
|
||||
firstChar,
|
||||
secondChar;
|
||||
|
||||
firstChar = symbols[0];
|
||||
secondChar = symbols[1] || firstChar;
|
||||
this.render = function(templ, view) {
|
||||
var str, regExp,
|
||||
result = templ;
|
||||
|
||||
Object
|
||||
.keys(view)
|
||||
.forEach(function(param) {
|
||||
str = view[param];
|
||||
str = Util.exec(str) || str;
|
||||
expr = firstChar + param + secondChar;
|
||||
ret = Util.replaceStr(ret, expr, str, notEscape);
|
||||
regExp = RegExp('{{\\s*' + param + '\\s*}}', 'g');
|
||||
result = result.replace(regExp, str);
|
||||
});
|
||||
|
||||
expr = firstChar + '.*' + secondChar;
|
||||
ret = Util.replaceStr(ret, expr, '', notEscape);
|
||||
if (result.indexOf('{{'))
|
||||
result.replace(/{{\s*.*\s*}}/, '');
|
||||
|
||||
return ret;
|
||||
return result;
|
||||
};
|
||||
|
||||
this.type = new TypeProto();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue