forked from andyedinborough/RazorJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
49 lines (45 loc) · 1006 Bytes
/
Copy pathutil.js
File metadata and controls
49 lines (45 loc) · 1006 Bytes
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
45
46
47
48
49
function extend(a) {
each(arguments, function (b, i) {
if (i === 0) return;
if (b)
each(objectKeys(b), function (key) {
a[key] = b[key];
});
});
return a;
}
function doubleEncode(txt) {
return txt
.split('\\').join('\\\\')
.split('\r').join('\\r')
.split('\n').join('\\n')
.split('"').join('\\"');
}
function htmlString(value) {
return {
toString: function () {
return value;
},
isHtmlString: true
};
}
function encode(value){
if (value === null || value === undefined) value = '';
if (value.isHtmlString) return value;
if (typeof value !== 'string') value += '';
value = value
.split('&').join('&')
.split('<').join('<')
.split('>').join('>')
.split('"').join('"');
return htmlString(value);
}
var HtmlHelper = function(){ };
extend(HtmlHelper.prototype, {
encode: encode,
attributeEncode: encode,
raw: htmlString,
renderPartial: function (view, model, page) {
return htmlString(Razor.view(view)(model, page || this.page));
}
});