Simplified documentation routing
Change-Id: Ie2e3907133e12b245b8ebb03b18f70af5b8cfe89
diff --git a/Changes b/Changes
index 14e1098..ee8f191 100755
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.37 2019-10-17
+0.37 2019-10-24
- Removed deprecated 'kalamar_test_port' helper.
- Separated KalamarHelpers and KalamarPages.
- Renamed 'doc_link_to' to 'embedded_link_to'
@@ -8,6 +8,7 @@
- Renamed 'doc_uc' to 'under_construction'
and deprecated 'doc_uc'.
- Introduced 'page_title' helper.
+ - Simplified documentation routing.
0.36 2019-09-19
- Rename all cookies to be independent
diff --git a/lib/Kalamar.pm b/lib/Kalamar.pm
index a47bb2d..322f118 100644
--- a/lib/Kalamar.pm
+++ b/lib/Kalamar.pm
@@ -239,8 +239,7 @@
# Documentation routes
$r->get('/doc')->to('documentation#page', page => 'korap')->name('doc_start');
- $r->get('/doc/:page')->to('documentation#page')->name('doc1');
- $r->get('/doc/*scope/:page')->to('documentation#page')->name('doc2');
+ $r->get('/doc/:scope/:page')->to('documentation#page', scope => undef)->name('doc');
# Contact route
$r->get('/contact')->to('documentation#contact');
diff --git a/lib/Kalamar/Plugin/KalamarPages.pm b/lib/Kalamar/Plugin/KalamarPages.pm
index 66ee72b..4c49854 100644
--- a/lib/Kalamar/Plugin/KalamarPages.pm
+++ b/lib/Kalamar/Plugin/KalamarPages.pm
@@ -25,8 +25,9 @@
($page, my $fragment) = split '#', $page;
- my $url = $c->doc->url($scope, $page);
+ my $url = $c->url_with('doc' => page => $page, scope => $scope);
$url->fragment($fragment) if $fragment;
+ $url->path->canonicalize;
return $c->link_to(
$title,
@@ -112,17 +113,10 @@
my $c = shift;
my $page = pop;
my $scope = shift;
- if ($scope) {
- return $c->url_with(
- 'doc2',
- page => $page,
- scope => $scope
- );
- };
-
return $c->url_with(
- 'doc1',
- page => $page
+ 'doc',
+ page => $page,
+ scope => $scope
);
}
);
diff --git a/t/docnavi.t b/t/docnavi.t
index 5b8447f..c1aa8ea 100644
--- a/t/docnavi.t
+++ b/t/docnavi.t
@@ -11,8 +11,7 @@
push(@{$app->plugins->namespaces}, 'Kalamar::Plugin');
# Establish test route
-$app->routes->get('/doc/:page')->to(cb => sub {})->name('doc1');
-$app->routes->get('/doc/*scope/:page')->to(cb => sub {})->name('doc2');
+$app->routes->get('/doc/:scope/:page')->to(cb => sub {}, scope => undef)->name('doc');
# Load plugin to test
$app->plugin('KalamarPages');