blob: f0115ae0d446ca7311fe3b544b3fca617cc4118c [file] [log] [blame]
Nils Diewald5d1ffb42014-05-21 17:45:34 +00001package Korap;
2use Mojo::Base 'Mojolicious';
3
Nils Diewald7cad8402014-07-08 17:06:56 +00004our $VERSION = '0.04';
5
6# Start dev with
7# morbo -w lib -w templates -w public/sass -w public/js script/korap
Nils Diewald64bab252014-05-22 11:04:04 +00008
Nils Diewald002e8fb2014-06-22 14:27:01 +00009# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +000010sub startup {
11 my $self = shift;
12
Nils Diewald7cad8402014-07-08 17:06:56 +000013 $self->defaults(layout => 'default');
14
Nils Diewald002e8fb2014-06-22 14:27:01 +000015 # Set secret for signed cookies
Nils Diewald33e15552014-06-13 19:38:37 +000016 $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']);
17
Nils Diewald002e8fb2014-06-22 14:27:01 +000018 # Add additional plugin path
Nils Diewald5d1ffb42014-05-21 17:45:34 +000019 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
Nils Diewald002e8fb2014-06-22 14:27:01 +000020
21 # Load plugins
22 foreach (qw/Config
23 CHI
24 TagHelpers::Pagination
25 Notifications
26 Number::Commify
27 KorapSearch
28 KorapInfo
Nils Diewald7cad8402014-07-08 17:06:56 +000029 KorapTagHelpers
30 /) {
Nils Diewald002e8fb2014-06-22 14:27:01 +000031 $self->plugin($_);
32 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000033
Nils Diewald7cad8402014-07-08 17:06:56 +000034 $self->plugin(AssetPack => {
35 minify => 1
36 });
37
38 $self->plugin('AssetPack::LibSass');
39
40 $self->asset(
41 'korap.css' => (
42 '/sass/style.scss',
43 '/sass/sidebar.scss',
44 '/sass/tutorial.scss',
45 '/sass/hint.scss',
46 '/sass/query.scss',
47 '/sass/table.scss',
48 '/sass/pagination.scss',
49 '/sass/kwic-4.0.scss',
50 '/css/media.css',
51 '/css/font-awesome.min.css',
52 '/css/highlight.css'
53 )
54 );
55
56 $self->asset(
57 'korap.js' => (
58 '/js/jquery-2.0.0.min.js',
59 '/js/translateTable.js',
60 '/js/hint.js',
61 '/js/highlight.pack.js'
62 )
63 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000064
Nils Diewald2329e1d2014-06-12 16:07:57 +000065 $self->helper(
66 date_format => sub {
67 my ($c, $date) = @_;
68 return $date;
69 }
70 );
71
Nils Diewald64bab252014-05-22 11:04:04 +000072 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000073 my $r = $self->routes;
74
Nils Diewald002e8fb2014-06-22 14:27:01 +000075 # Base search route
Nils Diewaldb22abdf2014-06-18 22:57:50 +000076 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000077
Nils Diewald002e8fb2014-06-22 14:27:01 +000078 # Tutorial data
79 $r->get('/tutorial/(*tutorial)', { tutorial => 'start' })
80 ->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +000081
Nils Diewald002e8fb2014-06-22 14:27:01 +000082 # Collection data
Nils Diewald7cad8402014-07-08 17:06:56 +000083 my $collection = $r->bridge('/collection');
84 $collection->to('info#about_collection');
85 my $collection_id = $collection->bridge('/:collection_id');
86 # stats
87 # $collection_id->;
88 $collection_id->search;
Nils Diewald1eba6572014-06-17 19:49:53 +000089
Nils Diewald002e8fb2014-06-22 14:27:01 +000090 # Corpus data
Nils Diewald7cad8402014-07-08 17:06:56 +000091 my $corpus_res = $r->route('/corpus');
92 my $corpus = $corpus_res->route('/:corpus_id');
93 # Todo: Stats
94 $corpus->search->name('search_corpus');
95 my $doc = $corpus->route('/#doc_id');
96 $doc->search->name('search_document');
97
98 # Match data
99 my $match = $doc->route('/:match_id');
100 $match->route->to('info#about_match')->name('match');
101 my $match_layer = $match->route('/:layer');
102 $match_layer->route->to('info#about_match');
103 $match_layer->route('/:foundry')->to('info#about_match');
Nils Diewald1eba6572014-06-17 19:49:53 +0000104
Nils Diewald002e8fb2014-06-22 14:27:01 +0000105 # Utilities
Nils Diewald7cad8402014-07-08 17:06:56 +0000106 # $r->get('/util/query')->to('search#query');
Nils Diewald64bab252014-05-22 11:04:04 +0000107};
108
Nils Diewald5d1ffb42014-05-21 17:45:34 +0000109
1101;