diff --git a/lib/LDV.pm b/lib/LDV.pm index a33d013..6fb5df8 100644 --- a/lib/LDV.pm +++ b/lib/LDV.pm @@ -9,9 +9,10 @@ use Mojo::Base 'Mojolicious'; sub startup { my ($self) = @_; - $self->plugin(I18N => {default => 'ru'}); my $config = $self->app->home->rel_file('conf/ldv.conf'); $self->plugin(Config => {file => $config}); + $self->plugin(I18N => {default => 'ru'}); + $self->plugin('LDV::Helpers'); $self->app->mode('production'); $self->app->secrets([ $self->app->config->{secret} ]); diff --git a/lib/LDV/Helpers.pm b/lib/LDV/Helpers.pm new file mode 100644 index 0000000..3caa677 --- /dev/null +++ b/lib/LDV/Helpers.pm @@ -0,0 +1,27 @@ +package LDV::Helpers; + +use strict; +use warnings; +use utf8; + +use Mojo::Base 'Mojolicious::Plugin'; + +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; + }); +} + +1;