File Coverage

lib/Dancer/Template/TemplateDeclare.pm
Criterion Covered Total %
statement 36 37 97.3
branch 1 2 50.0
condition 1 2 50.0
subroutine 13 14 92.8
pod 6 6 100.0
total 57 61 93.4


line stmt bran cond sub pod time code
1             package Dancer::Template::TemplateDeclare;
2             BEGIN {
3 3     3   630883 $Dancer::Template::TemplateDeclare::AUTHORITY = 'cpan:YANICK';
4             }
5             {
6             $Dancer::Template::TemplateDeclare::VERSION = '0.3.2';
7             }
8             # ABSTRACT: Template::Declare wrapper for Dancer
9              
10 3     3   35 use strict;
  3         7  
  3         99  
11 3     3   18 use FindBin;
  3         5  
  3         139  
12 3     3   3145 use Template::Declare;
  3         36277  
  3         98  
13 3     3   1132 use Dancer::Config 'setting';
  3         95897  
  3         222  
14              
15 3     3   24 use base 'Dancer::Template::Abstract';
  3         7  
  3         1262  
16              
17             sub init {
18 3     3 1 1055 my $self = shift;
19 3 50       5 my %config = %{$self->config || {}};
  3         24  
20              
21 3         71 my %args = @_;
22              
23 3         12 @config{keys %args} = values %args;
24              
25 3   50 2   5 eval "use $_; 1;" or die $@ for @{ $config{dispatch_to} };
  3     1   236  
  2         1184  
  2         33675  
  2         40  
  1         6  
  1         2  
  1         9  
26              
27 3         26 Template::Declare->init(%config);
28             }
29              
30 0     0 1 0 sub default_tmpl_ext { return 'DUMMY'; } # because Dancer requires an ext
31              
32 3     3 1 79 sub view_exists { return 1; }
33              
34 6     6 1 9142 sub view { return $_[1] }
35              
36             sub render {
37 5     5 1 920 my ($self, $template, $tokens) = @_;
38              
39 5         26 return Template::Declare->show( $template => $tokens );
40             }
41              
42             sub layout {
43 2     2 1 1339 my ($self, $layout, $tokens, $content) = @_;
44              
45 2         32 return Template::Declare->show(
46             join( '/', 'layout', $layout ) => {
47             %$tokens, content => $content
48             }
49             );
50             }
51              
52             1;
53              
54              
55              
56             =pod
57              
58             =head1 NAME
59              
60             Dancer::Template::TemplateDeclare - Template::Declare wrapper for Dancer
61              
62             =head1 VERSION
63              
64             version 0.3.2
65              
66             =head1 SYNOPSIS
67              
68             # in 'config.yml'
69             template: 'TemplateDeclare'
70              
71             engines:
72             TemplateDeclare:
73             dispatch_to:
74             - A::Template::Class
75             - Another::Template::Class
76              
77             # in the app
78            
79             get '/foo', sub {
80             template 'foo' => {
81             title => 'bar'
82             };
83             };
84              
85             =head1 DESCRIPTION
86              
87             This class is an interface between Dancer's template engine abstraction layer
88             and the L templating system.
89              
90             In order to use this engine, set the template to 'TemplateDeclare' in the configuration
91             file:
92              
93             template: TemplateDeclare
94              
95             =head1 Template::Declare CONFIGURATION
96              
97             Parameters can also be passed to the L interpreter via
98             the configuration file, like so:
99              
100             engines:
101             TemplateDeclare:
102             dispatch_to:
103             - Some::Template
104             - Some::Other::Template
105              
106             All the dispatch classes are automatically
107             loaded behind the scene.
108              
109             =head1 USING LAYOUTS
110              
111             If the layout is set to I<$name>,
112             the template C will be used and
113             passed via the C argument.
114              
115             For example, a simple C
layout would be:
116              
117             template '/layout/main' => sub {
118             my ( $self, $args ) = @_;
119              
120             html {
121             body {
122             outs_raw $args->{content}
123             }
124             }
125             };
126              
127             =head1 SEE ALSO
128              
129             L, L.
130              
131             =head1 AUTHOR
132              
133             Yanick Champoux
134              
135             =head1 COPYRIGHT AND LICENSE
136              
137             This software is copyright (c) 2012 by Yanick Champoux.
138              
139             This is free software; you can redistribute it and/or modify it under
140             the same terms as the Perl 5 programming language system itself.
141              
142             =cut
143              
144              
145             __END__