Generalized the usage of the navigation helper by introducing a 'realm' parameter
Change-Id: Ief04c7884d144a60855a25498faa8cca44a8ecd2
diff --git a/Changes b/Changes
index a95afbf..2b92041 100755
--- a/Changes
+++ b/Changes
@@ -10,6 +10,9 @@
- Introduced 'page_title' helper.
- Simplified documentation routing.
- Added 'realm' parameter to 'embedded_link_to' helper.
+ - Introduced 'navigation' helper with 'realm' parameter.
+ - Deprecated 'doc_navi' helper in favor of 'navigation'
+ helper.
0.36 2019-09-19
- Rename all cookies to be independent
diff --git a/lib/Kalamar.pm b/lib/Kalamar.pm
index 933b79b..51cb8f6 100644
--- a/lib/Kalamar.pm
+++ b/lib/Kalamar.pm
@@ -214,14 +214,14 @@
};
# Configure documentation navigation
- my $navi = Mojo::File->new($self->home->child('templates','doc','navigation.json'))->slurp;
- $navi = $navi ? decode_json($navi) : [];
+ my $doc_navi = Mojo::File->new($self->home->child('templates','doc','navigation.json'))->slurp;
+ $doc_navi = $doc_navi ? decode_json($doc_navi) : [];
if ($conf->{navi_ext}) {
- push @$navi, @{$conf->{navi_ext}};
+ push @$doc_navi, @{$conf->{navi_ext}};
};
- $self->config(navi => $navi);
+ $self->config(doc_navi => $doc_navi);
$self->log->info('API expected at ' . $self->korap->api);
diff --git a/lib/Kalamar/Controller/Documentation.pm b/lib/Kalamar/Controller/Documentation.pm
index abcaadb..bcb6633 100644
--- a/lib/Kalamar/Controller/Documentation.pm
+++ b/lib/Kalamar/Controller/Documentation.pm
@@ -22,7 +22,7 @@
# Set navigation to sidebar
$c->content_block(
sidebar => {
- inline => '<nav>' . $c->doc_navi($c->config('navi')) . '</nav>'
+ inline => '<nav>' . $c->navigation('doc', $c->config('doc_navi')) . '</nav>'
}
);
diff --git a/lib/Kalamar/Plugin/KalamarPages.pm b/lib/Kalamar/Plugin/KalamarPages.pm
index 1943542..8f4f3b5 100644
--- a/lib/Kalamar/Plugin/KalamarPages.pm
+++ b/lib/Kalamar/Plugin/KalamarPages.pm
@@ -104,7 +104,7 @@
my $scope = shift;
my $url;
if ($page) {
- $url = $c->doc->url($scope, $page);
+ $url = $c->url_with('doc', scope => $scope, page => $page);
$url->path->canonicalize;
}
else {
@@ -115,8 +115,10 @@
);
+ # DEPRECATED: 2019-10-24
$mojo->helper(
'doc.url' => sub {
+ deprecated 'Deprecated "doc->url" in favor of direct usage with "url_with"';
my $c = shift;
my $page = pop;
my $scope = shift;
@@ -129,14 +131,25 @@
);
# Documentation navigation helper
+ # DEPRECATED: 2019-10-24
$mojo->helper(
doc_navi => sub {
+ deprecated 'Deprecated "docnavi" in favor of "navigation"';
my $c = shift;
+ return $c->navigation('doc', @_)
+ }
+ );
+
+ # Navigation helper
+ $mojo->helper(
+ 'navigation' => sub {
+ my $c = shift;
+ my $realm = shift;
my $items = pop;
my $scope = shift;
# Create unordered list
- my $html = '<ul class="nav">'."\n";
+ my $html = '<ul class="nav nav-'.$realm.'">'."\n";
# Embed all link tags
foreach (@$items) {
@@ -152,7 +165,10 @@
my $id = $_->{id};
$id =~ s/^#//;
- $url = $c->doc->url($part_scope, $page);
+ $url = $c->url_with($realm, scope => $part_scope, page => $page);
+
+ # Canonicalize (for empty scopes)
+ $url->path->canonicalize;
$url->fragment($id);
}
@@ -165,7 +181,7 @@
};
# Generate url with query parameter inheritance
- $url = $c->doc->url($scope, $_->{id});
+ $url = $c->url_with($realm, scope => $scope, page => $_->{id});
# Canonicalize (for empty scopes)
$url->path->canonicalize;
@@ -194,7 +210,7 @@
if ($_->{items} && ref($_->{items}) eq 'ARRAY') {
$html .= "\n";
my $subscope = $scope ? scalar($scope) . '/' . $_->{id} : $_->{id};
- $html .= $c->doc_navi($subscope, $_->{items});
+ $html .= $c->navigation($realm, $subscope, $_->{items});
$html .= "</li>\n";
}
else {
@@ -292,9 +308,9 @@
Currently not used.
-=head2 doc_navi
+=head2 navigation
-Returns an HTML representation of the documentation navigation,
+Returns an HTML representation of a navigation structure
based on active navigation items.
diff --git a/t/docnavi.t b/t/navigation.t
similarity index 93%
rename from t/docnavi.t
rename to t/navigation.t
index c1aa8ea..f9518e8 100644
--- a/t/docnavi.t
+++ b/t/navigation.t
@@ -40,7 +40,7 @@
}
];
-my $render = $app->doc_navi($navi);
+my $render = $app->navigation('doc', $navi);
like($render, qr!/doc/korap!, 'Path matches doc/korap');
like($render, qr!KorAP!, 'Title matches');
@@ -55,7 +55,7 @@
}
];
-$render = $app->doc_navi($navi);
+$render = $app->navigation('doc', $navi);
like($render, qr!/doc/korap!, 'Path matches doc/korap');
like($render, qr!KorAP!, 'Title matches');
like($render, qr!/doc/krill!, 'Path matches doc/krill');
@@ -78,7 +78,7 @@
}
];
-$render = $app->doc_navi($navi);
+$render = $app->navigation('doc', $navi);
like($render, qr!/doc/korap!, 'Path matches doc/korap');
like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
like($render, qr!/doc/faq!, 'Path matches doc/faq');
@@ -128,7 +128,7 @@
}
];
-$render = $app->doc_navi($navi);
+$render = $app->navigation('doc', $navi);
like($render, qr!/doc/korap!, 'Path matches doc/korap');
like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
like($render, qr!/doc/korap/koral!, 'Path matches korap/koral');
@@ -144,7 +144,7 @@
my $c = $app->build_controller;
$c->stash(page => 'korap');
-$render = $c->doc_navi($navi);
+$render = $c->navigation('doc', $navi);
like($render, qr!/doc/korap!, 'Path matches doc/korap');
like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
like($render, qr!/doc/ql!, 'Path matches doc/ql');
@@ -155,7 +155,7 @@
like($render, qr!class="active".*?KorAP!, 'Active value for KorAP');
$c->stash(page => 'poliqarp-plus');
-$render = $c->doc_navi($navi);
+$render = $c->navigation('doc', $navi);
like($render, qr!/doc/korap!, 'Path matches doc/korap');
like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
like($render, qr!/doc/ql!, 'Path matches doc/ql');
@@ -211,7 +211,7 @@
title => 'F.A.Q.'
}
];
-$render = $c->doc_navi($navi);
+$render = $c->navigation('doc', $navi);
like($render, qr!/doc/korap!, 'Path matches doc/korap');
like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
@@ -241,7 +241,7 @@
}
];
-$render = $app->doc_navi($navi);
+$render = $app->navigation('doc', $navi);
like($render, qr!/doc/korap!, 'Path matches doc/korap');
like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!,
@@ -252,7 +252,7 @@
# Change preferred language
$languages = [qw/de en/];
-$render = $app->doc_navi($navi);
+$render = $app->navigation('doc', $navi);
like($render, qr!/doc/korap!, 'Path matches doc/korap');
like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!,