File Coverage

blib/lib/Mojolicious/Plugin/BootstrapHelpers.pm
Criterion Covered Total %
statement 55 59 93.2
branch 6 12 50.0
condition 3 14 21.4
subroutine 8 8 100.0
pod 1 2 50.0
total 73 95 76.8


line stmt bran cond sub pod time code
1 14     14   12090 use 5.20.0;
  14         96  
2 14     14   79 use warnings;
  14         33  
  14         897  
3              
4             package Mojolicious::Plugin::BootstrapHelpers;
5              
6             # ABSTRACT: Type less bootstrap
7             our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
8             our $VERSION = '0.0205';
9              
10 14     14   91 use Mojo::Base 'Mojolicious::Plugin';
  14         30  
  14         112  
11 14     14   10630 use Mojolicious::Plugin::BootstrapHelpers::Helpers;
  14         46  
  14         563  
12 14     14   106 use experimental qw/postderef signatures/;
  14         32  
  14         69  
13              
14 14     14 1 721 sub register($self, $app, $args) {
  14         38  
  14         28  
  14         28  
  14         27  
15              
16 14 50       64 if(exists $args->{'short_strappings_prefix'}) {
17 0         0 $app->log->debug("'short_strappings_prefix' is deprecated. Use 'shortcut_prefix' instead");
18 0   0     0 $args->{'shortcut_prefix'} //= $args->{'short_strappings_prefix'};
19             }
20 14 50       56 if(exists $args->{'init_short_strappings'}) {
21 0         0 $app->log->debug("'init_short_strappings' is deprecated. Use 'init_shortcuts' instead");
22 0   0     0 $args->{'init_shortcuts'} //= $args->{'init_short_strappings'};
23             }
24 14         55 my $tp = setup_prefix($args->{'tag_prefix'});
25 14         58 my $ssp = setup_prefix($args->{'shortcut_prefix'});
26 14   50     95 my $init_shortcuts = $args->{'init_shortcuts'} //= 1;
27              
28 14         190 $app->helper($tp.'bootstrap' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstraps_bootstraps);
29 14         2113 $app->helper($tp.'table' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_table);
30 14         1249 $app->helper($tp.'panel' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_panel);
31 14         1160 $app->helper($tp.'formgroup' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_formgroup);
32 14         1176 $app->helper($tp.'button' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_button);
33 14         1136 $app->helper($tp.'submit_button' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_submit);
34 14         649 $app->helper($tp.'badge' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_badge);
35 14         1192 $app->helper($tp.'context_menu' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_context_menu);
36 14         1282 $app->helper($tp.'dropdown' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_dropdown);
37 14         1178 $app->helper($tp.'buttongroup' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_buttongroup);
38 14         1177 $app->helper($tp.'toolbar' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_toolbar);
39 14         1426 $app->helper($tp.'input' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_input);
40 14         1276 $app->helper($tp.'navbar' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_navbar);
41 14         1196 $app->helper($tp.'nav' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_nav);
42              
43 14 50 33     1216 if(exists $args->{'icons'}{'class'} && $args->{'icons'}{'formatter'}) {
44 14         130 $app->config->{'Plugin::BootstrapHelpers'} = $args;
45 14         273 $app->helper($tp.'icon' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_icon);
46             }
47              
48 14 50       1380 if($init_shortcuts) {
49 14         59 my @sizes = qw/xsmall small medium large/;
50 14         62 my @contexts = qw/default active primary success info warning danger/;
51 14         44 my @table = qw/striped bordered hover condensed responsive/;
52 14         38 my @direction = qw/right left block vertical justified dropup/;
53 14         31 my @menu = qw/caret hamburger/;
54 14         33 my @misc = qw/disabled inverse/;
55              
56 14         38 foreach my $helper (@sizes, @contexts, @table, @direction, @menu, @misc) {
57 364     75   33332 $app->helper($ssp.$helper, sub { ("__$helper" => 1) });
  75         592883  
58             }
59             }
60             }
61              
62 28     28 0 55 sub setup_prefix($prefix) {
  28         71  
  28         48  
63 28 50 33     134 return defined $prefix && !length $prefix ? '_'
    50          
64             : defined $prefix ? $prefix
65             : ''
66             ;
67             }
68              
69             1;
70              
71             __END__