From ced746f813885bfd27c8548bec5457e80dc4677c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 5 Oct 2012 18:38:21 -0500 Subject: since functions and helpers are different, drop this special case --- lib/Text/Handlebars.pm | 12 ++++++++++-- lib/Text/Xslate/Syntax/Handlebars.pm | 7 ++++--- 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; } -- cgit v1.2.3