diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-10-03 18:34:41 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-10-03 18:34:41 -0500 |
commit | 6b7da8376218972db4d0a98a9e0220f9dc81dbd5 (patch) | |
tree | dce212b18885d32f6075af659752a13db2f88238 /lib/Text | |
parent | a7a8576d3716a03b7216252d0b25625e9edc67a7 (diff) | |
download | text-handlebars-6b7da8376218972db4d0a98a9e0220f9dc81dbd5.tar.gz text-handlebars-6b7da8376218972db4d0a98a9e0220f9dc81dbd5.zip |
make suffixes work for partials
Diffstat (limited to 'lib/Text')
-rw-r--r-- | lib/Text/Handlebars.pm | 5 | ||||
-rw-r--r-- | lib/Text/Handlebars/Compiler.pm | 12 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/Text/Handlebars.pm b/lib/Text/Handlebars.pm index 4cb1723..7c975b9 100644 --- a/lib/Text/Handlebars.pm +++ b/lib/Text/Handlebars.pm @@ -81,7 +81,10 @@ sub _register_builtin_methods { }; $funcs->{'(find_file)'} = sub { my ($filename) = @_; - return try { $weakself->find_file($filename); 1 } catch { undef }; + return 1 if try { $weakself->find_file($filename); 1 }; + $filename .= $weakself->{suffix}; + return 1 if try { $weakself->find_file($filename); 1 }; + return 0; }; } diff --git a/lib/Text/Handlebars/Compiler.pm b/lib/Text/Handlebars/Compiler.pm index 5f112fc..2fc7422 100644 --- a/lib/Text/Handlebars/Compiler.pm +++ b/lib/Text/Handlebars/Compiler.pm @@ -3,6 +3,8 @@ use Any::Moose; extends 'Text::Xslate::Compiler'; +use Try::Tiny; + has '+syntax' => ( default => 'Handlebars', ); @@ -19,6 +21,16 @@ sub _generate_block { return @compiled; } +sub _generate_include { + my $self = shift; + my ($node) = @_; + + my $file = $node->first; + $file->id($file->id . $self->engine->{suffix}) + unless try { $self->engine->find_file($file->id); 1 }; + return $self->SUPER::_generate_include($node); +} + if (0) { our $_recursing; around compile_ast => sub { |