diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-10-19 03:32:22 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-01-02 13:56:21 -0600 |
commit | 271ae740506b9b64119494a3a34bfe8a9786037e (patch) | |
tree | 4e0e835fb6a50d60f5cbb1b6e148ac00fceabe9f /lib/Text/Handlebars | |
parent | af336052276fd8d61b4c61a22ec77732083667c2 (diff) | |
download | text-handlebars-271ae740506b9b64119494a3a34bfe8a9786037e.tar.gz text-handlebars-271ae740506b9b64119494a3a34bfe8a9786037e.zip |
move most of find_file into the compiler
Diffstat (limited to 'lib/Text/Handlebars')
-rw-r--r-- | lib/Text/Handlebars/Compiler.pm | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/lib/Text/Handlebars/Compiler.pm b/lib/Text/Handlebars/Compiler.pm index 57a746a..4681d30 100644 --- a/lib/Text/Handlebars/Compiler.pm +++ b/lib/Text/Handlebars/Compiler.pm @@ -83,10 +83,7 @@ sub _generate_partial { return ( $self->compile_ast( - $self->save_lvar( - $lvar_id, - $self->call($node, '(find_file)', $node->first->clone) - ), + $self->save_lvar($lvar_id, $self->find_file($node->first->clone)), ), $self->compile_ast( $self->make_ternary( @@ -102,6 +99,42 @@ sub _generate_partial { ); } +sub find_file { + my $self = shift; + my ($filename) = @_; + + return $filename->clone( + arity => 'find_file', + first => $filename, + ); +} + +sub _generate_find_file { + my $self = shift; + my ($node) = @_; + + my $filename = $node->first; + my $with_suffix = $self->parser->symbol('~')->clone( + arity => 'binary', + first => $filename->clone, + second => $self->call($node, '(suffix)'), + ); + + return ( + $self->compile_ast( + $self->make_ternary( + $self->call($node, '(find_file)', $filename->clone), + $filename->clone, + $self->make_ternary( + $self->call($node, '(find_file)', $with_suffix->clone), + $with_suffix->clone, + $self->literal(''), + ), + ), + ), + ); +} + sub _generate_for { my $self = shift; my ($node) = @_; |