Added settings and navi helpers

Change-Id: Id54fa79c67609abc98c9d363b49520135fa002ac
diff --git a/Changes b/Changes
index 2b92041..d11686a 100755
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.37 2019-10-24
+0.37 2019-10-27
         - Removed deprecated 'kalamar_test_port' helper.
         - Separated KalamarHelpers and KalamarPages.
         - Renamed 'doc_link_to' to 'embedded_link_to'
@@ -13,6 +13,8 @@
         - Introduced 'navigation' helper with 'realm' parameter.
         - Deprecated 'doc_navi' helper in favor of 'navigation'
           helper.
+        - Added 'navi->set' and 'navi->add' helper.
+        - Added settings skeleton. 
 
 0.36 2019-09-19
         - Rename all cookies to be independent
diff --git a/dev/scss/main/main.scss b/dev/scss/main/main.scss
index 36d668c..c97973b 100644
--- a/dev/scss/main/main.scss
+++ b/dev/scss/main/main.scss
@@ -37,6 +37,18 @@
     margin-top: 0;
     padding-top: 1em;
   }
+
+  &.page {
+    margin-left: $logo-left-distance + 15px;
+    p,li, dd, dt {
+      code {
+        background-color: $ids-grey-2;
+        color: $ids-grey-1;
+        padding: 0 .5em;
+        border-radius: $standard-border-radius;
+      }
+    }
+  }
 }
 
 blockquote {
diff --git a/dev/scss/main/tutorial.scss b/dev/scss/main/tutorial.scss
index bc95a92..526a190 100644
--- a/dev/scss/main/tutorial.scss
+++ b/dev/scss/main/tutorial.scss
@@ -68,16 +68,6 @@
 }
 
 main.tutorial {
-  margin-left: $logo-left-distance + 15px;
-  p,li, dd, dt {
-    code {
-      background-color: $ids-grey-2;
-      color: $ids-grey-1;
-      padding: 0 .5em;
-      border-radius: $standard-border-radius;
-    }
-  }
-
   // Link to documentation
   a.embedded-link::after {
     font-family: FontAwesome;
diff --git a/dev/scss/media.scss b/dev/scss/media.scss
index 2e350da..1a61392 100644
--- a/dev/scss/media.scss
+++ b/dev/scss/media.scss
@@ -163,7 +163,7 @@
       line-height: 1em;
     }
     &.active ~ main div.intro,
-    &.active ~ main.tutorial {
+    &.active ~ main.page {
       margin-left: $standard-margin !important;
     }
 
@@ -205,7 +205,7 @@
     }
   }
 
-  main.tutorial {
+  main.page {
     margin-right: 20px;
   }
 }
@@ -218,7 +218,7 @@
   header, aside {
     display: none;
   }
-  main.tutorial {
+  main.page {
     margin: 1em;
   }
   #kalamar-bg {
diff --git a/kalamar.dict b/kalamar.dict
index 1637965..6c30001 100644
--- a/kalamar.dict
+++ b/kalamar.dict
@@ -59,6 +59,7 @@
     },
     privacy => 'Datenschutz',
     imprint => 'Impressum',
