From a811ee67ccf3a9da4bb898eac5e8a924ffb2f9ae Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 8 Oct 2014 14:21:24 +0300 Subject: [PATCH] Add blueprints support for modular content --- system/src/Grav/Common/Page/Page.php | 2 +- system/src/Grav/Common/Page/Pages.php | 14 +++++++++++++- system/src/Grav/Common/Page/Types.php | 26 +++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 7be6ecd58..adcc99acd 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -643,7 +643,7 @@ class Page $this->template = $var; } if (empty($this->template)) { - $this->template = str_replace(CONTENT_EXT, '', $this->name()); + $this->template = ($this->modular() ? 'modular/' : '') . str_replace(CONTENT_EXT, '', $this->name()); } return $this->template; } diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 4a4b91f81..62a414ee4 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -343,7 +343,19 @@ class Pages { $types = self::getTypes(); - return $types->toSelect(); + return $types->pageSelect(); + } + + /** + * Get available page types. + * + * @return array + */ + static public function modularTypes() + { + $types = self::getTypes(); + + return $types->modularSelect(); } /** diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php index e40b3f09b..4b17e86ea 100644 --- a/system/src/Grav/Common/Page/Types.php +++ b/system/src/Grav/Common/Page/Types.php @@ -29,9 +29,8 @@ class Types implements \ArrayAccess, \Iterator, \Countable 'filters' => [ 'key' => '|\.yaml$|' ], - 'key' => 'Filename', + 'key' => 'SubPathName', 'value' => 'PathName', - 'recursive' => false ]; $this->items = Folder::all($path, $options) + $this->items; @@ -52,15 +51,36 @@ class Types implements \ArrayAccess, \Iterator, \Countable foreach (Folder::all($path, $options) as $type) { $this->register($type); } + if (file_exists($path . 'modular/')) { + foreach (Folder::all($path . 'modular/', $options) as $type) { + $this->register($type); + } + } } - public function toSelect() + public function pageSelect() { $list = []; foreach ($this->items as $name => $file) { + if (strstr($name, '/')) { + continue; + } $list[$name] = ucfirst(strtr($name, '_', ' ')); } ksort($list); return $list; } + + public function modularSelect() + { + $list = []; + foreach ($this->items as $name => $file) { + if (strstr($name, 'modular/') !== 0) { + continue; + } + $list[$name] = trim(ucfirst(strtr($name, '_', ' '))); + } + ksort($list); + return $list; + } }