File Coverage

blib/lib/Mojolicious/Plugin/BootstrapHelpers.pm
Criterion Covered Total %
statement 57 61 93.4
branch 10 20 50.0
condition 3 14 21.4
subroutine 8 8 100.0
pod 1 2 50.0
total 79 105 75.2


line stmt bran cond sub pod time code
1 14     14   12921 use 5.20.0;
  14         78  
2 14     14   56 use warnings;
  14         18  
  14         1022  
3              
4             package Mojolicious::Plugin::BootstrapHelpers;
5              
6             # ABSTRACT: Type less bootstrap
7             our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
8             our $VERSION = '0.0204';
9              
10 14     14   59 use Mojo::Base 'Mojolicious::Plugin';
  14         16  
  14         96  
11 14     14   8920 use Mojolicious::Plugin::BootstrapHelpers::Helpers;
  14         27  
  14         450  
12 14     14   65 use experimental qw/postderef signatures/;
  14         17  
  14         50  
13              
14 14 50   14 1 617 sub register($self, $app, $args) {
  14 50       40  
  14         20  
  14         17  
  14         16  
  14         16  
15              
16 14 50       63 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       227 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         48 my $tp = setup_prefix($args->{'tag_prefix'});
25 14         45 my $ssp = setup_prefix($args->{'shortcut_prefix'});
26 14   50     87 my $init_shortcuts = $args->{'init_shortcuts'} //= 1;
27              
28 14         122 $app->helper($tp.'bootstrap' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstraps_bootstraps);
29 14         427 $app->helper($tp.'table' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_table);
30 14         144 $app->helper($tp.'panel' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_panel);
31 14         176 $app->helper($tp.'formgroup' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_formgroup);
32 14         133 $app->helper($tp.'button' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_button);
33 14         126 $app->helper($tp.'submit_button' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_submit);
34 14         133 $app->helper($tp.'badge' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_badge);
35 14         127 $app->helper($tp.'context_menu' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_context_menu);
36 14         124 $app->helper($tp.'dropdown' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_dropdown);
37 14         126 $app->helper($tp.'buttongroup' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_buttongroup);
38 14         120 $app->helper($tp.'toolbar' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_toolbar);
39 14         118 $app->helper($tp.'input' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_input);
40 14         119 $app->helper($tp.'navbar' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_navbar);
41 14         117 $app->helper($tp.'nav' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_nav);
42              
43 14 50 33     165 if(exists $args->{'icons'}{'class'} && $args->{'icons'}{'formatter'}) {
44 14         112 $app->config->{'Plugin::BootstrapHelpers'} = $args;
45 14         194 $app->helper($tp.'icon' => \&Mojolicious::Plugin::BootstrapHelpers::Helpers::bootstrap_icon);
46             }
47              
48 14 50       151 if($init_shortcuts) {
49 14         29 my @sizes = qw/xsmall small medium large/;
50 14         24 my @contexts = qw/default active primary success info warning danger/;
51 14         23 my @table = qw/striped bordered hover condensed responsive/;
52 14         24 my @direction = qw/right left block vertical justified dropup/;
53 14         18 my @menu = qw/caret hamburger/;
54 14         18 my @misc = qw/disabled inverse/;
55              
56 14         27 foreach my $helper (@sizes, @contexts, @table, @direction, @menu, @misc) {
57 364     75   3637 $app->helper($ssp.$helper, sub { ("__$helper" => 1) });
  75         364241  
58             }
59             }
60             }
61              
62 28 50   28 0 58 sub setup_prefix($prefix) {
  28 50       52  
  28         44  
  28         20  
63 28 50 33     112 return defined $prefix && !length $prefix ? '_'
    50          
64             : defined $prefix ? $prefix
65             : ''
66             ;
67             }
68              
69             1;
70              
71             __END__