Add a helper for formatting numbers.
This commit is contained in:
parent
c9c248a4b3
commit
74ae6e1745
15
lib/MyApp.pm
15
lib/MyApp.pm
|
@ -1,12 +1,27 @@
|
|||
package MyApp;
|
||||
use Mojo::Base 'Mojolicious', -signatures;
|
||||
|
||||
# Define home-made helpers.
|
||||
sub add_my_helpers ($self) {
|
||||
$self->helper(
|
||||
commify => sub ($self, $number) {
|
||||
my $rev = reverse $number;
|
||||
while ($rev =~ s/(\d{3})(\d)/$1,$2/) {};
|
||||
return scalar reverse $rev;
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
sub startup ($self) {
|
||||
# Set a "secret" for signing cookies, preventing "Your secret
|
||||
# passphrase needs to be changed" in the log, using my_app.yml.
|
||||
my $config = $self->plugin('NotYAMLConfig');
|
||||
$self->secrets([ $config->{secrets} ]);
|
||||
|
||||
# Add home-made helper(s).
|
||||
$self->add_my_helpers;
|
||||
|
||||
# Set routes.
|
||||
my $r = $self->routes;
|
||||
# Home gets an explicit name, else its name is an empty string. A
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<p/>
|
||||
Page <%= $pager->current_page %> of <%= $pager->last_page %>
|
||||
Page <%= commify($pager->current_page) %>
|
||||
of <%= commify($pager->last_page) %>
|
||||
|
||||
|
||||
<%= link_to url_with(page_number => 1) => begin %>◄ First<% end %>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
%= end
|
||||
|
||||
<p/>
|
||||
<%= $pager->total_entries %> authors found.
|
||||
<%= commify($pager->total_entries) %> authors found.
|
||||
|
||||
<p/>
|
||||
<div>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
%= end
|
||||
|
||||
<p/>
|
||||
<%= $pager->total_entries %> books found.
|
||||
<%= commify($pager->total_entries) %> books found.
|
||||
|
||||
<p/>
|
||||
<div>
|
||||
|
|
Loading…
Reference in New Issue