summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Text/Handlebars.pm5
-rw-r--r--lib/Text/Handlebars/Compiler.pm12
-rw-r--r--t/mustache.t4
3 files changed, 17 insertions, 4 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 {
diff --git a/t/mustache.t b/t/mustache.t
index bbd9227..8034db2 100644
--- a/t/mustache.t
+++ b/t/mustache.t
@@ -152,9 +152,8 @@ RENDERED
"comments"
);
-{ local $TODO = "unimplemented";
render_file_ok(
- { path => ['t/mustache/partials'] },
+ { path => ['t/mustache/partials'], suffix => '.mustache' },
'base.mustache',
{
names => [
@@ -171,7 +170,6 @@ render_file_ok(
EXPECTED
"partials"
);
-}
render_ok(
<<'TEMPLATE',