File Coverage

blib/lib/Dancer/Layout/Bootstrap.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Dancer::Layout::Bootstrap;
2 1     1   1020 use Dancer ':syntax';
  1         148465  
  1         5  
3 1     1   634 use Dancer::Plugin::FlashMessage;
  1         2095  
  1         173  
4              
5             =head1 NAME
6              
7             Dancer::Layout::Bootstrap - Boostrap layout for Dancer
8              
9             =head1 SYNOPSIS
10              
11             # 1. Copy the included template files to your dancer application
12             # 2. Change the "layout" parameter in config.yml to "bootstrap3"
13             # 3. Dance On!
14              
15             # Preview the layout
16             plackup -a bin\app.pl
17              
18             =head1 ABSTRACT
19              
20             Template and dummy application that applies the
21             Bootstrap CSS to Dancer.
22              
23             =head1 SUPPORTED FEATURES
24              
25             If you want to show alerts etc., the main
26             template already provides support for that
27             via L.
28              
29             flash success => sprintf "Welcome back, %s",
30             session('user')->{name};
31              
32             ... will produce a nice, green "Welcome back"
33             message for the user.
34              
35             All flash message output is HTML escaped for security reasons.
36              
37             =head1 TEMPLATE FILES IN THIS DISTRIBUTION
38              
39             The meat of this package are the template and Bootstrap and jQuery files.
40             These don't get installed but live in the distribution. You will need to
41             copy the following files and directories into your application
42             directory, at least until L resp. the C application comes
43             with a way to specify default layouts when generating a new application
44             scaffold.
45              
46             You will likely want to use either Bootstrap 2 or Bootstrap 3. See the
47             appropriate list of files to copy.
48              
49             =head2 LIST OF FILES TO COPY
50              
51             =head3 Bootstrap 3
52              
53             public/css/bootstrap-3/bootstrap.css Bootstrap 3
54             public/css/bootstrap-3/bootstrap.min.css Bootstrap 3
55             public/css/fonts/glyphicons-halflings-regular.eot Bootstrap 3
56             public/css/fonts/glyphicons-halflings-regular.svg Bootstrap 3
57             public/css/fonts/glyphicons-halflings-regular.ttf Bootstrap 3
58             public/css/fonts/glyphicons-halflings-regular.woff Bootstrap 3
59             public/css/fonts/glyphicons-halflings-regular.woff2 Bootstrap 3
60             public/javascripts/bootstrap-3/bootstrap.js Bootstrap 3
61             public/javascripts/bootstrap-3/bootstrap.min.js Bootstrap 3
62             public/javascripts/jQuery/jquery-1.11.3.min.js jQuery 1.11.3 (for Bootstrap 3)
63              
64             =head3 Bootstrap 2
65              
66             public/css/bootstrap-responsive.css Bootstrap 2.3.0
67             public/css/bootstrap.css Bootstrap 2.3.0
68             public/css/bootstrap.min.css Bootstrap 2.3.0
69             public/images/glyphicons-halflings-white.png Glyphicons
70             public/images/glyphicons-halflings.png Bootstrap 2.0.3
71             public/javascripts/bootstrap-2.3.0/bootstrap-alert.js Bootstrap 2.3.0
72             public/javascripts/bootstrap-2.3.0/bootstrap.js Bootstrap 2.3.0
73             public/javascripts/bootstrap-2.3.0/bootstrap.min.js Bootstrap 2.3.0
74             public/javascripts/jQuery/jquery-1.7.2.min.js jQuery 1.7.2
75             public/javascripts/jQuery/jquery.ui.widget.js jQuery 1.7.2
76             views/index.tt Index page with Bootstrap layout
77             views/layouts/bootstrap.tt The Bootstrap layout
78              
79             =head1 NEEDED MODULES
80              
81             The simple templating included with Dancer does not properly
82             support user log-in / log out, so the template needs
83             L.
84              
85             =head1 SEE ALSO
86              
87             L - Bootstrap
88              
89             L - Themes for Bootstrap
90              
91             L - Icons from Glyphicons Free, licensed under CC BY 3.0.
92              
93             L - jQuery 1.7.2
94              
95             L - create new colour schemes
96              
97             =cut
98              
99             our $VERSION = '0.03';
100              
101             get '/' => sub {
102             template 'index';
103             };
104              
105             get '/user/login' => sub {
106             template 'login';
107             };
108              
109             post '/user/login' => sub {
110             session user => { name => params->{'name'} };
111              
112             flash success => sprintf "Welcome back, %s",
113             session->{user}->{name};
114            
115             return redirect '/';
116             };
117              
118             get '/user/logout' => sub {
119             my $user= session('user')->{name};
120             session user => undef;
121              
122             flash success => sprintf "Goodbye, %s",
123             $user;
124            
125             redirect '/';
126             };
127              
128             true;