package LDV::Helpers; use strict; use warnings; use utf8; use Mojo::Base 'Mojolicious::Plugin'; use POSIX qw(strftime); use Text::Markdown; sub register { my ($self, $app) = @_; $app->helper(markdown => sub { my ($c, $text) = @_; my $render = Text::Markdown->new; return $render->markdown($text); }); $app->helper(plaintext => sub { my ($c, $text) = @_; $text =~ s{\r?\n}{
}go; return $text; }); $app->helper(from_unixtime => sub { my ($c, $unixtime) = @_; return strftime("%Y-%m-%d %H:%M", localtime($unixtime)); }); $app->helper(access_allowed => sub { my ($c, $level) = @_; $level //= ''; if ($level eq 'user' and not $c->session('useruid')) { $c->redirect_to('/user/eaccess'); return; } return 1; }); } 1;