summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Simões <rsimoes@cpan.org>2011-12-09 10:09:17 -0600
committerRichard Simões <rsimoes@cpan.org>2011-12-09 10:09:17 -0600
commit495c00a71e8937eb9fd6f85657c8b7d097f1dfba (patch)
tree0fa7c861f34880858b42b9f61c09684bb137c656
parentMerge pull request #4 from fayland/master (diff)
downloaddancer-template-xslate-495c00a71e8937eb9fd6f85657c8b7d097f1dfba.tar.gz
add dzil plugins, use File::Spec exclusively instead of regular expressions
-rw-r--r--Changes8
-rw-r--r--dist.ini33
-rw-r--r--lib/Dancer/Template/Xslate.pm64
-rw-r--r--perlcritic.rc4
-rw-r--r--t/00-load.t7
-rw-r--r--t/01-main.t13
-rw-r--r--t/02-app.t28
-rw-r--r--t/lib/TestApp.pm22
-rw-r--r--t/views/index.tx (renamed from t/index.tx)0
-rw-r--r--t/views/index.xslate (renamed from t/index.xslate)0
10 files changed, 102 insertions, 77 deletions
diff --git a/Changes b/Changes
index 9ff9470..1a9b490 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,10 @@
-Revision history for Perl extension Dancer::Template::Xslate
+Revision history for Dancer-Template-Xslate
+
+{{$NEXT}}
+     - fix bug preventing templates with extensions other than "tt" from being found
+     - accept relative template paths
+     - fix MS Windows pathing bug
+     - don't use Dancer::Config directly
 
 0.01 Mon 02 Aug 2010 12:23:50 PM CEST
      - initial release
diff --git a/dist.ini b/dist.ini
index b2c7be5..5fabcfb 100644
--- a/dist.ini
+++ b/dist.ini
@@ -2,27 +2,36 @@ name = Dancer-Template-Xslate
 author = franck cuny <franck@lumberjaph.net>
 license = Perl_5
 copyright_holder = franck cuny
-copyright_year = 2010
-version = 0.01
+copyright_year = 2011
+version = 0.010_001
 
 [@Filter]
 bundle = @Basic
+remove = MakeMaker
+[ModuleBuild]
 
-[MetaConfig]
-[MetaJSON]
-[PkgVersion]
-[PodSyntaxTests]
-[PodCoverageTests]
-[NoTabsTests]
-[EOLTests]
+[@TestingMania]
+
+[AutoMetaResources]
+repository.github = user:franckcuny
+bugtracker.github = user:franckcuny
 
 [MetaResources]
 repository = git://github.com/franckcuny/dancer-template-xslate.git
 bugtracker = http://rt.cpan.org/Public/Dist/Display.html?Name=Dancer::Template::Xslate
 homepage = http://search.cpan.org/perldoc?Dancer::Template::Xslate
 
+[Test::PodSpelling]
+stopwords = franck
+stopwords = cuny
+
 [PodWeaver]
-[AutoPrereq]
+[AutoPrereqs]
 [ReadmeFromPod]
-[CheckChangeLog]
-[UploadToCPAN]
+[CheckChangesHasContent]
+[Clean]
+[ExtraTests]
+[MetaJSON]
+[MinimumPerl]
+[NextRelease]
+[OurPkgVersion]
diff --git a/lib/Dancer/Template/Xslate.pm b/lib/Dancer/Template/Xslate.pm
index d3b062b..203089d 100644
--- a/lib/Dancer/Template/Xslate.pm
+++ b/lib/Dancer/Template/Xslate.pm
@@ -1,57 +1,57 @@
 package Dancer::Template::Xslate;
 
-# ABSTRACT: Text::Xslate wrapper for Dancer
 
 use strict;
 use warnings;
 
-use Text::Xslate;
+use Carp;
 use Dancer::App;
-use File::Spec;
+use File::Spec::Functions qw(splitpath);
+use Text::Xslate;
 
 use base 'Dancer::Template::Abstract';
 
-my $_engine;
+# VERSION
+# ABSTRACT: Text::Xslate wrapper for Dancer
 
