summaryrefslogtreecommitdiff
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
parentMerge pull request #5 from ywatase/fix_extention_problem (diff)
downloaddancer-template-xslate-039b1aa667373f9af5b5fe4121d509075cddbc69.tar.gz
Clean up code and docs, tweak tests.
-rw-r--r--.gitignore4
-rw-r--r--Changes17
-rw-r--r--dist.ini1
-rw-r--r--lib/Dancer/Template/Xslate.pm54
-rw-r--r--perlcritic.rc1
-rw-r--r--t/01-main.t8
-rw-r--r--t/03-cascade.t15
7 files changed, 60 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fe0c40c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*#
+*#*
+.build
+Dancer-Template-Xslate-*
diff --git a/Changes b/Changes
index 8edba69..91fb2f4 100644
--- a/Changes
+++ b/Changes
@@ -1,12 +1,15 @@
Revision history for Dancer-Template-Xslate
{{$NEXT}}
+ - Fix bug involving conversion from "extension" to "suffix" options.
+ - Documented caveats involving Dancer's "layout" feature.
-0.02 2011-12-12 18:35:33 CST6CDT
- - 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.02 2011-12-12 18:35:33 America/Chicago
+ - Fix bug preventing templates with extensions other than "tt" from being
+ found.
+ - Now accepting relative template paths
+ - Fixed MS Windows pathing bug.
+ - Stopped using Dancer::Config directly.
-0.01 Mon 2010-08-02 12:23:50 CEST
- - initial release
+0.01 Mon 2010-08-02 12:23:50 CEST
+ - initial release
diff --git a/dist.ini b/dist.ini
index 60f31c5..c8ce79b 100644
--- a/dist.ini
+++ b/dist.ini
@@ -24,6 +24,7 @@ homepage = https://github.com/franckcuny/dancer-template-xslate
[Test::PodSpelling]
stopwords = franck
stopwords = cuny
+stopwords = Xslate's
[PodWeaver]
[AutoPrereqs]
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
diff --git a/perlcritic.rc b/perlcritic.rc
index 686c6bf..c891e6b 100644
--- a/perlcritic.rc
+++ b/perlcritic.rc
@@ -1,4 +1,5 @@
severity = 3
verbose = 9
theme = core
+exclude = RegularExpressions::RequireExtendedFormatting
include = Variables::ProhibitPackageVars
diff --git a/t/01-main.t b/t/01-main.t
index 1a79add..481c980 100644
--- a/t/01-main.t
+++ b/t/01-main.t
@@ -14,12 +14,12 @@ my $result = $engine->render(
$template,
{ var1 => 1,
var2 => 2,
- foo => 'one',
- bar => 'two',
- baz => 'three'
+ foo => "one",
+ bar => "two",
+ baz => "three"
}
);
my $expected =
- 'this is var1="1" and var2=2' . "\n\nanother line\n\none two three\n";
+ qq(this is var1="1" and var2=2\n\nanother line\n\none two three\n);
is $result, $expected, "processed a template given as a file name";
diff --git a/t/03-cascade.t b/t/03-cascade.t
index 5da25e2..2a3991a 100644
--- a/t/03-cascade.t
+++ b/t/03-cascade.t
@@ -1,28 +1,27 @@
use strict;
use warnings;
use Test::More tests => 2;
-use File::Spec::Functions qw(catfile);
+use File::Spec::Functions qw(catdir catfile);
use Dancer::Template::Xslate;
my $engine = Dancer::Template::Xslate->new(
config =>
{
- extension => 'tx',
- path => [catfile(qw(t views))],
+ extension => "tx",
+ path => [catdir(qw(t views))],
},
);
-my $template = catfile(qw(t views cascade.tx));
-my $result = $engine->render($template);
+my $template = "cascade.tx";
+my $result = $engine->render($template);
my $expected = "header\nbody\nfooter\n";
-
is $result, $expected, "cascade and extension test";
$engine = Dancer::Template::Xslate->new(
config =>
{
- suffix => '.tx',
- path => [catfile(qw(t views))],
+ suffix => ".tx",
+ path => [catdir(qw(t views))],
},
);
$result = $engine->render($template);