summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-13 22:09:57 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-13 22:09:57 +0200
commit82166696c912e9ca2e2b1937606f9af58982cae6 (patch)
tree9aa1e4fa416ab5f4e18106d5dd160c3c16136550
downloaddancer-template-declare-82166696c912e9ca2e2b1937606f9af58982cae6.tar.gz
first commit
-rw-r--r--lib/Dancer/Template/Declare.pm25
-rw-r--r--t/01-basic.t32
2 files changed, 57 insertions, 0 deletions
diff --git a/lib/Dancer/Template/Declare.pm b/lib/Dancer/Template/Declare.pm
new file mode 100644
index 0000000..8816ecd
--- /dev/null
+++ b/lib/Dancer/Template/Declare.pm
@@ -0,0 +1,25 @@
+package Dancer::Template::Declare;
+
+use strict;
+use warnings;
+
+use base 'Dancer::Template::Abstract';
+use Template::Declare;
+
+my $_init;
+
+sub init {
+    my $self = shift;
+    $_init = $self->{config};
+}
+
+sub view { return $_[1] }
+sub layout { return $_[3] }
+
+sub render {
+    my ($self, $template, $token) = @_;
+    Template::Declare->init( %{ $_init } );
+    Template::Declare->show($template, $token);
+}
+
+1;
diff --git a/t/01-basic.t b/t/01-basic.t
new file mode 100644
index 0000000..9193bdf
--- /dev/null
+++ b/t/01-basic.t
@@ -0,0 +1,32 @@
+use strict;
+use warnings;
+use Test::More import => ['!pass'];
+
+package mytemplate;
+use Template::Declare::Tags;
+use base 'Template::Declare';
+
+template hello => sub {
+    my ($self, $vars) = @_;
+    html {
+        head {
+            title {"Hello, $vars->{user}"};
+        };
+        body {
+            h1 {"Hello, $vars->{user}"};
+        };
+    };
+};
+
+package main;
+
+use Dancer::Template::Declare;
+
+ok my $td =
+  Dancer::Template::Declare->new(config => {dispatch_to => [qw/mytemplate/]}),
+  'D::T::Declare object created';
+
+ok my $result = $td->render('hello', {user => 'marc'}), 'render is ok';
+like $result, qr/<title>Hello, marc<\/title>/, 'content match';
+
+done_testing;