2015-05-18 14:26:29 +02:00
|
|
|
<?php namespace Todaymade\Daux\Format\Base;
|
|
|
|
|
2015-05-22 14:48:09 +02:00
|
|
|
use League\CommonMark\CommonMarkConverter;
|
2015-06-29 16:11:01 +02:00
|
|
|
use Todaymade\Daux\Config;
|
2015-05-18 14:26:29 +02:00
|
|
|
use Todaymade\Daux\Tree\Content;
|
|
|
|
|
|
|
|
abstract class MarkdownPage extends SimplePage
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Content
|
|
|
|
*/
|
|
|
|
protected $file;
|
|
|
|
|
|
|
|
/**
|
2015-06-29 16:11:01 +02:00
|
|
|
* @var Config
|
2015-05-18 14:26:29 +02:00
|
|
|
*/
|
|
|
|
protected $params;
|
|
|
|
|
|
|
|
public function __construct($title, $content)
|
|
|
|
{
|
|
|
|
$this->initializePage($title, $content);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFile(Content $file)
|
|
|
|
{
|
|
|
|
$this->file = $file;
|
|
|
|
}
|
|
|
|
|
2015-06-29 16:11:01 +02:00
|
|
|
public function setParams(Config $params)
|
2015-05-18 14:26:29 +02:00
|
|
|
{
|
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
2015-05-22 14:48:09 +02:00
|
|
|
protected function getMarkdownConverter()
|
|
|
|
{
|
|
|
|
return new CommonMarkConverter();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function convertPage($content)
|
|
|
|
{
|
|
|
|
return $this->getMarkdownConverter()->convertToHtml($content);
|
|
|
|
}
|
|
|
|
|
2015-05-18 14:26:29 +02:00
|
|
|
protected function generatePage()
|
|
|
|
{
|
2015-05-22 14:48:09 +02:00
|
|
|
return $this->convertPage($this->content);
|
2015-05-18 14:26:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function fromFile(Content $file, $params)
|
|
|
|
{
|
|
|
|
$page = new static($file->title, file_get_contents($file->getPath()));
|
|
|
|
$page->setFile($file);
|
|
|
|
$page->setParams($params);
|
|
|
|
|
|
|
|
return $page;
|
|
|
|
}
|
|
|
|
}
|