-sub default_tmpl_ext { "tx" }
+# Note: The standard Xslate template extension is
+# "tx" but kept to "tt" for backward compatibility.
 
 sub init {
-    my $self = shift;
-
-    my %args = (
-        %{$self->config},
-    );
+    my ($self) = @_;
+    my $config = $self->config;
+    my $app    = Dancer::App->current;
+    my %xslate_args = %{$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);
+    $xslate_args{path} ||= [];
+    my $views_dir = $config->{views_dir} = $app->setting('views');
+    push @{$xslate_args{path}}, $views_dir
+        if not grep { $_ eq $views_dir } @{$xslate_args{path}};
+
+    ## for those who read Text::Xslate instead of Dancer::Template::Abstract
+    $config->{extension} = $xslate_args{suffix}
+        if exists $xslate_args{suffix};
+
+    ## avoid 'Text::Xslate: Unknown option(s): extension'
+    $xslate_args{suffix} = delete $xslate_args{extension}
+        if exists $xslate_args{extension};
+
+    $self->{driver} = Text::Xslate->new(%xslate_args);
+    return;
 }
 
 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 $config = $self->config;
 
-    my $content = eval {
-        $_engine->render($template, $tokens)
-    };
+    my $views_dir = $self->config->{views_dir};
+    (undef, undef, $template) = splitpath $template if $views_dir;
+    my $xslate = $self->{driver};
+    my $content = $xslate->render($template, $tokens);
 
     if (my $err = $@) {
-        my $error = qq/Couldn't render template "$err"/;
-        die $error;
+        croak qq[Couldn't render template "$err"];
     }
 
     return $content;
diff --git a/perlcritic.rc b/perlcritic.rc
new file mode 100644
index 0000000..686c6bf
--- /dev/null
+++ b/perlcritic.rc
@@ -0,0 +1,4 @@
+severity = 3
+verbose  = 9
+theme    = core
+include  = Variables::ProhibitPackageVars
diff --git a/t/00-load.t b/t/00-load.t
deleted file mode 100644
index d4ef20b..0000000
--- a/t/00-load.t
+++ /dev/null
@@ -1,7 +0,0 @@
-use strict;
-use warnings;
-use Test::More tests => 1;
-
-BEGIN {
-    use_ok( 'Dancer::Template::Xslate' ) || print "Bail out!";
-}
diff --git a/t/01-main.t b/t/01-main.t
index 97682ed..c0961e3 100644
--- a/t/01-main.t
+++ b/t/01-main.t
@@ -1,16 +1,15 @@
 use strict;
 use warnings;
 use Test::More tests => 2;
-use Dancer::FileUtils 'path';
+use File::Spec::Functions qw(catfile);
 
 use Dancer::Template::Xslate;
 
-my $engine;
-eval { $engine = Dancer::Template::Xslate->new };
-is $@, '',
-  "Dancer::Template::Xslate engine created";
-
-my $template = path('t', 'index.xslate');
+ok(
+    my $engine = Dancer::Template::Xslate->new,
+    "Dancer::Template::Xslate engine created"
+);
+my $template = catfile(qw(t views index.xslate));
 
 my $result = $engine->render(
     $template,
diff --git a/t/02-app.t b/t/02-app.t
index 40d0d27..737008e 100644
--- a/t/02-app.t
+++ b/t/02-app.t
@@ -1,20 +1,12 @@
 use strict;
 use warnings;
-use Test::More import => ["!pass"];
-
-use Dancer ':syntax';
-use Dancer::Test;
-
-plan tests => 3;
-
-setting views   => 't';
-setting template => 'xslate';
-
-ok(
-    get '/' => sub {
-        template 'index', { loop => [1..2] };
-    }
-);
-
-route_exists [ GET => '/' ];
-response_content_like( [ GET => '/' ], qr/1<br \/>\n2/ );
+use Test::More tests => 2;
+use File::Spec;
+
+{
+    use Dancer::Test;
+    use lib File::Spec->catdir(qw(t lib));
+    use TestApp;
+    route_exists [ GET => '/' ];
+    response_content_like( [ GET => '/' ], qr/1<br \/>\n2/ );
+}
diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm
new file mode 100644
index 0000000..32b7255
--- /dev/null
+++ b/t/lib/TestApp.pm
@@ -0,0 +1,22 @@
+package
+TestApp;
+
+use strict;
+use warnings;
+use Dancer ':syntax';
+use File::Spec::Functions qw(catdir);
+
+set views    => catdir qw(t views);
+set engines => {
+    xslate => {
+        cache     => 0,
+        extension => 'tx',
+    },
+};
+set template => 'xslate';
+set logger   => 'console';
+set log      => 'warning';
+
+get '/' => sub { return template 'index', { loop => [1, 2] } };
+
+true;
diff --git a/t/index.tx b/t/views/index.tx
index 8ecc8e1..8ecc8e1 100644
--- a/t/index.tx
+++ b/t/views/index.tx
diff --git a/t/index.xslate b/t/views/index.xslate
index 7ec6233..7ec6233 100644
--- a/t/index.xslate
+++ b/t/views/index.xslate