summaryrefslogtreecommitdiffstats
path: root/lib/Text/Handlebars.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-04 16:06:38 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-04 16:06:38 -0500
commitc4fd3dc97042a13cf365f06dd84bb6b02a1efdfb (patch)
treee8ba2d8de7a46b673acca3e0819e95b317d2b65e /lib/Text/Handlebars.pm
parent1f055d6a66f97020c2b8aac0837bb128d4c696f5 (diff)
downloadtext-handlebars-c4fd3dc97042a13cf365f06dd84bb6b02a1efdfb.tar.gz
text-handlebars-c4fd3dc97042a13cf365f06dd84bb6b02a1efdfb.zip
implement helpers
Diffstat (limited to 'lib/Text/Handlebars.pm')
-rw-r--r--lib/Text/Handlebars.pm16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm
index 7c975b9..fd3fc28 100644
--- a/lib/Text/Handlebars.pm
+++ b/lib/Text/Handlebars.pm
@@ -63,7 +63,10 @@ sub options {
my $class = shift;
my $options = $class->SUPER::options(@_);
+
$options->{compiler} = 'Text::Handlebars::Compiler';
+ $options->{helpers} = {};
+
return $options;
}
@@ -86,6 +89,19 @@ sub _register_builtin_methods {
return 1 if try { $weakself->find_file($filename); 1 };
return 0;
};
+
+ for my $helper (keys %{ $self->{helpers} }) {
+ my $code = $self->{helpers}{$helper};
+ $funcs->{$helper} = sub {
+ my ($raw_text, @args) = @_;
+ my $recurse = sub {
+ my ($vars) = @_;
+ return $weakself->render_string($raw_text, $vars);
+ };
+
+ return $code->(@args, { fn => $recurse });
+ }
+ }
}
1;