Cleanup testbed
diff --git a/lib/Korap.pm b/lib/Korap.pm
index 5d2cde0..fddb9b4 100644
--- a/lib/Korap.pm
+++ b/lib/Korap.pm
@@ -1,6 +1,8 @@
package Korap;
use Mojo::Base 'Mojolicious';
+our $VERSION = '0.01';
+
# This method will run once at server start
sub startup {
my $self = shift;
@@ -27,8 +29,7 @@
}
);
-
- # Router
+ # Routes
my $r = $self->routes;
$r->add_shortcut(
@@ -37,12 +38,19 @@
}
);
-# , resource => [qw/collection corpus/]
+ $r->get('/')->to(
+ cb => sub {
+ my $c = shift;
+ $c->render('text' => 'Go to '. $c->link_to('search', '/collection/search'));
+ }
+ );
+
+ # 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;
diff --git a/lib/Korap/Example.pm b/lib/Korap/Example.pm
deleted file mode 100644
index 58fbd8b..0000000
--- a/lib/Korap/Example.pm
+++ /dev/null
@@ -1,12 +0,0 @@
-package Korap::Example;
-use Mojo::Base 'Mojolicious::Controller';
-
-# This action will render a template
-sub welcome {
- my $self = shift;
-
- # Render template "example/welcome.html.ep" with message
- $self->render(msg => 'Welcome to the Mojolicious real-time web framework!');
-}
-
-1;
diff --git a/lib/Korap/Plugin/KorapSearch.pm b/lib/Korap/Plugin/KorapSearch.pm
index 0245e5d..343e50d 100644
--- a/lib/Korap/Plugin/KorapSearch.pm
+++ b/lib/Korap/Plugin/KorapSearch.pm
@@ -2,6 +2,8 @@
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::ByteStream 'b';
+# TODO: This will probably be an engine for M::P::Search
+
sub register {
my ($plugin, $mojo, $param) = @_;
$param ||= {};
@@ -73,14 +75,18 @@
my $ua = Mojo::UserAgent->new($url);
$c->app->log->debug($url->to_string);
+
+ # Blocking request
+ # TODO: Make non-blocking
my $tx = $ua->get($url);
+ # Request successful
if (my $res = $tx->success) {
my $json = $res->json;
- my $b_hit = $json->{benchmarkHitCounter};
+ # Reformat benchmark counter
+ my $b_hit = $json->{benchmarkHitCounter};
my $b_search = $json->{benchmarkSearchResults};
-
if ($b_hit =~ s/\s+(m)?s$//) {
$b_hit = sprintf("%.2f", $b_hit) . ($1 ? $1 : '') . 's';
};
@@ -88,21 +94,30 @@
$b_search = sprintf("%.2f", $b_search) . ($1 ? $1 : '') . 's';
};
- $c->stash('search.bm.hit' => $b_hit);
- $c->stash('search.bm.result' => $b_search);
- $c->stash('search.itemsPerPage' => $json->{itemsPerPage});
+ for ($c->stash) {
+ $_->{'search.bm.hit'} = $b_hit;
+ $_->{'search.bm.result'} = $b_search;
+ $_->{'search.itemsPerPage'} = $json->{itemsPerPage};
+ $_->{'search.query'} = $json->{request}->{query};
+ $_->{'search.hits'} = $json->{matches};
+ $_->{'search.totalResults'} = $json->{totalResults};
+ };
+
if ($json->{error}) {
$c->notify('error' => $json->{error});
};
- $c->stash('search.query' => $json->{request}->{query});
- $c->stash('search.hits' => $json->{matches});
- $c->stash('search.totalResults' => $json->{totalResults});
}
+
+ # Request failed
else {
my $res = $tx->res;
$c->notify('error' => $res->code . ': ' . $res->message);
};
+
+ # Run embedded template
my $v = $cb->();
+
+ # Delete useless stash keys
foreach (qw/hits totalResults bm.hit bm.result itemsPerPage error query/) {
delete $c->stash->{'search.' . $_};
};
@@ -110,6 +125,8 @@
}
);
+
+ # Establish 'search_hits' helper
$mojo->helper(
search_hits => sub {
my $c = shift;
@@ -122,15 +139,20 @@
my $hits = delete $c->stash->{'search.hits'};
my $string;
+
+ # Iterate over all hits
foreach (@$hits) {
local $_ = $_;
$c->stash('search.hit' => $_);
$string .= $cb->($_);
};
- delete $c->stash->{'lucy.hit'};
+
+ # Delete unnecessary stash values
+ delete $c->stash->{'search.hit'};
return b($string || '');
}
);
};
+
1;
diff --git a/lib/Korap/Plugin/Notifications.pm b/lib/Korap/Plugin/Notifications.pm
index c07df47..af1833b 100644
--- a/lib/Korap/Plugin/Notifications.pm
+++ b/lib/Korap/Plugin/Notifications.pm
@@ -4,6 +4,9 @@
our $TYPE_RE = qr/^[-a-zA-Z_]+$/;
+# This will be separated published as Mojolicious::Plugin::Notifications
+# (wasn't exclusively developed for KorAP)
+
# Todo: Support multiple notification center,
# so the notifications can be part of
# json as well as XML
@@ -21,7 +24,9 @@
my $debug = $mojo->mode eq 'development' ? 1 : 0;
- my $center = camelize(delete $param->{use} // __PACKAGE__ . '::HTML');
+ my $center = camelize(
+ delete $param->{use} // __PACKAGE__ . '::HTML'
+ );
if (index($center,'::') < 0) {
$center = __PACKAGE__ . '::' . $center;
@@ -111,26 +116,3 @@
The notification won't be included in case no notifications are
in the queue and no parameters are passed.
-
-
-
-% if (flash('fine') || flash('alert') || stash('fine') || stash('alert')) {
-%= javascript '/js/humane.min.js'
-%= javascript begin
- humane.baseCls = 'humane-libnotify';
-% if (flash('fine') || stash('fine')) {
- humane.log("<%= l(flash('fine') || stash('fine')) %>", {
- timeout: 3000,
- clickToClose: true,
- addnCls: 'humane-libnotify-success'
- });
-% };
-% if (flash('alert') || stash('alert')) {
- humane.log("<%= l(flash('alert') || stash('alert')) %>", {
- timeout: 3000,
- clickToClose: true,
- addnCls: 'humane-libnotify-error'
- });
-% };
-%= end
-% };
diff --git a/public/index.html b/public/index.html
deleted file mode 100644
index e74bb5f..0000000
--- a/public/index.html
+++ /dev/null
@@ -1,11 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Welcome to the Mojolicious real-time web framework!</title>
- </head>
- <body>
- <h2>Welcome to the Mojolicious real-time web framework!</h2>
- This is the static document "public/index.html",
- <a href="/">click here</a> to get back to the start.
- </body>
-</html>
diff --git a/t/basic.t b/t/basic.t
index b6893cd..abb2332 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -4,6 +4,6 @@
use Test::Mojo;
my $t = Test::Mojo->new('Korap');
-$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i);
+$t->get_ok('/')->status_is(200)->content_like(qr/Go to/i);
done_testing();