Add previous and next links to the pages, fixes #93

Cette révision appartient à :
Stéphane Goetz 2015-10-28 00:18:29 +01:00
Parent 6e38c56a12
révision 18a34beac3
11 fichiers modifiés avec 111 ajouts et 6 suppressions

Voir le fichier

@ -33,7 +33,6 @@ class Generate extends SymfonyCommand
// Generate the tree
$daux->generateTree();
$daux->getProcessor()->manipulateTree($daux->tree);
// Generate the documentation
$daux->getGenerator()->generateAll($input, $output, $width);

Voir le fichier

@ -3,6 +3,8 @@
use Symfony\Component\Console\Output\NullOutput;
use Todaymade\Daux\ContentTypes\ContentTypeHandler;
use Todaymade\Daux\Tree\Builder;
use Todaymade\Daux\Tree\Content;
use Todaymade\Daux\Tree\Directory;
use Todaymade\Daux\Tree\Root;
class Daux
@ -173,6 +175,41 @@ class Daux
$this->tree->getEntries()[$key]->setTitle($node);
}
}
// Enhance the tree with processors
$this->getProcessor()->manipulateTree($this->tree);
// Sort the tree one last time before it is finalized
$this->sortTree($this->tree);
$this->finalizeTree($this->tree);
}
public function sortTree(Directory $current) {
$current->sort();
foreach ($current->getEntries() as $entry) {
if ($entry instanceof Directory) {
$this->sortTree($entry);
}
}
}
public function finalizeTree(Directory $current, $prev = null)
{
foreach ($current->getEntries() as $entry) {
if ($entry instanceof Directory) {
$prev = $this->finalizeTree($entry, $prev);
} elseif ($entry instanceof Content) {
if ($prev) {
$prev->setNext($entry);
$entry->setPrevious($prev);
}
$prev = $entry;
}
}
return $prev;
}
/**

Voir le fichier

@ -74,7 +74,9 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
'markdown' => $this->content,
'request' => $params['request'],
'content' => $this->convertPage($this->content),
'breadcrumbs' => $params['html']['breadcrumbs']
'breadcrumbs' => $params['html']['breadcrumbs'],
'prev' => $this->file->getPrevious(),
'next' => $this->file->getNext(),
];
if ($page['breadcrumbs']) {

Voir le fichier

@ -74,7 +74,7 @@ class Processor
* phase, with this you can change the markdown parser or add
* a completely different file type.
*
* @return \Todaymade\Daux\Format\Base\ContentTypes\ContentType[]
* @return \Todaymade\Daux\ContentTypes\ContentType[]
*/
public function addContentType()
{

Voir le fichier

@ -37,7 +37,6 @@ class Server
// Improve the tree with a processor
$daux->generateTree();
$daux->getProcessor()->manipulateTree($daux->tree);
$server = new static($daux);

Voir le fichier

@ -7,6 +7,16 @@ class Content extends Entry
*/
protected $content;
/**
* @var Content
*/
protected $previous;
/**
* @var Content
*/
protected $next;
/**
* @return string
*/
@ -26,4 +36,46 @@ class Content extends Entry
{
$this->content = $content;
}
/**
* @return Content
*/
public function getPrevious()
{
return $this->previous;
}
/**
* @param Content $previous
*/
public function setPrevious($previous)
{
$this->previous = $previous;
}
/**
* @return Content
*/
public function getNext()
{
return $this->next;
}
/**
* @param Content $next
*/
public function setNext($next)
{
$this->next = $next;
}
public function dump()
{
$dump = parent::dump();
$dump['prev'] = $this->getPrevious() ? $this->getPrevious()->getUrl() : '';
$dump['next'] = $this->getNext() ? $this->getNext()->getUrl() : '';
return $dump;
}
}

Voir le fichier

@ -14,6 +14,7 @@ class Directory extends Entry
{
// Separate the values into buckets to sort them separately
$buckets = [
'index' => [],
'numeric' => [],
'normal' => [],
'down_numeric' => [],
@ -23,6 +24,11 @@ class Directory extends Entry
foreach ($this->children as $key => $entry) {
$name = $entry->getName();
if ($name == 'index' || $name == '_index') {
$buckets['index'][$key] = $entry;
continue;
}
if ($name[0] == "-") {
if (is_numeric($name[1])) {
$exploded = explode("_", $name);

Voir le fichier

@ -31,5 +31,14 @@
<?php } ?>
<?= $page['content']; ?>
<?php if(!empty($page['prev']) || !empty($page['next'])) { ?>
<nav>
<ul class="pager">
<?php if(!empty($page['prev'])) { ?><li><a href="<?= $base_url . $page['prev']->getUrl() ?>">Previous</a></li><?php } ?>
<?php if(!empty($page['next'])) { ?><li><a href="<?= $base_url . $page['next']->getUrl() ?>">Next</a></li><?php } ?>
</ul>
</nav>
<?php } ?>
</article>

Voir le fichier

@ -16,6 +16,7 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase {
array(["A_File", "01_A_File"], ["01_A_File", "A_File"]),
array(["A_File", "01_Continuing", "-01_Coming", "-02_Soon"], ["01_Continuing", "A_File", "-01_Coming", "-02_Soon"]),
array(["01_Getting_Started", "API_Calls", "200_Something_Else-Cool", "_5_Ways_to_Be_Happy"], ["01_Getting_Started", "200_Something_Else-Cool", "_5_Ways_to_Be_Happy", "API_Calls"]),
array(["01_Getting_Started", "API_Calls", "index", "200_Something_Else-Cool", "_5_Ways_to_Be_Happy"], ["index", "01_Getting_Started", "200_Something_Else-Cool", "_5_Ways_to_Be_Happy", "API_Calls"]),
array(["Before_but_after", "A_File", "Continuing"], ["A_File", "Before_but_after", "Continuing"]),
array(["01_GitHub_Flavored_Markdown", "Code_Test", "05_Code_Highlighting"], ["01_GitHub_Flavored_Markdown", "05_Code_Highlighting", "Code_Test"]),
);

Diff de fichier supprimé car une ou plusieurs lignes sont trop longues

Voir le fichier

@ -31,7 +31,7 @@
@import "navbar.less";
//@import "breadcrumbs.less";
//@import "pagination.less";
//@import "pager.less";
@import "pager.less";
//@import "labels.less";
//@import "badges.less";
//@import "jumbotron.less";