From 55ef0b982bb9e334ba2445a8d23c44acfdf2f0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Goetz?= Date: Sun, 13 Mar 2016 21:51:15 +0100 Subject: [PATCH] Add `getPureContent` to Page to be able to get content without template --- libs/Format/Base/ComputedRawPage.php | 5 +++++ libs/Format/Base/ContentPage.php | 12 +++++++++--- libs/Format/Base/Page.php | 12 ++++++++++++ libs/Format/Base/RawPage.php | 5 +++++ libs/Format/Base/SimplePage.php | 5 +++++ libs/Format/HTML/ContentPage.php | 2 +- libs/Server/ErrorPage.php | 2 +- 7 files changed, 38 insertions(+), 5 deletions(-) diff --git a/libs/Format/Base/ComputedRawPage.php b/libs/Format/Base/ComputedRawPage.php index 8fdef8f..b9e141e 100644 --- a/libs/Format/Base/ComputedRawPage.php +++ b/libs/Format/Base/ComputedRawPage.php @@ -15,4 +15,9 @@ abstract class ComputedRawPage implements Page { return $this->raw->getContent(); } + + public function getPureContent() + { + return $this->raw->getContent(); + } } diff --git a/libs/Format/Base/ContentPage.php b/libs/Format/Base/ContentPage.php index 585e756..7641085 100644 --- a/libs/Format/Base/ContentPage.php +++ b/libs/Format/Base/ContentPage.php @@ -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) diff --git a/libs/Format/Base/Page.php b/libs/Format/Base/Page.php index 3ee5d23..a7fd4c9 100644 --- a/libs/Format/Base/Page.php +++ b/libs/Format/Base/Page.php @@ -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(); } diff --git a/libs/Format/Base/RawPage.php b/libs/Format/Base/RawPage.php index 3d8f8a3..bb0009e 100644 --- a/libs/Format/Base/RawPage.php +++ b/libs/Format/Base/RawPage.php @@ -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"); diff --git a/libs/Format/Base/SimplePage.php b/libs/Format/Base/SimplePage.php index 6e783a4..bc7660a 100644 --- a/libs/Format/Base/SimplePage.php +++ b/libs/Format/Base/SimplePage.php @@ -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)) { diff --git a/libs/Format/HTML/ContentPage.php b/libs/Format/HTML/ContentPage.php index 62cd1d5..596c66c 100644 --- a/libs/Format/HTML/ContentPage.php +++ b/libs/Format/HTML/ContentPage.php @@ -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(), diff --git a/libs/Server/ErrorPage.php b/libs/Server/ErrorPage.php index 5311e64..1d034a3 100644 --- a/libs/Server/ErrorPage.php +++ b/libs/Server/ErrorPage.php @@ -33,7 +33,7 @@ class ErrorPage extends SimplePage $params = $this->params; $page = [ 'title' => $this->title, - 'content' => $this->content, + 'content' => $this->getPureContent(), 'language' => '', ];