mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
Show nested sidebar menu
This commit is contained in:
parent
31a3b8a744
commit
314e504903
@ -370,4 +370,40 @@ class DocumentationManifest {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the children of the provided record path.
|
||||
*
|
||||
* Looks for any pages in the manifest which have one more slash attached.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function getChildrenFor($base, $record) {
|
||||
$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)) {
|
||||
if($base !== $record) {
|
||||
$mode = (strstr($url, $record) !== false) ? 'current' : 'link';
|
||||
} else {
|
||||
$mode = 'link';
|
||||
}
|
||||
|
||||
$output->push(new ArrayData(array(
|
||||
'Link' => $url,
|
||||
'Title' => $page['title'],
|
||||
'LinkingMode' => $mode
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -219,14 +219,14 @@ class DocumentationViewer extends Controller {
|
||||
/**
|
||||
* Returns the current language.
|
||||
*
|
||||
* @return string
|
||||
* @return DocumentationEntityLanguage
|
||||
*/
|
||||
public function getLanguage() {
|
||||
return ($this->record) ? $this->record->getEntity()->getLanguage() : null;
|
||||
return ($this->record) ? $this->record->getEntity() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return DocumentationManifest
|
||||
*/
|
||||
public function getManifest() {
|
||||
return new DocumentationManifest((isset($_GET['flush'])));
|
||||
@ -272,10 +272,17 @@ class DocumentationViewer extends Controller {
|
||||
if($entities) {
|
||||
foreach($entities as $entity) {
|
||||
$mode = 'link';
|
||||
$children = new ArrayList();
|
||||
|
||||
if($this->record) {
|
||||
if($entity->hasRecord($this->record)) {
|
||||
$mode = 'current';
|
||||
|
||||
// add children
|
||||
$children = $this->getManifest()->getChildrenFor(
|
||||
$this->getLanguage()->Link(),
|
||||
$this->record->Link()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,7 +291,8 @@ class DocumentationViewer extends Controller {
|
||||
$output->push(new ArrayData(array(
|
||||
'Title' => $entity->getTitle(),
|
||||
'Link' => $link,
|
||||
'LinkingMode' => $mode
|
||||
'LinkingMode' => $mode,
|
||||
'Children' => $children
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
@ -173,12 +173,9 @@ class DocumentationEntity extends ViewableData {
|
||||
*/
|
||||
public function hasRecord(DocumentationPage $page) {
|
||||
foreach($this->getVersions() as $version) {
|
||||
foreach($version->getSupportedLanguages() as $lang) {
|
||||
if($lang === $page->getEntity()) {
|
||||
return true;
|
||||
}
|
||||
if(strstr($page->getPath(), $version->getPath()) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -29,7 +29,9 @@ class DocumentationEntityLanguage extends ViewableData {
|
||||
*/
|
||||
public function Link() {
|
||||
return Controller::join_links(
|
||||
$this->entity->Link(), $this->language
|
||||
$this->entity->Link(),
|
||||
$this->language,
|
||||
'/'
|
||||
);
|
||||
}
|
||||
|
||||
@ -66,7 +68,10 @@ class DocumentationEntityLanguage extends ViewableData {
|
||||
* @return string
|
||||
*/
|
||||
public function getPath() {
|
||||
return Controller::join_links($this->entity->getPath(), $this->language);
|
||||
return Controller::join_links(
|
||||
$this->entity->getPath(),
|
||||
$this->language
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +83,19 @@ class DocumentationPage extends ViewableData {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
return DocumentationHelper::clean_page_name($this->filename);
|
||||
$page = DocumentationHelper::clean_page_name($this->filename);
|
||||
|
||||
if($page == "Index") {
|
||||
// look at the folder name
|
||||
$parts = explode("/", $this->getPath());
|
||||
array_pop($parts); // name
|
||||
|
||||
$page = DocumentationHelper::clean_page_name(
|
||||
array_pop($parts)
|
||||
);
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,16 +62,31 @@ html {
|
||||
padding: 15px 15px 14px;
|
||||
}
|
||||
|
||||
#sidebar .nav .current {
|
||||
#sidebar .nav .current .top {
|
||||
background: #f6f7f8;
|
||||
border: none;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#sidebar .nav .current li {
|
||||
font-weight: normal;
|
||||
padding: 5px 0;
|
||||
list-style: none;
|
||||
font-size: 13px;
|
||||
}
|
||||
#sidebar .nav .current a {
|
||||
color: rgb(51, 67, 72);
|
||||
}
|
||||
|
||||
#sidebar .minor-nav a {
|
||||
color: #181C17;
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
#sidebar .nav a.current {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#layout {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
@ -68,13 +68,13 @@ p {
|
||||
|
||||
/*! lists */
|
||||
ul {
|
||||
margin: 15px 0 20px 20px;
|
||||
margin: 10px 0 20px 20px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
li, dd {
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
margin: 0 0 5px 0;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<% if DefaultEntity %>
|
||||
|
||||
<% else %>
|
||||
<li><a href="$Link" class="$LinkingMode top">$Title <% if IsFolder %><span class="is-folder">►</span><% end_if %></a>
|
||||
<li class="$LinkingMode"><a href="$Link" class="top">$Title <% if IsFolder %><span class="is-folder">►</span><% end_if %></a>
|
||||
<% if LinkingMode == current %>
|
||||
<% if Children %>
|
||||
<ul>
|
||||
|
Loading…
Reference in New Issue
Block a user