| package Korap; |
| use Mojo::Base 'Mojolicious'; |
| |
| our $VERSION = '0.01'; |
| |
| # This method will run once at server start |
| sub startup { |
| my $self = shift; |
| |
| $self->plugin('Config'); |
| $self->plugin('CHI'); |
| $self->plugin('TagHelpers::Pagination' => { |
| prev => '<span><i class="fa fa-caret-left"></i></span>', |
| next => '<span><i class="fa fa-caret-right"></i></span>', |
| ellipsis => '<span><i class="fa fa-ellipsis-h"></i></span>', |
| separator => '', |
| current => '<span>{current}</span>', |
| page => '<span>{page}</span>' |
| }); |
| $self->plugin('Notifications'); |
| $self->plugin('Number::Commify'); |
| push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
| $self->plugin('KorapSearch'); |
| $self->plugin('KorapInfo'); |
| $self->plugin('KorapTagHelpers'); |
| |
| $self->helper( |
| date_format => sub { |
| my ($c, $date) = @_; |
| return $date; |
| } |
| ); |
| |
| # TODO: Write search snippet |
| |
| # Routes |
| my $r = $self->routes; |
| |
| # Create search endpoint |
| $r->add_shortcut( |
| search => sub { |
| shift->get('/search')->to('search#remote') |
| } |
| ); |
| |
| $r->get('/')->to( |
| cb => sub { |
| my $c = shift; |
| $c->render( |
| text => |
| 'Go to '. |
| $c->link_to('search', '/collection/search')); |
| } |
| ); |
| |
| # Tutorial |
| $r->get('/tutorial')->to('tutorial#page')->name('tutorial'); |
| $r->get('/tutorial/(*tutorial)')->to('tutorial#page'); |
| |
| $r->get('/util/query')->to('search#query'); |
| |
| $r->get('/:resource' => [qw/collection corpus/])->to('search#info'); |
| |
| # resource => [qw/collection corpus/] |
| $r->get('/:resource')->search; |
| $r->get('/:resource/:cid', resource => [qw/collection corpus/])->search; |
| $r->get('/:resource/')->search; |
| # /matchInfo?id=...&f=&l=&spans |
| |
| }; |
| |
| |
| 1; |