Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Commit

Permalink
Adding TOCManager::POSITION_FIRST / LAST
Browse files Browse the repository at this point in the history
For better TOC positionning inside the document
  • Loading branch information
lcallarec committed Mar 27, 2013
1 parent b8760a6 commit 05159c1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/Flownode/Babel/Formatter/Html/Formatter.php
Expand Up @@ -169,13 +169,14 @@ public function addGrid(\Flownode\Babel\Document\Grid\Grid $grid)
/**
*
* @param \Flownode\Babel\Document\Element\Link $link
* @param string $position
* @return void
*/
public function addTOC(\Flownode\Babel\Manager\TOCManager $toc, $page)
public function addTOC(\Flownode\Babel\Manager\TOCManager $toc, $position)
{
$formatter = new TOCFormatter($this, $toc);

if($page === 1)
if($position === \Flownode\Babel\Manager\TOCManager::POSITION_FIRST)
{
$this->content = $formatter->getContent().$this->content;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Flownode/Babel/Formatter/Html/TOCFormatter.php
Expand Up @@ -34,6 +34,10 @@ public function __construct(Formatter $formatter, $toc)
}
}

/**
* Get HTML TOC content
* @return string
*/
public function getContent()
{
return $this->content;
Expand Down
18 changes: 12 additions & 6 deletions src/Flownode/Babel/Formatter/Tcpdf/Formatter.php
Expand Up @@ -106,12 +106,9 @@ public function addImage(\Flownode\Babel\Document\Element\Image $image)
*/
public function addHr(\Flownode\Babel\Document\Element\Hr $hr)
{

$this->executeRules($hr->getRules());

$this->content->Cell(0, 0, '', 'B', 1);


}

/**
Expand All @@ -129,18 +126,27 @@ public function addLink(\Flownode\Babel\Document\Element\Link $link)
$this->content->Write('', $name, $href, false, '', true);

$this->executeRules('default');

}

/**
*
* @param \Flownode\Babel\Document\Element\Link $link
* @param string $position
* @return void
*/
public function addTOC(\Flownode\Babel\Manager\TOCManager $toc, $page)
public function addTOC(\Flownode\Babel\Manager\TOCManager $toc, $position)
{
$this->content->addTOCPage();
$this->content->addTOC(1);
if($position === \Flownode\Babel\Manager\TOCManager::POSITION_FIRST)
{
$position = 1;
}
else
{
$position = '';
}

$this->content->addTOC($position);
$this->content->endTOCPage();
}

Expand Down
4 changes: 4 additions & 0 deletions src/Flownode/Babel/Manager/Manager.php
Expand Up @@ -38,6 +38,10 @@ public function setFormatter(FormatterInterface $formatter)
return $this;
}

/**
* Launch the format process
* Do nothing for non-writing manager
*/
public function format()
{

Expand Down
20 changes: 17 additions & 3 deletions src/Flownode/Babel/Manager/TOCManager.php
Expand Up @@ -19,6 +19,13 @@ class TOCManager extends Manager
{
const NAME = 'toc';

/**
* Position of the TOC inside the document
*/
const POSITION_LAST = 'LAST';
const POSITION_FIRST = 'FIRST';


/**
* Hash of titles
*
Expand All @@ -31,13 +38,20 @@ class TOCManager extends Manager
*/
protected $titles = array();

/**
* Position of TOC inside the document
* May be : self::POSITION_LAST or self::POSITION_FIRST
* @var string
*/
protected $position;

/**
*
* @param string $page
*/
public function __construct($page)
public function __construct($position)
{
$this->page = 1;
$this->position = $position;
}

/**
Expand Down Expand Up @@ -69,7 +83,7 @@ public function getTitles()
*/
public function format()
{
$this->formatter->addTOC($this, $this->page);
$this->formatter->addTOC($this, $this->position);

return $this;
}
Expand Down

0 comments on commit 05159c1

Please sign in to comment.