Skip to content

Commit

Permalink
Establish navi->list helper
Browse files Browse the repository at this point in the history
Change-Id: I0bab00500aac7c0398e8e4ab60792e0f0b567bb7
  • Loading branch information
Akron committed Oct 21, 2024
1 parent 0d3630c commit b161fcc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.58 2024-10-08
0.58 2024-10-14
- Fix meta table view for key value pairs (diewald)
- Fix warning on OAuth public clients (diewald)
- Introduce navi->list helper (diewald)

0.57 2024-10-08
- Support VCs via URL without queries (diewald)
Expand Down
27 changes: 27 additions & 0 deletions lib/Kalamar/Plugin/KalamarPages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,33 @@ sub register {
return 1;
}
);

# List navi entries on top level
$mojo->helper(
'navi.list' => sub {
my $c = shift;
my $realm = shift;
my @list = ();

# Iterate over items
foreach (@{$navi->{$realm} // []}) {
# Fragments are not allowed on the top level - so ignore this!

# Generate url with query parameter inheritance
my $url = $c->url_with($realm, page => $_->{id});

# Canonicalize (for empty scopes)
$url->path->canonicalize;
$url->fragment('page-top');

push @list, {
url => $url,
title => $c->loc('Nav_' . $_->{id}, $_->{title})
};
};
return @list;
}
);
}

1;
Expand Down
22 changes: 22 additions & 0 deletions t/navigation.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ push(@{$app->plugins->namespaces}, 'Kalamar::Plugin');

# Establish test route
$app->routes->get('/doc/:scope/:page')->to(cb => sub {}, scope => undef)->name('doc');
$app->routes->get('/settings/:scope/:page')->to(cb => sub {}, scope => undef)->name('settings');


# Load plugin to test
$app->plugin('KalamarPages');
Expand Down Expand Up @@ -273,7 +275,27 @@ like($render, qr!<a href="/doc/development/krill(?:#[^"]+)?">Krill</a>!,
like($render, qr!<a href="/doc/faq(?:#[^"]+)?">FAQ</a>!,
'Path matches FAQ');

# Create settings realm
$app->navi->add(settings => (
'OAuth', 'oauth'
));

# Create settings realm
$app->navi->add(settings => (
'Marketplace', 'marketplace'
));

$render = $app->navigation('settings');

like($render, qr!/settings/oauth#page-top!);
like($render, qr!/settings/marketplace#page-top!);

my @list = $app->navi->list('settings');

is($list[0]->{url}, '/settings/oauth#page-top');
is($list[0]->{title}, 'OAuth');
is($list[1]->{url}, '/settings/marketplace#page-top');
is($list[1]->{title}, 'Marketplace');

done_testing;

Expand Down

0 comments on commit b161fcc

Please sign in to comment.