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

View File

@ -178,7 +178,10 @@ class DocumentationViewer extends Controller {
return $response; 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 // 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 // list of the URL. If the URL exists then set that as the current
// page to match against. // page to match against.
@ -292,6 +295,7 @@ class DocumentationViewer extends Controller {
'Title' => $entity->getTitle(), 'Title' => $entity->getTitle(),
'Link' => $link, 'Link' => $link,
'LinkingMode' => $mode, 'LinkingMode' => $mode,
'DefaultEntity' => $entity,
'Children' => $children 'Children' => $children
))); )));
} }
@ -320,7 +324,10 @@ class DocumentationViewer extends Controller {
*/ */
public function getBreadcrumbs() { public function getBreadcrumbs() {
if($this->record) { 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 * @return string
*/ */
public function getPageTitle() { public function getTitle() {
return ($this->record) ? $this->record->getBreadcrumbTitle() : null; return ($this->record) ? $this->record->getTitle() : null;
} }
/** /**

View File

@ -42,6 +42,15 @@ class DocumentationEntity extends ViewableData {
*/ */
protected $versions; 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 * Constructor. You do not need to pass the langs to this as
* it will work out the languages from the filesystem * it will work out the languages from the filesystem
@ -153,7 +162,9 @@ class DocumentationEntity extends ViewableData {
* @return string * @return string
*/ */
public function Link() { 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'), Config::inst()->get('DocumentationViewer', 'link_base'),
$this->getFolder() $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) { public function getMarkdown($removeMetaData = false) {
try { try {
if ($md = file_get_contents($this->path)) { if ($md = file_get_contents($this->path)) {
if ($this->title != 'Index') {
$this->populateMetaDataFromText($md, $removeMetaData); $this->populateMetaDataFromText($md, $removeMetaData);
}
return $md; return $md;
} }

View File

@ -393,3 +393,15 @@ html {
#content .warningBoxBottom a:hover { color: #f3fbfe; } #content .warningBoxBottom a:hover { color: #f3fbfe; }
#content .warningBoxBottom ul { margin: 0 0 0 40px; } #content .warningBoxBottom ul { margin: 0 0 0 40px; }
#content .warningBoxBottom li { background: none; margin-bottom: 0; } #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 */ /*! headers */
h1 { h1 {
font-size: 30px; font-size: 35px;
line-height: 30px; line-height: 40px;
margin-bottom: 10px; margin-bottom: 10px;
margin-top: 0; margin-top: 0;
letter-spacing: -1px; letter-spacing: -1px;

View File

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

View File

@ -3,12 +3,25 @@
<ul class="nav"> <ul class="nav">
<% loop Entities %> <% loop Entities %>
<% if DefaultEntity %> <% 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 LinkingMode == current %>
<% if Children %> <% 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 %> <% loop Children %>
<li><a href="$Link" class="$LinkingMode">$Title</a></li> <li><a href="$Link" class="$LinkingMode">$Title</a></li>
<% end_loop %> <% end_loop %>