summary refs log tree commit diff
path: root/lib/Dancer/Template/Xslate.pm
diff options
context:
space:
mode:
authorRichard Simões <rsimoes@cpan.org>2012-04-12 20:04:36 -0500
committerRichard Simões <rsimoes@cpan.org>2012-04-12 20:12:39 -0500
commit039b1aa667373f9af5b5fe4121d509075cddbc69 (patch)
tree0399836a2ea4bdb7d939e8974c86bce04d092257 /lib/Dancer/Template/Xslate.pm
parentMerge pull request #5 from ywatase/fix_extention_problem (diff)
downloaddancer-template-xslate-039b1aa667373f9af5b5fe4121d509075cddbc69.tar.gz
Clean up code and docs, tweak tests.
Diffstat (limited to 'lib/Dancer/Template/Xslate.pm')
-rw-r--r--lib/Dancer/Template/Xslate.pm54
1 files changed, 33 insertions, 21 deletions
diff --git a/lib/Dancer/Template/Xslate.pm b/lib/Dancer/Template/Xslate.pm
index 688a645..cd29dec 100644
--- a/lib/Dancer/Template/Xslate.pm
+++ b/lib/Dancer/Template/Xslate.pm
@@ -1,6 +1,5 @@
 package Dancer::Template::Xslate;
 
-
 use strict;
 use warnings;
 
@@ -9,7 +8,7 @@ use Dancer::App;
 use File::Spec::Functions qw(abs2rel rel2abs);
 use Text::Xslate;
 
-use base 'Dancer::Template::Abstract';
+use base "Dancer::Template::Abstract";
 
 # VERSION
 # ABSTRACT: Text::Xslate wrapper for Dancer
@@ -22,35 +21,38 @@ sub init {
     my $app    = Dancer::App->current;
     my %xslate_args = %{$self->config};
 
-    ## set default path for header/footer etc.
+    ## Set default path for header/footer etc.
     $xslate_args{path} ||= [];
-    my $views_dir = $app->setting('views');
-    push @{$xslate_args{path}}, $views_dir
-        if not grep { $_ eq $views_dir } @{$xslate_args{path}};
+    my $views_dir = $app->setting("views") || "";
+    push @{ $xslate_args{path} }, $views_dir
+        if !grep { $_ eq $views_dir } @{ $xslate_args{path} };
 
     ## for those who read Text::Xslate instead of Dancer::Template::Abstract
-    $self->config->{extension} = $xslate_args{suffix}
-        if exists $xslate_args{suffix};
-
-    $self->config->{extension} =~ s/^\.//;
+    if ( defined $xslate_args{suffix} ) {
+        $self->config->{extension} = $xslate_args{suffix};
+        $self->config->{extension} =~ s/^\.//;
+    }
 
-    ## avoid 'Text::Xslate: Unknown option(s): extension'
-    $xslate_args{suffix} = '.' . delete $xslate_args{extension}
-        if exists $xslate_args{extension};
+    ## Avoid "Text::Xslate: Unknown option(s): extension"
+    $xslate_args{suffix} = exists $xslate_args{extension}
+        ? delete $xslate_args{extension}
+        : ".tt";
+    $xslate_args{suffix} = ".$xslate_args{suffix}"
+        if $xslate_args{suffix} !~ /^\./;
 
     $self->{driver} = Text::Xslate->new(%xslate_args);
-    return;
+    return $self;
 }
 
 sub render {
     my ($self, $template, $tokens) = @_;
     my $app    = Dancer::App->current;
-    $template = abs2rel( rel2abs($template), $app->setting('views') );
+    $template = abs2rel( rel2abs($template), $app->setting("views") );
     my $xslate = $self->{driver};
     my $content = $xslate->render($template, $tokens);
 
     if (my $err = $@) {
-        croak qq[Couldn't render template "$err"];
+        croak qq(Couldn't render template "$err");
     }
 
     return $content;
@@ -85,20 +87,30 @@ You can configure L<Text::Xslate>:
 
 =head1 CAVEATS
 
-=head2 Cascading
+=over
+
+=item Cascading
 
 Dancer already provides a <cascade>-like feature, called a "layout", in order
-to augment other template engines lacking such a feature. If you want to use
+to augment other template engines lacking such a feature. In order to use
 Xslate's C<cascade>, turn off C<layout> by commenting out or removing the
-appropriate line in your Dancer config file.
+appropriate line in your Dancer application config.
 
-=head2 Smart HTML Escaping
+=item Smart HTML Escaping
 
 Use of Dancer's C<layout> feature will cause HTML templates to be HTML-entity
 encoded twice if Xslate's "smart HTML escaping" feature is enabled. Xslate's
 C<type> option can be set to "text" to disable smart-escaping, or, once again,
 C<layout> can be disabled in favor of C<cascade>.
 
+=back
+
 =head1 SEE ALSO
 
-L<Dancer>, L<Text::Xslate>, L<http://xslate.org/>
+=over
+
+=item L<Dancer>
+
+=item L<Text::Xslate>
+
+=back