summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Text/Handlebars.pm31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm
index 11de467..71b1ac1 100644
--- a/lib/Text/Handlebars.pm
+++ b/lib/Text/Handlebars.pm
@@ -64,6 +64,37 @@ sub options {
my $options = $class->SUPER::options(@_);
$options->{compiler} = 'Text::Handlebars::Compiler';
+ $options->{function} = {
+ ($options->{function} ? %{ $options->{function} } : ()),
+ with => sub {
+ my ($context, $new_context, $options) = @_;
+ return $options->{fn}->($new_context);
+ },
+ each => sub {
+ my ($context, $list, $options) = @_;
+
+ my $ret = '';
+ for my $new_context (@$list) {
+ $ret .= $options->{fn}->($new_context);
+ }
+
+ return $ret;
+ },
+ if => sub {
+ my ($context, $conditional, $options) = @_;
+ if ($conditional) {
+ return $options->{fn}->($context);
+ }
+ return '';
+ },
+ unless => sub {
+ my ($context, $conditional, $options) = @_;
+ unless ($conditional) {
+ return $options->{fn}->($context);
+ }
+ return '';
+ },
+ },
return $options;
}