Mojolicious::Plugin::Moai - Mojolicious UI components using modern UI libraries
version 0.003
use Mojolicious::Lite; plugin Moai => 'Bootstrap4'; app->start; __DATA__ @@ list.html.ep %= include 'moai/lib' %= include 'moai/table', items => \@items, columns => [qw( id name )] %= include 'moai/pager', current_page => 1, total_pages => 5
This plugin provides some common UI components using a couple different popular UI libraries.
These components are designed to integrate seamlessly with Yancy, Mojolicious::Plugin::DBIC, and Mojolicious::Plugin::SQL.
These libraries are not included and the desired version should be added to your layout templates. To add your library using a CDN, see "moai/lib", below.
http://getbootstrap.com
Widgets are snippets that you can include in your templates using the include helper.
<%= include 'moai/pager', current_page => param( 'page' ), total_pages => $total_pages, %>
A pagination control. Will display previous and next buttons along with individual page buttons.
Also comes in a mini variant in moai/pager/mini that has just previous/next buttons.
mini
moai/pager/mini
The current page number. Defaults to the value of the page parameter.
page
The total number of pages. Required.
The name of the parameter to use for the current page. Defaults to page.
An ID to add to the pager
<%= include 'moai/table', items => [ { id => 1, name => 'Doug' }, ], columns => [ { key => 'id', title => 'ID' }, { key => 'name', title => 'Name' }, ], %>
A table of items.
The items to display in the table. An arrayref of hashrefs.
The columns to display, in order. An arrayref of hashrefs with the following keys:
The hash key in the item to use.
The text to display in the column heading
Add a link to the given named route. The route will be filled in by the current item, like url_for $link_to => $item.
url_for $link_to => $item
An ID to add to the table.
A hashref of additional classes to add to certain elements:
col - Add these classes to every cell in the column
col
table
thead
wrapper - Add a wrapper element with these classes
wrapper
%= include 'moai/lib', version => '4.1.0';
Add the required stylesheet and JavaScript links for the current library using a CDN. The stylesheets and JavaScript can be added separately using moai/lib/stylesheet and moai/lib/javascript respectively.
moai/lib/stylesheet
moai/lib/javascript
The specific version of the library to use. Required.
The CDN links should have full security hashes.
Accessibility testing should be automated and applied to all supported libraries.
This library should use Mojolicious's variant feature to provide translations for every widget in every library.
variant
There should be widgets for...
menus (vertical lists, horizontal navbars, dropdown buttons)
switched panels (tabs, accordion, slider)
alerts (error, warning, info)
menus (dropdown button, menu bar)
popups (modal dialogs, tooltips, notifications)
grid (maybe...)
There should be support for...
Bootstrap 3
Bulma
Material
Moai should support the same features for each library, allowing easy switching between them.
Some examples of progressive enhancement:
The table widget could have sortable columns
The table widget could use AJAX to to filter and paginate
The pager widget could use AJAX to update a linked element
The switched panel widgets could load their content lazily
Built-in selection of CDN-based themes for each library
A customizable layout with good defaults.
A standard way of adding extra classes to individual tags inside components. In addition to a string, we should also support a subref so that loops can apply classes to certain elements based on input criteria.
Each supported library should come with a single page that demonstrates the various widgets and provides copy/paste code snippets to achieve that widget.
It would be amazing if there was a way to make one template apply to all supported libraries.
We cannot, should not, must not make every little thing customizable or else our templates will be so complex as to be unmaintainable and unusable. We should instead make content sections that can be extended, like the moai/table template could have a thead section, a tbody section, and a tbody.tr section.
moai/table
tbody
tbody.tr
A rule of thumb for adding a feature should be if it can be configured simply by a single string. The more complex the configuration needs to be, the more likely it should be customized using Mojolicious's template extends
extends
Mojolicious::Guides::Rendering
Doug Bell <preaction@cpan.org>
This software is copyright (c) 2019 by Doug Bell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Mojolicious::Plugin::Moai, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::Moai
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::Moai
For more information on module installation, please visit the detailed CPAN module installation guide.