Improve tree api

This commit is contained in:
Stéphane Goetz 2015-07-16 11:08:16 +02:00 committed by Stéphane Goetz
parent 290f52d181
commit a044b4b0ca
5 changed files with 61 additions and 26 deletions

BIN
daux.phar Normal file → Executable file

Binary file not shown.

View File

@ -53,7 +53,7 @@ abstract class MarkdownPage extends SimplePage
public static function fromFile(Content $file, $params)
{
$page = new static($file->title, file_get_contents($file->getPath()));
$page = new static($file->getTitle(), $file->getContent());
$page->setFile($file);
$page->setParams($params);

View File

@ -56,7 +56,7 @@ class MarkdownPage extends \Todaymade\Daux\Format\Base\MarkdownPage
$entry_page['View Documentation'] = $params['base_page'] . $params['entry_page']->getUrl();
}
} elseif ($params['file_uri'] === 'index') {
$entry_page[$params['entry_page']->title] = $params['base_page'] . $params['entry_page']->getUrl();
$entry_page[$params['entry_page']->getTitle()] = $params['base_page'] . $params['entry_page']->getUrl();
}
$page = [

View File

@ -4,7 +4,7 @@ use Todaymade\Daux\DauxHelper;
class Content extends Entry
{
public $title;
protected $content;
public function __construct($path = '', $parents = array())
{
@ -12,6 +12,20 @@ class Content extends Entry
$this->value = $this->uri;
}
public function getContent()
{
if (!$this->content) {
$this->content = file_get_contents($this->getPath());
}
return $this->content;
}
public function setContent($content)
{
$this->content = $content;
}
protected function getFilename($file)
{

View File

@ -15,40 +15,28 @@ abstract class Entry
public function __construct($path = '', $parents = array())
{
if (!isset($path) || $path == '' || !file_exists($path)) {
return;
}
$this->local_path = $path;
$this->parents = $parents;
$this->last_modified = filemtime($path);
$this->name = DauxHelper::pathinfo($path)['filename'];
$this->title = $this->getTitleInternal($this->name);
$this->uri = $this->getUrlInternal($this->getFilename($path));
$this->index_page = false;
$this->setPath($path);
$this->setParents($parents);
}
public function getName()
{
return $this->name;
}
public function setUri($uri)
{
$this->uri = $uri;
}
public function setName($name)
{
$this->name = $name;
}
public function getUri()
{
return $this->uri;
}
public function getUrl()
public function setUri($uri)
{
$url = '';
foreach ($this->parents as $node) {
$url .= $node->uri . '/';
}
$url .= $this->uri;
return $url;
$this->uri = $uri;
}
public function getIndexPage()
@ -101,16 +89,39 @@ abstract class Entry
{
return $this->title;
}
public function setTitle($title)
{
$this->title = $title;
}
public function getParents()
{
return $this->parents;
}
public function setParents($parents)
{
$this->parents = $parents;
}
public function getPath()
{
return $this->local_path;
}
public function setPath($path)
{
if (!isset($path) || $path == '' || !file_exists($path)) {
return;
}
$this->local_path = $path;
$this->last_modified = filemtime($path);
$this->name = DauxHelper::pathinfo($path)['filename'];
$this->title = $this->getTitleInternal($this->name);
$this->uri = $this->getUrlInternal($this->getFilename($path));
$this->index_page = false;
}
public function write($content)
{
@ -121,6 +132,16 @@ abstract class Entry
file_put_contents($this->local_path, $content);
return true;
}
public function getUrl()
{
$url = '';
foreach ($this->parents as $node) {
$url .= $node->uri . '/';
}
$url .= $this->uri;
return $url;
}
protected function getFilename($file)
{