summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Simões <rsimoes@cpan.org>2011-12-05 10:54:10 -0800
committerRichard Simões <rsimoes@cpan.org>2011-12-05 10:54:10 -0800
commit23433b80be8b3ea6779658e28f7cac6d58dcd77c (patch)
treeb073eab21ee90c9282a4b91a70eea714afad32d2
parentupdate tests (diff)
parentfix Win32 path (diff)
downloaddancer-template-xslate-23433b80be8b3ea6779658e28f7cac6d58dcd77c.tar.gz
Merge pull request #4 from fayland/master
fix few issues like
-rw-r--r--lib/Dancer/Template/Xslate.pm19
-rw-r--r--t/02-app.t2
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 {