Commit 75b1f481 by Carsten Brandt

improved HTML guide navigation

parent 713f73e6
......@@ -81,7 +81,7 @@ class ApiMarkdown extends GithubMarkdown
{
$content = $this->parseInline($block['content']);
$hash = Inflector::slug(strip_tags($content));
$hashLink = "<a href=\"#$hash\" name=\"$hash\">&para;</a>";
$hashLink = "<a href=\"#$hash\" name=\"$hash\" class=\"hashlink\">&para;</a>";
$tag = 'h' . $block['level'];
return "<$tag>$content $hashLink</$tag>";
......
......@@ -8,6 +8,7 @@
namespace yii\apidoc\renderers;
use Yii;
use yii\apidoc\helpers\IndexFileAnalyzer;
/**
* Base class for all Guide documentation renderers
......@@ -25,4 +26,24 @@ abstract class GuideRenderer extends BaseRenderer
*/
abstract public function render($files, $targetDir);
protected function loadGuideStructure($files)
{
$chapters = [];
foreach ($files as $file) {
$contents = file_get_contents($file);
if (basename($file) == 'README.md') {
$indexAnalyzer = new IndexFileAnalyzer();
$chapters = $indexAnalyzer->analyze($contents);
break;
}
if (preg_match("/^(.*)\n=+/", $contents, $matches)) {
$headlines[$file] = $matches[1];
} else {
$headlines[$file] = basename($file);
}
}
return $chapters;
}
}
......@@ -110,6 +110,35 @@ table.summary-table .col-defined { width: 15%; }
text-decoration: none;
}
.hashlink {
display: none;
}
h1:hover .hashlink, h2:hover .hashlink, h3:hover .hashlink, h4:hover .hashlink, h5:hover .hashlink {
display: inline;
}
.toplink {
position: fixed;
bottom: 50px;
right: 50px;
padding: 5px 8px 0 5px;
border: solid 1px #ddd;
border-radius: 5px;
background: #fff;
}
.toplink a {
color: #bbb;
text-decoration: none;
}
.toplink a:hover {
color: #999;
text-decoration: none;
}
#search-resultbox {
position: fixed;
......
......@@ -5,6 +5,7 @@ use yii\apidoc\templates\bootstrap\SideNavWidget;
/**
* @var yii\web\View $this
* @var string $content
* @var array $chapters
*/
$this->beginContent('@yii/apidoc/templates/bootstrap/layouts/main.php'); ?>
......@@ -12,23 +13,20 @@ $this->beginContent('@yii/apidoc/templates/bootstrap/layouts/main.php'); ?>
<div class="row">
<div class="col-md-2">
<?php
asort($headlines);
$nav = [];
foreach ($headlines as $file => $headline) {
if (basename($file) == 'README.md') {
$nav[] = [
'label' => $headline,
'url' => $this->context->generateGuideUrl($file),
'active' => isset($currentFile) && ($file == $currentFile),
foreach ($chapters as $chapter) {
$items = [];
foreach($chapter['content'] as $chContent) {
$items[] = [
'label' => $chContent['headline'],
'url' => $this->context->generateGuideUrl($chContent['file']),
'active' => isset($currentFile) && ($chContent['file'] == basename($currentFile)),
];
unset($headlines[$file]);
}
}
foreach ($headlines as $file => $headline) {
$nav[] = [
'label' => $headline,
'url' => $this->context->generateGuideUrl($file),
'active' => isset($currentFile) && ($file == $currentFile),
'label' => $chapter['headline'],
// 'url' => $this->context->generateGuideUrl($file),
'items' => $items,
];
} ?>
<?= SideNavWidget::widget([
......@@ -39,6 +37,7 @@ $this->beginContent('@yii/apidoc/templates/bootstrap/layouts/main.php'); ?>
</div>
<div class="col-md-9 guide-content" role="main">
<?= $content ?>
<div class="toplink"><a href="#" class="h1" title="go to top"><span class="glyphicon glyphicon-arrow-up"></a></div>
</div>
</div>
......
......@@ -78,17 +78,12 @@ abstract class GuideRenderer extends BaseGuideRenderer
}
$done = 0;
$fileData = [];
$headlines = [];
$chapters = $this->loadGuideStructure($files);
foreach ($files as $file) {
$fileData[$file] = file_get_contents($file);
if (basename($file) == 'README.md') {
continue; // to not add index file to nav
}
if (preg_match("/^(.*)\n=+/", $fileData[$file], $matches)) {
$headlines[$file] = $matches[1];
} else {
$headlines[$file] = basename($file);
}
}
foreach ($fileData as $file => $content) {
......@@ -96,7 +91,7 @@ abstract class GuideRenderer extends BaseGuideRenderer
$output = $this->fixMarkdownLinks($output);
if ($this->layout !== false) {
$params = [
'headlines' => $headlines,
'chapters' => $chapters,
'currentFile' => $file,
'content' => $output,
];
......
......@@ -7,7 +7,6 @@
namespace yii\apidoc\templates\pdf;
use cebe\markdown\latex\GithubMarkdown;
use Yii;
use yii\apidoc\helpers\ApiMarkdownLaTeX;
use yii\apidoc\helpers\IndexFileAnalyzer;
......@@ -43,13 +42,8 @@ class GuideRenderer extends \yii\apidoc\templates\html\GuideRenderer
}
$done = 0;
$fileData = [];
$chapters = [];
$chapters = $this->loadGuideStructure($files);
foreach ($files as $file) {
if (basename($file) == 'README.md') {
$indexAnalyzer = new IndexFileAnalyzer();
$chapters = $indexAnalyzer->analyze(file_get_contents($file));
continue; // to not add index file to nav
}
if (basename($file) == 'tutorial-i18n.md') {
continue; // TODO avoid i18n tut because of non displayable characters right now. need to fix it.
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment