diff options
-rw-r--r-- | lib/Text/Handlebars.pm | 22 | ||||
-rw-r--r-- | lib/Text/Xslate/Syntax/Handlebars.pm | 12 | ||||
-rw-r--r-- | t/helpers.t | 20 |
3 files changed, 27 insertions, 27 deletions
diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm index 471d2f0..11de467 100644 --- a/lib/Text/Handlebars.pm +++ b/lib/Text/Handlebars.pm @@ -64,7 +64,6 @@ sub options { my $options = $class->SUPER::options(@_); $options->{compiler} = 'Text::Handlebars::Compiler'; - $options->{helpers} = {}; return $options; } @@ -88,19 +87,16 @@ sub _register_builtin_methods { return 1 if try { $weakself->find_file($filename); 1 }; return 0; }; + $funcs->{'(run_block_helper)'} = sub { + my ($code, $raw_text, $vars, @args) = @_; - for my $helper (keys %{ $self->{helpers} }) { - my $code = $self->{helpers}{$helper}; - $funcs->{$helper} = sub { - my ($raw_text, $vars, @args) = @_; - my $recurse = sub { - my ($new_vars) = @_; - return $weakself->render_string($raw_text, $new_vars); - }; - - return $code->($vars, @args, { fn => $recurse }); - } - } + my $recurse = sub { + my ($new_vars) = @_; + return $weakself->render_string($raw_text, $new_vars); + }; + + return $code->($vars, @args, { fn => $recurse }); + }; } 1; diff --git a/lib/Text/Xslate/Syntax/Handlebars.pm b/lib/Text/Xslate/Syntax/Handlebars.pm index d99f3d0..69a20c6 100644 --- a/lib/Text/Xslate/Syntax/Handlebars.pm +++ b/lib/Text/Xslate/Syntax/Handlebars.pm @@ -350,11 +350,15 @@ sub std_block { $self->advance(';'); if ($name->arity eq 'call') { - unshift @{ $name->second }, ( - $raw_text->clone, - $self->symbol('(vars)')->clone(arity => 'vars'), + return $self->print_raw( + $self->call( + '(run_block_helper)', + $self->symbol($name->first->id)->clone, + $raw_text->clone, + $self->symbol('(vars)')->clone(arity => 'vars'), + @{ $name->second }, + ), ); - return $self->print_raw($name); } my $iterations = $inverted diff --git a/t/helpers.t b/t/helpers.t index 3cc418d..50f3fe0 100644 --- a/t/helpers.t +++ b/t/helpers.t @@ -7,7 +7,7 @@ use Test::Handlebars; render_ok( { - helpers => { + function => { noop => sub { my ($context, $options) = @_; return $options->{fn}->($context); @@ -36,7 +36,7 @@ RENDERED render_ok( { - helpers => { + function => { with => sub { my ($context, $new_context, $options) = @_; return $options->{fn}->($new_context); @@ -71,7 +71,7 @@ RENDERED render_ok( { - helpers => { + function => { with => sub { my ($context, $new_context, $options) = @_; return $options->{fn}->($new_context); @@ -138,7 +138,7 @@ RENDERED render_ok( { - helpers => { + function => { list => sub { my ($context, $items, $options) = @_; my $out = "<ul>"; @@ -178,7 +178,7 @@ RENDERED render_ok( { - helpers => { + function => { if => sub { my ($context, $conditional, $options) = @_; if ($conditional) { @@ -204,7 +204,7 @@ RENDERED render_ok( { - helpers => { + function => { if => sub { my ($context, $conditional, $options) = @_; if ($conditional) { @@ -230,7 +230,7 @@ RENDERED { local $TODO = "unimplemented"; local $SIG{__WARN__} = sub { }; render_ok( { - helpers => { + function => { if => sub { my ($context, $conditional, $options) = @_; if ($conditional) { @@ -260,7 +260,7 @@ RENDERED render_ok( { - helpers => { + function => { if => sub { my ($context, $conditional, $options) = @_; if ($conditional) { @@ -290,7 +290,7 @@ RENDERED render_ok( { - helpers => { + function => { list => sub { my ($context, $items, $options) = @_; @@ -333,7 +333,7 @@ RENDERED render_ok( { - helpers => { + function => { list => sub { my ($context, $items, $options) = @_; |