NAME
Mojolicious::Plugin::BootstrapHelpers - Type less bootstrap
SYNOPSIS
# Mojolicious
$self->plugin('BootstrapHelpers');
# ::Lite
plugin 'BootstrapHelpers';
# Meanwhile, somewhere in a template...
%= formgroup 'Email', text_field => ['email'], large, cols => { small => [3, 9] }
# ...that renders into
STATUS
This is an unstable work in progress. Backwards compatibility is
currently not to be expected between releases.
Currently supported Bootstrap version: 3.2.0.
Currently only Perl 5.20+ is supported (thanks to postderef).
DESCRIPTION
Mojolicious::Plugin::BootstrapHelpers is a convenience plugin that
reduces some bootstrap complexity by introducing several tag helpers
specifically for Bootstrap 3 .
The goal is not to have tag helpers for everything, but for common use
cases.
All examples below (and more, see tests) is expected to work.
How to use Bootstrap
If you don't know what Bootstrap is, see
for possible usages.
You might want to use Mojolicious::Plugin::Bootstrap3 in your templates.
To get going quickly by using the official CDN you can use the following
helpers:
# CSS
%= bootstrap
# or (if you want to use the theme)
%= bootstrap 'theme'
# And the javascript
%= bootstrap 'js'
# Or just:
%= bootstrap 'all'
It is also possible to automatically include jQuery (2.*)
%= bootstrap 'jsq'
%= bootstrap 'allq'
Strappings
There are several shortcuts ("strappings") for applying context and size
classes that automatically expands to the correct class depending on
which tag it is applied to. For instance, if you apply the "info"
strapping to a panel, it becomes "panel-info", but when applied to a
button it becomes "btn-info".
You can use them in two different ways, but internally they are the
same. These to lines are exactly identical:
%= button 'Push me', primary
%= button 'Push me', __primary => 1
For sizes, you can only use the longform ("xsmall", "small", "medium"
and "large") no matter if you use the short strapping form or not. They
are shortened to the Bootstrap type classes.
The following strappings are available:
xsmall default striped caret right
small primary bordered
medium success hover
large info condensed
warning responsive
danger
Add two leading underscores if you don't want to use the short form.
See below for usage. Important: You can't follow a short form strapping
with a fat comma ("=>"). The fat comma auto-quotes the strapping, and
then it breaks.
If there is no corresponding class for the element you add the strapping
to it is silently not applied.
Syntax convention
In the syntax sections below the following conventions are used:
name A specific string
$name Any string
%name One or more key-value pairs, written as:
key => 'value', key2 => 'value2'
or, if you use short form strappings:
primary, large
$key => [...] Both of these are array references where the ordering of strings
key => [...] are significant, for example:
key => [ $thing, $thing2, %hash ]
$key => {...} Both of these are hash references where the ordering of pairs are
key => {...} are insignificant, for example:
key => { key2 => $value, key3 => 'othervalue' }
(...) Anything between parenthesis is optional. The parenthesis is not part of the
actual syntax
|...| Two pipes is a reference to another specification. For instance, button toolbars contain
button groups that contain buttons. Using this syntax makes the important parts clearer.
The pipes are not part of the actual syntax.
Ordering between two hashes that follows each other is also not
significant.
About %has
The following applies to all %has hashes below:
* They refer to any html attributes and/or strappings to apply to the
current element.
* When helpers are nested, all occurrencies are change to tag-specific
names, such as %panel_has.
* This hash is always optional. It is not marked so in the definitions
below in order to reduce clutter.
* Depending on context either the leading or following comma is
optional together with the hash. It is usually obvious.
* Sometimes on nested helpers (such as tables in panels just below),
%has is the only thing that can be applied to the other element. In
this case "panel => { %panel_has }". It follows from above that in
those cases this entire expression is *also* optional. Such cases
are also not marked as optional in syntax definitions and are not
mentioned in syntax description, unless they need further comment.
From this definition:
%= table ($title,) %table_has, panel => { %panel_has }, begin
$body
% end
Both of these are legal:
# since both panel => { %panel_has } and %table_has are hashes, their ordering is not significant.
%= table 'Heading Table', panel => { success }, condensed, id => 'the-table', begin
<%= badge '4', data => { custom => 'yes' }, right %>
4
Buttons
Bootstrap documentation
Syntax
%= button $button_text(, [$url]), %has
%= submit_button $text, %has
$button_text
Mandatory. The text on the button.
"[$url]"
Optional array reference. It is handed off to url_for, so with it this
is basically link_to with Bootstrap classes.
Not available for "submit_button".
Available strappings
"default" "primary" "success" "info" "warning" "danger" "link" applies
the various ".btn-*" classes.
"large" "small" "xsmall" applies ".btn-lg" ".btn-sm" ".btn-xs"
respectively.
"active" "block" applies the ".active" and ".block" classes.
"disabled" applies the ".disabled" class if the generated element is an
"". On a "