+    settings => 'Einstellungen',
     Template => {
       intro => 'de/intro',
       doc => {
@@ -153,6 +154,7 @@
     },
     privacy => 'Privacy',
     imprint => 'Imprint',
+    settings => 'Settings',
     Template => {
       intro => 'intro',
       doc => {
diff --git a/lib/Kalamar.pm b/lib/Kalamar.pm
index 51cb8f6..8470db6 100644
--- a/lib/Kalamar.pm
+++ b/lib/Kalamar.pm
@@ -217,12 +217,18 @@
   my $doc_navi = Mojo::File->new($self->home->child('templates','doc','navigation.json'))->slurp;
   $doc_navi = $doc_navi ? decode_json($doc_navi) : [];
 
+  # TODO:
+  #   Use navi->add()
   if ($conf->{navi_ext}) {
     push @$doc_navi, @{$conf->{navi_ext}};
   };
 
+  # TODO:
+  #   Remove navi entry
   $self->config(doc_navi => $doc_navi);
 
+  $self->navi->set(doc => $doc_navi);
+
   $self->log->info('API expected at ' . $self->korap->api);
 
   # Establish routes with authentification
@@ -241,6 +247,10 @@
   $r->get('/doc')->to('documentation#page', page => 'korap')->name('doc_start');
   $r->get('/doc/:scope/:page')->to('documentation#page', scope => undef)->name('doc');
 
+  # Settings routes (deactivated)
+  # $r->get('/settings')->to(cb => sub { shift->render('settings') })->name('settings_start');
+  # $r->get('/settings/:scope/:page')->to(scope => undef, page => undef)->name('settings');
+
   # Contact route
   $r->get('/contact')->to('documentation#contact');
   $r->get('/contact')->mail_to_chiffre('documentation#contact');
diff --git a/lib/Kalamar/Controller/Documentation.pm b/lib/Kalamar/Controller/Documentation.pm
index bcb6633..6698f55 100644
--- a/lib/Kalamar/Controller/Documentation.pm
+++ b/lib/Kalamar/Controller/Documentation.pm
@@ -28,7 +28,7 @@
 
   # Render template
   $c->stash(sidebar_active => 1);
-  $c->stash(main_class => 'tutorial');
+  $c->stash(main_class => 'page tutorial');
   $c->stash(documentation => 1);
 
   return $c->render_maybe(
diff --git a/lib/Kalamar/Plugin/KalamarPages.pm b/lib/Kalamar/Plugin/KalamarPages.pm
index 8f4f3b5..b887e7d 100644
--- a/lib/Kalamar/Plugin/KalamarPages.pm
+++ b/lib/Kalamar/Plugin/KalamarPages.pm
@@ -4,6 +4,7 @@
 use Mojo::ByteStream 'b';
 use Mojo::Util qw/xml_escape deprecated/;
 
+our $navi = {};
 
 # TODO:
 #   Add documentation plugin to programmatically
@@ -148,6 +149,11 @@
       my $items = pop;
       my $scope = shift;
 
+      # Take items from central list
+      unless ($items) {
+        $items = $navi->{$realm};
+      };
+
       # Create unordered list
       my $html = '<ul class="nav nav-'.$realm.'">'."\n";
 
@@ -192,7 +198,6 @@
         push(@classes, $_->{'class'}) if $_->{'class'};
         push(@classes, 'active') if $active;
 
-
         # New list item
         $html .= '<li';
         if (@classes) {
@@ -254,6 +259,31 @@
     }
   );
 
+  # Set a navigation list to a realm
+  $mojo->helper(
+    'navi.set' => sub {
+      my $c = shift;
+      my $realm = shift;
+      my $list = shift;
+
+      $navi->{$realm} = $list;
+    }
+  );
+
+  $mojo->helper(
+    'navi.add' => sub {
+      my $c = shift;
+      my $realm = shift;
+      my $navi_realm = ($navi->{$realm} //= []);
+      my $title = shift;
+      my $id = shift;
+
+      push @$navi_realm, {
+        title => $title,
+        id => $id
+      }
+    }
+  );
 }
 
 1;
diff --git a/t/settings.t b/t/settings.t
new file mode 100644
index 0000000..9620504
--- /dev/null
+++ b/t/settings.t
@@ -0,0 +1,52 @@
+package Kalamar::Plugin::Test;
+use Mojo::Base 'Mojolicious::Plugin';
+
+
+sub register {
+  my ($plugin, $app, $param) = @_;
+
+  # Add entry to settings navigation
+  $app->navi->add(settings => (
+    'OAuth Token Management', 'oauth'
+  ));
+
+  $app->routes->get('/settings/oauth')->to(
+    cb => sub {
+      my $c = shift;
+      $c->content_with(settings => '<p id="abc">My Settings</p>');
+      return $c->render('settings');
+    }
+  );
+};
+
+package main;
+use Mojo::Base -strict;
+use Test::More;
+use Test::Mojo;
+use Mojo::ByteStream 'b';
+
+my $t = Test::Mojo->new('Kalamar' => {
+  Kalamar => {
+    plugins => ['Test']
+  }
+});
+
+my $app = $t->app;
+
+$app->routes->get('/settings')->to(cb => sub { shift->render('settings') })->name('settings_start');
+$app->routes->get('/settings/:scope/:page')->to(scope => undef, page => undef)->name('settings');
+
+
+$t->get_ok('/settings')
+  ->text_is('a[href~/settings/oauth]','OAuth Token Management')
+  ->text_is('h2#page-top', 'Settings')
+  ;
+
+$t->get_ok('/settings/oauth')
+  ->text_is('a[href~/settings/oauth]','OAuth Token Management')
+  ->text_is('h2#page-top', 'Settings')
+  ->text_is('#abc', 'My Settings')
+  ;
+
+done_testing;
+__END__
diff --git a/templates/settings.html.ep b/templates/settings.html.ep
new file mode 100644
index 0000000..bd92eb6
--- /dev/null
+++ b/templates/settings.html.ep
@@ -0,0 +1,17 @@
+% if (param('embedded')) {
+%   stash(embedded => 1);
+% };
+
+% unless (stash('title')) {
+%   stash(title => loc('settings'))
+% }
+
+% content_block(sidebar => {
+%    inline => '<nav>' . navigation('settings') . '</nav>'
+% });
+
+% layout 'main', sidebar_active => 1, main_class => 'page settings';
+
+%= page_title
+
+%= content 'settings'