File Coverage

blib/lib/Mojolicious/Plugin/Moai.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition 1 2 50.0
subroutine 3 3 100.0
pod 1 1 100.0
total 18 19 94.7


- Add these classes to every cell in the column
line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::Moai;
2             our $VERSION = '0.003';
3             # ABSTRACT: Mojolicious UI components using modern UI libraries
4              
5             #pod =head1 SYNOPSIS
6             #pod
7             #pod use Mojolicious::Lite;
8             #pod plugin Moai => 'Bootstrap4';
9             #pod app->start;
10             #pod __DATA__
11             #pod @@ list.html.ep
12             #pod %= include 'moai/lib'
13             #pod %= include 'moai/table', items => \@items, columns => [qw( id name )]
14             #pod %= include 'moai/pager', current_page => 1, total_pages => 5
15             #pod
16             #pod =head1 DESCRIPTION
17             #pod
18             #pod This plugin provides some common UI components using a couple different
19             #pod popular UI libraries.
20             #pod
21             #pod These components are designed to integrate seamlessly with L,
22             #pod L, and L.
23             #pod
24             #pod =head1 SUPPORTED LIBRARIES
25             #pod
26             #pod These libraries are not included and the desired version should be added
27             #pod to your layout templates. To add your library using a CDN, see
28             #pod L, below.
29             #pod
30             #pod =head2 Bootstrap4
31             #pod
32             #pod L
33             #pod
34             #pod =head1 WIDGETS
35             #pod
36             #pod Widgets are snippets that you can include in your templates using the
37             #pod L.
38             #pod
39             #pod =head2 moai/pager
40             #pod
41             #pod <%= include 'moai/pager',
42             #pod current_page => param( 'page' ),
43             #pod total_pages => $total_pages,
44             #pod %>
45             #pod
46             #pod A pagination control. Will display previous and next buttons along with
47             #pod individual page buttons.
48             #pod
49             #pod Also comes in a C variant in C that has just
50             #pod previous/next buttons.
51             #pod
52             #pod =head3 Stash
53             #pod
54             #pod =over
55             #pod
56             #pod =item current_page
57             #pod
58             #pod The current page number. Defaults to the value of the C parameter.
59             #pod
60             #pod =item total_pages
61             #pod
62             #pod The total number of pages. Required.
63             #pod
64             #pod =item page_param
65             #pod
66             #pod The name of the parameter to use for the current page. Defaults to C.
67             #pod
68             #pod =item id
69             #pod
70             #pod An ID to add to the pager
71             #pod
72             #pod =back
73             #pod
74             #pod =head2 moai/table
75             #pod
76             #pod <%= include 'moai/table',
77             #pod items => [
78             #pod { id => 1, name => 'Doug' },
79             #pod ],
80             #pod columns => [
81             #pod { key => 'id', title => 'ID' },
82             #pod { key => 'name', title => 'Name' },
83             #pod ],
84             #pod %>
85             #pod
86             #pod A table of items.
87             #pod
88             #pod =head3 Stash
89             #pod
90             #pod =over
91             #pod
92             #pod =item items
93             #pod
94             #pod The items to display in the table. An arrayref of hashrefs.
95             #pod
96             #pod =item columns
97             #pod
98             #pod The columns to display, in order. An arrayref of hashrefs with the following
99             #pod keys:
100             #pod
101             #pod =over
102             #pod
103             #pod =item key
104             #pod
105             #pod The hash key in the item to use.
106             #pod
107             #pod =item title
108             #pod
109             #pod The text to display in the column heading
110             #pod
111             #pod =item link_to
112             #pod
113             #pod Add a link to the given named route. The route will be filled in by the current
114             #pod item, like C<< url_for $link_to => $item >>.
115             #pod
116             #pod =item id
117             #pod
118             #pod An ID to add to the table.
119             #pod
120             #pod =item class
121             #pod
122             #pod A hashref of additional classes to add to certain elements:
123             #pod
124             #pod =over
125             #pod
126             #pod =item * C
127             #pod
128             #pod =back
129             #pod
130             #pod =back
131             #pod
132             #pod =item class
133             #pod
134             #pod A hashref of additional classes to add to certain elements:
135             #pod
136             #pod =over
137             #pod
138             #pod =item * C section, section, and a C section.
139             #pod
140             #pod =item * C
141             #pod
142             #pod =item * C - Add a wrapper element with these classes
143             #pod
144             #pod =back
145             #pod
146             #pod =back
147             #pod
148             #pod =head2 moai/lib
149             #pod
150             #pod %= include 'moai/lib', version => '4.1.0';
151             #pod
152             #pod Add the required stylesheet and JavaScript links for the current library
153             #pod using a CDN. The stylesheets and JavaScript can be added separately
154             #pod using C and C respectively.
155             #pod
156             #pod =head3 Stash
157             #pod
158             #pod =over
159             #pod
160             #pod =item version
161             #pod
162             #pod The specific version of the library to use. Required.
163             #pod
164             #pod =back
165             #pod
166             #pod =head1 TODO
167             #pod
168             #pod =over
169             #pod
170             #pod =item Security
171             #pod
172             #pod The CDN links should have full security hashes.
173             #pod
174             #pod =item Accessibility Testing
175             #pod
176             #pod Accessibility testing should be automated and applied to all supported
177             #pod libraries.
178             #pod
179             #pod =item Internationalization
180             #pod
181             #pod This library should use Mojolicious's C feature to provide
182             #pod translations for every widget in every library.
183             #pod
184             #pod =item Add more widgets
185             #pod
186             #pod There should be widgets for...
187             #pod
188             #pod =over
189             #pod
190             #pod =item * menus (vertical lists, horizontal navbars, dropdown buttons)
191             #pod
192             #pod =item * switched panels (tabs, accordion, slider)
193             #pod
194             #pod =item * alerts (error, warning, info)
195             #pod
196             #pod =item * menus (dropdown button, menu bar)
197             #pod
198             #pod =item * popups (modal dialogs, tooltips, notifications)
199             #pod
200             #pod =item * grid (maybe...)
201             #pod
202             #pod =back
203             #pod
204             #pod =item Add more libraries
205             #pod
206             #pod There should be support for...
207             #pod
208             #pod =over
209             #pod
210             #pod =item * Bootstrap 3
211             #pod
212             #pod =item * Bulma
213             #pod
214             #pod =item * Material
215             #pod
216             #pod =back
217             #pod
218             #pod Moai should support the same features for each library, allowing easy
219             #pod switching between them.
220             #pod
221             #pod =item Add progressive enhancement
222             #pod
223             #pod Some examples of progressive enhancement:
224             #pod
225             #pod =over
226             #pod
227             #pod =item * The table widget could have sortable columns
228             #pod
229             #pod =item * The table widget could use AJAX to to filter and paginate
230             #pod
231             #pod =item * The pager widget could use AJAX to update a linked element
232             #pod
233             #pod =item * The switched panel widgets could load their content lazily
234             #pod
235             #pod =back
236             #pod
237             #pod =item Themes
238             #pod
239             #pod Built-in selection of CDN-based themes for each library
240             #pod
241             #pod =item Layouts
242             #pod
243             #pod A customizable layout with good defaults.
244             #pod
245             #pod =item Extra Classes
246             #pod
247             #pod A standard way of adding extra classes to individual tags inside components. In addition
248             #pod to a string, we should also support a subref so that loops can apply classes to certain
249             #pod elements based on input criteria.
250             #pod
251             #pod =item Documentation Sheet
252             #pod
253             #pod Each supported library should come with a single page that demonstrates the various
254             #pod widgets and provides copy/paste code snippets to achieve that widget.
255             #pod
256             #pod It would be amazing if there was a way to make one template apply to all
257             #pod supported libraries.
258             #pod
259             #pod =item Content section overrides
260             #pod
261             #pod We cannot, should not, must not make every little thing customizable or
262             #pod else our templates will be so complex as to be unmaintainable and
263             #pod unusable. We should instead make content sections that can be extended,
264             #pod like the C template could have a C
265             #pod a C
266             #pod
267             #pod A rule of thumb for adding a feature should be if it can be configured simply by a single
268             #pod string. The more complex the configuration needs to be, the more likely it should be
269             #pod customized using L|Mojolicious::Guides::Rendering/Template inheritance>
270             #pod
271             #pod =back
272             #pod
273             #pod =head1 SEE ALSO
274             #pod
275             #pod L
276             #pod
277             #pod =cut
278              
279 3     3   58685 use Mojo::Base 'Mojolicious::Plugin';
  3         6  
  3         14  
280 3     3   383 use Mojo::File qw( path );
  3         7  
  3         429  
281              
282             sub register {
283 3     3 1 96 my ( $self, $app, $conf ) = @_;
284 3         6 my $library = $conf->[0];
285 3   50     18 $conf = $conf->[1] || {};
286 3         12 my $libdir = path( __FILE__ )->sibling( 'Moai' )->child( 'resources', lc $library );
287 3         329 push @{$app->renderer->paths}, $libdir->child( 'templates' );
  3         9  
288 3         64 return;
289             }
290              
291             1;
292              
293             __END__