diff options
author | Richard Simões <rsimoes@cpan.org> | 2011-12-05 10:54:10 -0800 |
---|---|---|
committer | Richard Simões <rsimoes@cpan.org> | 2011-12-05 10:54:10 -0800 |
commit | 23433b80be8b3ea6779658e28f7cac6d58dcd77c (patch) | |
tree | b073eab21ee90c9282a4b91a70eea714afad32d2 | |
parent | update tests (diff) | |
parent | fix Win32 path (diff) | |
download | dancer-template-xslate-23433b80be8b3ea6779658e28f7cac6d58dcd77c.tar.gz |
Merge pull request #4 from fayland/master
fix few issues like
-rw-r--r-- | lib/Dancer/Template/Xslate.pm | 19 | ||||
-rw-r--r-- | t/02-app.t | 2 |
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/Dancer/Template/Xslate.pm b/lib/Dancer/Template/Xslate.pm index 939bbb8..d3b062b 100644 --- a/lib/Dancer/Template/Xslate.pm +++ b/lib/Dancer/Template/Xslate.pm @@ -6,6 +6,8 @@ use strict; use warnings; use Text::Xslate; +use Dancer::App; +use File::Spec; use base 'Dancer::Template::Abstract'; @@ -20,11 +22,28 @@ sub init { %{$self->config}, ); + ## set default path for header/footer etc. + $args{path} ||= []; + my $view_dir = Dancer::App->current->setting('views'); + push @{$args{path}}, $view_dir unless grep { $_ eq $view_dir } @{$args{path}}; + + ## for those people read Text::Xslate instead of Dancer::Template::Abstract + $self->config->{extension} = $args{suffix} if exists $args{suffix}; + # avoid 'Text::Xslate: Unknown option(s): extension' + $args{suffix} = delete $args{extension} if exists $args{extension}; + $_engine = Text::Xslate->new(%args); } sub render { my ($self, $template, $tokens) = @_; + + # absolute filename will never work under Windows even we hard set path as ['/'] + my $view_dir = Dancer::App->current->setting('views'); + if ( $view_dir ) { + $view_dir = File::Spec->catdir( File::Spec->splitdir($view_dir) ) if $^O eq 'MSWin32'; # dirty Win32 fixes for / \ + $template =~ s/^\Q$view_dir\E//; + } my $content = eval { $_engine->render($template, $tokens) diff --git a/t/02-app.t b/t/02-app.t index 73e738c..40d0d27 100644 --- a/t/02-app.t +++ b/t/02-app.t @@ -7,8 +7,8 @@ use Dancer::Test; plan tests => 3; -setting template => 'xslate'; setting views => 't'; +setting template => 'xslate'; ok( get '/' => sub { |