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   2064 use Dancer ':syntax';
  1         327299  
  1         7  
3 1     1   1539 use Dancer::Plugin::FlashMessage;
  1         4335  
  1         358  
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 "bootstrap"
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             =head2 LIST OF FILES TO COPY
47              
48             public/css/bootstrap-responsive.css Bootstrap 2.3.0
49             public/css/bootstrap.css Bootstrap 2.3.0
50             public/css/bootstrap.min.css Bootstrap 2.3.0
51             public/images/glyphicons-halflings-white.png Glyphicons
52             public/images/glyphicons-halflings.png Bootstrap 2.0.3
53             public/javascripts/bootstrap-2.3.0/bootstrap-alert.js Bootstrap 2.3.0
54             public/javascripts/bootstrap-2.3.0/bootstrap.js Bootstrap 2.3.0
55             public/javascripts/bootstrap-2.3.0/bootstrap.min.js Bootstrap 2.3.0
56             public/javascripts/jQuery/jquery-1.7.2.min.js jQuery 1.7.2
57             public/javascripts/jQuery/jquery.ui.widget.js jQuery 1.7.2
58             views/index.tt Index page with Bootstrap layout
59             views/layouts/bootstrap.tt The Bootstrap layout
60              
61             =head1 NEEDED MODULES
62              
63             The simple templating included with Dancer does not properly
64             support user log-in / log out, so the template needs
65             L.
66              
67             =head1 SEE ALSO
68              
69             L - Bootstrap
70              
71             L - Themes for Bootstrap
72              
73             L - Icons from Glyphicons Free, licensed under CC BY 3.0.
74              
75             L - jQuery 1.7.2
76              
77             L - create new colour schemes
78              
79             =cut
80              
81             our $VERSION = '0.02';
82              
83             get '/' => sub {
84             template 'index';
85             };
86              
87             get '/user/login' => sub {
88             template 'login';
89             };
90              
91             post '/user/login' => sub {
92             session user => { name => params->{'name'} };
93              
94             flash success => sprintf "Welcome back, %s",
95             session->{user}->{name};
96            
97             return redirect '/';
98             };
99              
100             get '/user/logout' => sub {
101             my $user= session('user')->{name};
102             session user => undef;
103              
104             flash success => sprintf "Goodbye, %s",
105             $user;
106            
107             redirect '/';
108             };
109              
110             true;