summaryrefslogtreecommitdiffstats
path: root/lib/Text/Handlebars.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-05 10:39:27 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-05 10:39:27 -0500
commit1a010552eeb2a965c92fab007c45f8e59ac60b02 (patch)
tree1c384604ddc6a5101302edce2ced26e66bafc8d4 /lib/Text/Handlebars.pm
parentd94b450ad15be78a1ead0b614b853e659370119b (diff)
downloadtext-handlebars-1a010552eeb2a965c92fab007c45f8e59ac60b02.tar.gz
text-handlebars-1a010552eeb2a965c92fab007c45f8e59ac60b02.zip
implement else blocks
Diffstat (limited to 'lib/Text/Handlebars.pm')
-rw-r--r--lib/Text/Handlebars.pm15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm
index c1afc32..cf2a8f1 100644
--- a/lib/Text/Handlebars.pm
+++ b/lib/Text/Handlebars.pm
@@ -85,14 +85,14 @@ sub options {
if ($conditional) {
return $options->{fn}->($context);
}
- return '';
+ return $options->{inverse} ? $options->{inverse}->($context) : '';
},
unless => sub {
my ($context, $conditional, $options) = @_;
unless ($conditional) {
return $options->{fn}->($context);
}
- return '';
+ return $options->{inverse} ? $options->{inverse}->($context) : '';
},
},
@@ -119,14 +119,19 @@ sub _register_builtin_methods {
return 0;
};
$funcs->{'(run_block_helper)'} = sub {
- my ($code, $raw_text, $vars, @args) = @_;
+ my ($code, $raw_text, $else_raw_text, $vars, @args) = @_;
- my $recurse = sub {
+ my $options = {};
+ $options->{fn} = sub {
my ($new_vars) = @_;
return $weakself->render_string($raw_text, $new_vars);
};
+ $options->{inverse} = sub {
+ my ($new_vars) = @_;
+ return $weakself->render_string($else_raw_text, $new_vars);
+ };
- return $code->($vars, @args, { fn => $recurse });
+ return $code->($vars, @args, $options);
};
}