lib/CrashTest/Helper/Stats.pm
changeset 88 c82f5589db11
child 122 8692800ec9ba
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/CrashTest/Helper/Stats.pm	Mon Dec 28 23:08:23 2015 +0100
@@ -0,0 +1,39 @@
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package CrashTest::Helper::Stats;
+use Mojo::Base 'Mojolicious::Plugin';
+use Mojo::ByteStream qw/b/;
+
+sub register {
+    my ($self, $app, $conf) = @_;
+
+    $app->helper(stats_bar => sub { $self->_stats_bar(@_) } );
+}
+
+sub _stats_bar {
+  my ($self, $c, $val, $max) = @_;
+  my $pct = sprintf("%.2f", $val / $max * 100.0);
+
+    return b(
+<<EOF
+<div class="progress stats">
+  <div class="progress-bar" role="progressbar" aria-valuenow="$val" aria-valuemin="0" aria-valuemax="$max" style="min-width: 2em; width: $pct%;">
+    $val
+  </div>
+</div>
+EOF
+);
+}
+
+1;