summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler.js
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-12-19 00:06:55 -0800
committerwycats <wycats@gmail.com>2010-12-19 00:06:55 -0800
commit8f502ffbe76b49ebf4d11bd19b3f094e2c483d6a (patch)
tree0ec464a824b40c3f1999bac7dc48d0a57e21f14c /lib/handlebars/compiler.js
parentf4ae0c27fecddba3b627a3a7d4a63b386f756120 (diff)
downloadhandlebars.js-8f502ffbe76b49ebf4d11bd19b3f094e2c483d6a.zip
handlebars.js-8f502ffbe76b49ebf4d11bd19b3f094e2c483d6a.tar.gz
handlebars.js-8f502ffbe76b49ebf4d11bd19b3f094e2c483d6a.tar.bz2
Add #each and #if built-in helpers for more readable iteration and conditionals
Diffstat (limited to 'lib/handlebars/compiler.js')
-rw-r--r--lib/handlebars/compiler.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/handlebars/compiler.js b/lib/handlebars/compiler.js
index 96ae36a..2ffd829 100644
--- a/lib/handlebars/compiler.js
+++ b/lib/handlebars/compiler.js
@@ -77,6 +77,28 @@ Handlebars.registerHelper('blockHelperMissing', function(context, fn, inverse) {
}, function(context, fn) {
return fn(context)
});
+
+Handlebars.registerHelper('each', function(context, fn, inverse) {
+ var ret = "";
+
+ if(context.length > 0) {
+ for(var i=0, j=context.length; i<j; i++) {
+ ret = ret + fn(context[i]);
+ }
+ } else {
+ ret = inverse(this);
+ }
+ return ret;
+});
+
+Handlebars.registerHelper('if', function(context, fn, inverse) {
+ if(context === false || context == null) {
+ return inverse(this);
+ } else {
+ return fn(this);
+ }
+});
+
// END(BROWSER)
exports.Handlebars = Handlebars;