From 550e2f03ad0b60b3c9db3d68dbf014dcb740a2ff Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Tue, 17 Jan 2017 15:37:25 +0530 Subject: Initial Commit --- src/templateRenderer.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/templateRenderer.js (limited to 'src/templateRenderer.js') diff --git a/src/templateRenderer.js b/src/templateRenderer.js new file mode 100644 index 0000000..acd6289 --- /dev/null +++ b/src/templateRenderer.js @@ -0,0 +1,24 @@ +define(['nunjucks'], function(nunjucks) { + + var TEMPLATE_RENDERER = { + /* + * target: target HTML element can be an #id or .class. + * partialUrl : the url where specified partial exists. + * data : JSON object contains the data to be rendered. + * callback : The callback method that will be executed when + * template is successfull loaded + */ + render: function(target, partialUrl, data, callback) { + require(['text!' + partialUrl], function(template) { + var rendered = nunjucks.renderString(template, data); + $(target).html(rendered); + callback.call(); + }); + + + } + } + + return TEMPLATE_RENDERER; + +}); -- cgit v1.2.3