Add a footer with the version number
authorVincent Tondellier <tonton+hg@team1664.org>
Sun, 18 Dec 2016 22:17:10 +0100
changeset 124 12da024402d2
parent 123 56f9cb30ded9
child 125 c019ceb604a4
Add a footer with the version number
lib/CrashTest.pm
lib/CrashTest/Helper/Version.pm
lib/CrashTest/files/templates/layouts/main.html.ep
--- a/lib/CrashTest.pm	Sun Dec 18 21:53:46 2016 +0100
+++ b/lib/CrashTest.pm	Sun Dec 18 22:17:10 2016 +0100
@@ -46,7 +46,7 @@
     $self->plugin("CrashTest::Helper::XmlEscape");
     $self->plugin("CrashTest::Helper::Stats");
     $self->plugin("CrashTest::Helper::BugLinks", $self->config->{WebInterface}->{BugTrackerLinks});
-
+    $self->plugin("CrashTest::Helper::Version");
 
     $self->helper(crash_reports     => sub { state $crash_reports   = CrashTest::Model::CrashReport->new    (app => $self); });
     $self->helper(crash_groups      => sub { state $crash_groups    = CrashTest::Model::CrashGroup->new     (app => $self); });
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/CrashTest/Helper/Version.pm	Sun Dec 18 22:17:10 2016 +0100
@@ -0,0 +1,47 @@
+# 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::Version;
+
+use Mojo::Base 'Mojolicious::Plugin';
+use FindBin;
+
+sub register {
+    my ($self, $mojo, $params) = @_;
+
+    $mojo->helper(crashtest_version => sub { state $version = $self->_version(@_); });
+}
+
+sub _version {
+    my ($self, $c) = @_;
+
+    # release version
+    if($CrashTest::Helper::Version::VERSION) {
+        return $CrashTest::Helper::Version::VERSION;
+    }
+
+    # calling hg is slow, avoid in dev mode
+    if($c->app->mode eq 'development') {
+        return "devel";
+    }
+
+    # production on a checkout
+    if(-d "$FindBin::Bin/../.hg") {
+        return "rev hg." . qx<hg id>;
+    }
+
+    return "";
+}
+
+1;
+
--- a/lib/CrashTest/files/templates/layouts/main.html.ep	Sun Dec 18 21:53:46 2016 +0100
+++ b/lib/CrashTest/files/templates/layouts/main.html.ep	Sun Dec 18 22:17:10 2016 +0100
@@ -23,6 +23,11 @@
       %= include("layouts/_messages")
 
       <%= content %>
+
+      <hr class="clearfix" />
+      <footer>
+        <p class="text-center text-muted">Powered by CrashTest <%= crashtest_version %></p>
+      </footer>
     </div>
     % if ( $self->app->mode eq 'development'){
     %= javascript '/assets/js/jquery.js'