summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-05 18:38:21 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-05 18:38:21 -0500
commitced746f813885bfd27c8548bec5457e80dc4677c (patch)
tree9017cd92bb068617ef7c7759ebce9bf9e8611ead
parent6ff12b877afbda62ad2cb6d748487e7674e5c396 (diff)
downloadtext-handlebars-ced746f813885bfd27c8548bec5457e80dc4677c.tar.gz
text-handlebars-ced746f813885bfd27c8548bec5457e80dc4677c.zip
since functions and helpers are different, drop this special case
-rw-r--r--lib/Text/Handlebars.pm12
-rw-r--r--lib/Text/Xslate/Syntax/Handlebars.pm7
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm
index a040504..328359c 100644
--- a/lib/Text/Handlebars.pm
+++ b/lib/Text/Handlebars.pm
@@ -7,10 +7,9 @@ use base 'Text::Xslate';
use Scalar::Util 'weaken';
use Try::Tiny;
-sub default_functions {
+sub default_helpers {
my $class = shift;
return {
- %{ $class->SUPER::default_functions(@_) },
with => sub {
my ($context, $new_context, $options) = @_;
return $options->{fn}->($new_context);
@@ -31,6 +30,14 @@ sub default_functions {
? $options->{inverse}->($context)
: $options->{fn}->($context);
},
+ };
+}
+
+sub default_functions {
+ my $class = shift;
+ return {
+ %{ $class->SUPER::default_functions(@_) },
+ %{ $class->default_helpers },
'(is_array)' => sub {
my ($val) = @_;
return ref($val) && ref($val) eq 'ARRAY';
@@ -141,6 +148,7 @@ sub _compiler {
if (!ref($self->{compiler})) {
my $compiler = $self->SUPER::_compiler(@_);
$compiler->define_helper(keys %{ $self->{helpers} });
+ $compiler->define_helper(keys %{ $self->default_helpers });
return $compiler;
}
else {
diff --git a/lib/Text/Xslate/Syntax/Handlebars.pm b/lib/Text/Xslate/Syntax/Handlebars.pm
index a24fa00..ff1eefb 100644
--- a/lib/Text/Xslate/Syntax/Handlebars.pm
+++ b/lib/Text/Xslate/Syntax/Handlebars.pm
@@ -304,12 +304,13 @@ sub nud_name {
my $call = $self->call($name);
+ if ($name->is_helper) {
+ push @{ $call->second }, $self->vars;
+ }
+
if ($self->token->is_defined) {
push @{ $call->second }, $self->expression(0);
}
- elsif ($name->id ne 'mark_raw') {
- push @{ $call->second }, $self->vars;
- }
return $call;
}