Add `getPureContent` to Page to be able to get content without template

This commit is contained in:
Stéphane Goetz 2016-03-13 21:51:15 +01:00
parent d8f7a6e238
commit 55ef0b982b
7 changed files with 38 additions and 5 deletions

View File

@ -15,4 +15,9 @@ abstract class ComputedRawPage implements Page
{
return $this->raw->getContent();
}
public function getPureContent()
{
return $this->raw->getContent();
}
}

View File

@ -21,6 +21,8 @@ abstract class ContentPage extends SimplePage
*/
protected $contentType;
protected $generatedContent;
public function __construct($title, $content)
{
$this->initializePage($title, $content);
@ -49,14 +51,18 @@ abstract class ContentPage extends SimplePage
$this->contentType = $contentType;
}
protected function convertPage($content)
public function getPureContent()
{
return $this->contentType->convert($content, $this->getFile());
if (!$this->generatedContent) {
$this->generatedContent = $this->contentType->convert($this->content, $this->getFile());
}
return $this->generatedContent;
}
protected function generatePage()
{
return $this->convertPage($this->content);
return $this->getPureContent();
}
public static function fromFile(Content $file, $params, ContentType $contentType)

View File

@ -2,5 +2,17 @@
interface Page
{
/**
* Get the converted content, without any template
*
* @return string
*/
public function getPureContent();
/**
* Get the full content
*
* @return mixed
*/
public function getContent();
}

View File

@ -16,6 +16,11 @@ abstract class RawPage implements Page
return $this->file;
}
public function getPureContent()
{
throw new Exception("you should not use this method to show a raw content");
}
public function getContent()
{
throw new Exception("you should not use this method to show a raw content");

View File

@ -11,6 +11,11 @@ abstract class SimplePage implements Page
$this->initializePage($title, $content);
}
public function getPureContent()
{
return $this->content;
}
public function getContent()
{
if (is_null($this->generated)) {

View File

@ -81,7 +81,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
'modified_time' => filemtime($this->file->getPath()),
'markdown' => $this->content,
'request' => $params['request'],
'content' => $this->convertPage($this->content),
'content' => $this->getPureContent(),
'breadcrumbs' => $params['html']['breadcrumbs'],
'prev' => $this->file->getPrevious(),
'next' => $this->file->getNext(),

View File

@ -33,7 +33,7 @@ class ErrorPage extends SimplePage
$params = $this->params;
$page = [
'title' => $this->title,
'content' => $this->content,
'content' => $this->getPureContent(),
'language' => '',
];