summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-08 14:15:23 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-08 14:15:23 -0500
commit703ac3ef783a86eac77af2c402c6600c33e6a71c (patch)
tree7d7552cbc02a792d742b4760b784b41a2569ce64
parent52ea1ea3f9d1bd29dcb7b056536a8b3f58268dee (diff)
downloadtext-handlebars-703ac3ef783a86eac77af2c402c6600c33e6a71c.tar.gz
text-handlebars-703ac3ef783a86eac77af2c402c6600c33e6a71c.zip
move more bits into the compiler
-rw-r--r--lib/Text/Handlebars/Compiler.pm30
-rw-r--r--lib/Text/Xslate/Syntax/Handlebars.pm27
2 files changed, 41 insertions, 16 deletions
diff --git a/lib/Text/Handlebars/Compiler.pm b/lib/Text/Handlebars/Compiler.pm
index 54f760d..5ffe882 100644
--- a/lib/Text/Handlebars/Compiler.pm
+++ b/lib/Text/Handlebars/Compiler.pm
@@ -105,6 +105,8 @@ sub _generate_call {
my $hash = $parser->call($make_hash, @hash);
+ unshift @args, $parser->vars;
+
if ($node->first->arity eq 'call' && $node->first->first->id eq '(make_block_helper)') {
push @{ $node->first->second }, $hash;
$node->second(\@args);
@@ -117,6 +119,34 @@ sub _generate_call {
return $self->SUPER::_generate_call($node);
}
+sub _generate_partial {
+ my $self = shift;
+ my ($node) = @_;
+
+ my $parser = $self->parser;
+
+ my $find_file = $parser->symbol('(name)')->clone(
+ arity => 'name',
+ id => '(find_file)',
+ line => $node->line,
+ );
+
+ return $self->compile_ast(
+ $parser->make_ternary(
+ $parser->call($find_file, $node->first->clone),
+ $node->clone(
+ arity => 'include',
+ id => 'include',
+ first => $node->first,
+ ),
+ $node->clone(
+ arity => 'literal',
+ id => '',
+ ),
+ ),
+ );
+}
+
__PACKAGE__->meta->make_immutable;
no Any::Moose;
diff --git a/lib/Text/Xslate/Syntax/Handlebars.pm b/lib/Text/Xslate/Syntax/Handlebars.pm
index 0929f2c..dc4713b 100644
--- a/lib/Text/Xslate/Syntax/Handlebars.pm
+++ b/lib/Text/Xslate/Syntax/Handlebars.pm
@@ -308,11 +308,6 @@ sub nud_name {
my $call = $self->call($name);
- if ($name->is_helper) {
- $call->is_helper(1);
- push @{ $call->second }, $self->vars;
- }
-
if ($self->token->is_defined) {
push @{ $call->second }, $self->expression(0);
}
@@ -504,17 +499,9 @@ sub std_partial {
my $partial = $self->token->clone(arity => 'literal');
$self->advance;
- return $self->make_ternary(
- $self->call('(find_file)', $partial->clone),
- $symbol->clone(
- arity => 'include',
- id => 'include',
- first => $partial,
- ),
- $symbol->clone(
- arity => 'literal',
- id => '',
- ),
+ return $symbol->clone(
+ arity => 'partial',
+ first => $partial,
);
}
@@ -617,6 +604,14 @@ sub expression {
return $left;
}
+sub call {
+ my $self = shift;
+
+ my $call = $self->SUPER::call(@_);
+ $call->is_helper($call->first->is_helper);
+ return $call;
+}
+
sub make_field_lookup {
my $self = shift;
my ($var, $field, $dot) = @_;