forked from danharper/Handlebars-Helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
144 lines (125 loc) · 4.21 KB
/
Copy pathhelpers.js
File metadata and controls
144 lines (125 loc) · 4.21 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* Handlebars Helpers - Dan Harper (http://github.com/danharper) */
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details. */
/**
* Following lines make Handlebars helper function to work with all
* three such as Direct web, RequireJS AMD and Node JS.
* This concepts derived from UMD.
* @courtesy - https://github.com/umdjs/umd/blob/master/returnExports.js
*/
(function (root, factory) {
if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(require('handlebars'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['handlebars'], factory);
} else {
// Browser globals (root is window)
root.returnExports = factory(root.Handlebars);
}
}(this, function (Handlebars) {
/**
* If Equals
* if_eq this compare=that
*/
Handlebars.registerHelper('if_eq', function(context, options) {
if (context == options.hash.compare)
return options.fn(this);
return options.inverse(this);
});
/**
* Unless Equals
* unless_eq this compare=that
*/
Handlebars.registerHelper('unless_eq', function(context, options) {
if (context == options.hash.compare)
return options.inverse(this);
return options.fn(this);
});
/**
* If Greater Than
* if_gt this compare=that
*/
Handlebars.registerHelper('if_gt', function(context, options) {
if (context > options.hash.compare)
return options.fn(this);
return options.inverse(this);
});
/**
* Unless Greater Than
* unless_gt this compare=that
*/
Handlebars.registerHelper('unless_gt', function(context, options) {
if (context > options.hash.compare)
return options.inverse(this);
return options.fn(this);
});
/**
* If Less Than
* if_lt this compare=that
*/
Handlebars.registerHelper('if_lt', function(context, options) {
if (context < options.hash.compare)
return options.fn(this);
return options.inverse(this);
});
/**
* Unless Less Than
* unless_lt this compare=that
*/
Handlebars.registerHelper('unless_lt', function(context, options) {
if (context < options.hash.compare)
return options.inverse(this);
return options.fn(this);
});
/**
* If Greater Than or Equal To
* if_gteq this compare=that
*/
Handlebars.registerHelper('if_gteq', function(context, options) {
if (context >= options.hash.compare)
return options.fn(this);
return options.inverse(this);
});
/**
* Unless Greater Than or Equal To
* unless_gteq this compare=that
*/
Handlebars.registerHelper('unless_gteq', function(context, options) {
if (context >= options.hash.compare)
return options.inverse(this);
return options.fn(this);
});
/**
* If Less Than or Equal To
* if_lteq this compare=that
*/
Handlebars.registerHelper('if_lteq', function(context, options) {
if (context <= options.hash.compare)
return options.fn(this);
return options.inverse(this);
});
/**
* Unless Less Than or Equal To
* unless_lteq this compare=that
*/
Handlebars.registerHelper('unless_lteq', function(context, options) {
if (context <= options.hash.compare)
return options.inverse(this);
return options.fn(this);
});
/**
* Convert new line (\n\r) to <br>
* from http://phpjs.org/functions/nl2br:480
*/
Handlebars.registerHelper('nl2br', function(text) {
var nl2br = (text + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + '<br>' + '$2');
return new Handlebars.SafeString(nl2br);
});
}));