From 258fb11669cb506afd86adfc634c2429cc3e2889 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 17 Jan 2013 10:50:21 -0500 Subject: [PATCH] added easy template renderrer Util.render --- ChangeLog | 2 ++ lib/client/dom.js | 1 + lib/util.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/ChangeLog b/ChangeLog index efc5195b..6b9bdce8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/lib/client/dom.js b/lib/client/dom.js index 765f5fe2..cdfaa25e 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -550,6 +550,7 @@ var CloudCommander, Util, return lRet; }, + /** * Функция создаёт елемент style и записывает туда стили * @param pParams_o - структура параметров, заполняеться таким diff --git a/lib/util.js b/lib/util.js index f28ab4b3..f7f9f60c 100644 --- a/lib/util.js +++ b/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 *