forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
44 lines (37 loc) · 1.02 KB
/
helpers.js
File metadata and controls
44 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*global Handlebars */
var renderTemplate = (function (handlebars, undefined) {
'use strict';
var compilationOptions = {
"knownHelpers": {
"link": true
},
"knownHelpersOnly": true
};
handlebars.registerHelper('link', function (text, url, newWindow) {
var escapedText = handlebars.Utils.escapeExpression(text),
escapedUrl = handlebars.Utils.escapeExpression(url)
;
return new handlebars.SafeString(
'<a href="' + escapedUrl + '"' + (newWindow ? ' target="_blank"' : '') + '>' + escapedText + '</a>'
);
});
/**
* Renders a Handlebars templates
*
* @param {String} sourceCode - Source code of Handlebars template
* @param {String} serializedData - A string containing JSON data
* @returns {String} HTML code
* @expose
*/
function renderTemplate(sourceCode, serializedData) {
var data,
template,
content
;
template = handlebars.compile(sourceCode, compilationOptions);
data = JSON.parse(serializedData);
content = template(data);
return content;
}
return renderTemplate;
}(Handlebars));