Fix breadcrumbs

This commit is contained in:
Will Rossiter 2014-09-07 22:14:10 +12:00
parent 314e504903
commit 1e04aaed28
8 changed files with 114 additions and 26 deletions

View File

@ -29,8 +29,6 @@
*/
class DocumentationManifest {
const TEMPLATES_DIR = 'documentation';
/**
* @config
*
@ -119,6 +117,10 @@ class DocumentationManifest {
);
$entity->addVersion($version);
if(isset($details['DefaultEntity']) && $details['DefaultEntity']) {
$entity->setDefaultEntity(true);
}
}
}
@ -290,6 +292,9 @@ class DocumentationManifest {
$this->entity, $basename, $path
);
// populate any meta data
$page->getMarkdown();
$this->pages[$page->Link()] = array(
'title' => $page->getTitle(),
'filepath' => $path,
@ -302,12 +307,32 @@ class DocumentationManifest {
/**
* Generate an {@link ArrayList} of the pages to the given page.
*
* @param DocumentationPage
* @param DocumentationEntityLanguage
*
* @return ArrayList
*/
public function generateBreadcrumbs($record) {
public function generateBreadcrumbs($record, $base) {
$output = new ArrayList();
// @todo
$parts = explode('/', $record->getRelativeLink());
$output->push(new ArrayData(array(
'Link' => $base->Link(),
'Title' => $base->Title
)));
$progress = $base->Link();
foreach($parts as $part) {
if($part) {
$progress = Controller::join_links($progress, $part, '/');
$output->push(new ArrayData(array(
'Link' => $progress,
'Title' => DocumentationHelper::clean_page_name($part)
)));
}
}
return $output;
}
@ -380,24 +405,33 @@ class DocumentationManifest {
*
* @return ArrayList
*/
public function getChildrenFor($base, $record) {
public function getChildrenFor($base, $record, $recursive = true) {
$output = new ArrayList();
$depth = substr_count($base, '/');
foreach($this->getPages() as $url => $page) {
if(strstr($url, $base) !== false) {
// children
if(substr_count($url, '/') == ($depth + 1)) {
// found a child
if($base !== $record) {
$mode = (strstr($url, $record) !== false) ? 'current' : 'link';
} else {
$mode = 'link';
}
$children = new ArrayList();
if($mode == 'current') {
if($recursive) {
$children = $this->getChildrenFor($url, $url, false);
}
}
$output->push(new ArrayData(array(
'Link' => $url,
'Title' => $page['title'],
'LinkingMode' => $mode
'LinkingMode' => $mode,
'Children' => $children
)));
}
}

View File

@ -178,7 +178,10 @@ class DocumentationViewer extends Controller {
return $response;
}
if($response->getStatusCode() !== 200) {
$action = $request->param('Action');
$allowed = $this->config()->allowed_actions;
if(!in_array($action, $allowed) || $response->getStatusCode() !== 200) {
// look up the manifest to see find the nearest match against the
// list of the URL. If the URL exists then set that as the current
// page to match against.
@ -292,6 +295,7 @@ class DocumentationViewer extends Controller {
'Title' => $entity->getTitle(),
'Link' => $link,
'LinkingMode' => $mode,
'DefaultEntity' => $entity,
'Children' => $children
)));
}
@ -320,7 +324,10 @@ class DocumentationViewer extends Controller {
*/
public function getBreadcrumbs() {
if($this->record) {
return $this->getManifest()->generateBreadcrumbs($this->record);
return $this->getManifest()->generateBreadcrumbs(
$this->record,
$this->record->getEntity()
);
}
}
@ -335,8 +342,8 @@ class DocumentationViewer extends Controller {
*
* @return string
*/
public function getPageTitle() {
return ($this->record) ? $this->record->getBreadcrumbTitle() : null;
public function getTitle() {
return ($this->record) ? $this->record->getTitle() : null;
}
/**

View File

@ -42,6 +42,15 @@ class DocumentationEntity extends ViewableData {
*/
protected $versions;
/**
* If the system is setup to only document one entity then you may only
* want to show a single entity in the URL and the sidebar. Set this when
* you register the entity with the key `DefaultEntity`
*
* @var boolean $default_entity
*/
protected $defaultEntity;
/**
* Constructor. You do not need to pass the langs to this as
* it will work out the languages from the filesystem
@ -153,7 +162,9 @@ class DocumentationEntity extends ViewableData {
* @return string
*/
public function Link() {
return Controller::join_links(
return ($this->getDefaultEntity())
? Config::inst()->get('DocumentationViewer', 'link_base')
: Controller::join_links(
Config::inst()->get('DocumentationViewer', 'link_base'),
$this->getFolder()
);
@ -178,4 +189,17 @@ class DocumentationEntity extends ViewableData {
}
}
}
/**
* @param boolean $bool
*/
public function setDefaultEntity($bool) {
$this->defaultEntity = $bool;
return $this;
}
public function getDefaultEntity() {
return $this->defaultEntity;
}
}

View File

@ -115,9 +115,7 @@ class DocumentationPage extends ViewableData {
public function getMarkdown($removeMetaData = false) {
try {
if ($md = file_get_contents($this->path)) {
if ($this->title != 'Index') {
$this->populateMetaDataFromText($md, $removeMetaData);
}
return $md;
}

View File

@ -393,3 +393,15 @@ html {
#content .warningBoxBottom a:hover { color: #f3fbfe; }
#content .warningBoxBottom ul { margin: 0 0 0 40px; }
#content .warningBoxBottom li { background: none; margin-bottom: 0; }
.doc-breadcrumbs {
margin-top: -10px;
}
.doc-breadcrumbs p {
font-size: 11px;
margin: 0;
color: #999;
}
.doc-breadcrumbs p a {
color: #999;
}

View File

@ -121,8 +121,8 @@ ul.third {
/*! headers */
h1 {
font-size: 30px;
line-height: 30px;
font-size: 35px;
line-height: 40px;
margin-bottom: 10px;
margin-top: 0;
letter-spacing: -1px;

View File

@ -4,7 +4,7 @@
<head>
<% base_tag %>
<meta charset="utf-8" />
<title><% if PageTitle %>$PageTitle<% end_if %>$DocumentationTitle</title>
<title><% if Title %>$Title &#8211; <% end_if %>$DocumentationTitle</title>
</head>
<body>

View File

@ -3,12 +3,25 @@
<ul class="nav">
<% loop Entities %>
<% if DefaultEntity %>
<% loop Children %>
<li class="$LinkingMode $FirstLast">
<a href="$Link" class="top">$Title</a>
<% else %>
<li class="$LinkingMode"><a href="$Link" class="top">$Title <% if IsFolder %><span class="is-folder">&#9658;</span><% end_if %></a>
<% if LinkingMode == current %>
<% if Children %>
<ul>
<ul class="$FirstLast">
<% loop Children %>
<li><a href="$Link" class="$LinkingMode">$Title</a></li>
<% end_loop %>
</ul><% end_if %>
<% end_if %>
</li>
<% end_loop %>
<% else %>
<li class="$LinkingMode $FirstLast"><a href="$Link" class="top">$Title <% if IsFolder %><span class="is-folder">&#9658;</span><% end_if %></a>
<% if LinkingMode == current %>
<% if Children %>
<ul class="$FirstLast">
<% loop Children %>
<li><a href="$Link" class="$LinkingMode">$Title</a></li>
<% end_loop %>