-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from wireframe-framework/dev
Release 0.11.0
- Loading branch information
Showing
4 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
* @method static string|Page|NullPage page($source, $args = []) Static getter (factory) method for Pages. | ||
* @method static string|null partial(string $partial_name, array $args = []) Static getter (factory) method for Partials. | ||
* | ||
* @version 0.10.2 | ||
* @version 0.11.0 | ||
* @author Teppo Koivula <[email protected]> | ||
* @license Mozilla Public License v2.0 https://mozilla.org/MPL/2.0/ | ||
*/ | ||
|
@@ -510,7 +510,7 @@ public function ___initView(): \Wireframe\View { | |
$view->setExt($ext); | ||
$view->setPage($this->page); | ||
$view->setData($data); | ||
$view->setPartials($this->findPartials($paths->partials . "*")); | ||
$view->setPartials($this->findPartials($paths->partials)); | ||
$view->setPlaceholders(new \Wireframe\ViewPlaceholders($view)); | ||
$view->setRenderer($this->renderer); | ||
$this->view = $view; | ||
|
@@ -953,11 +953,11 @@ protected function findPartials(string $path, string $ext = null): \Wireframe\Pa | |
$cache_key = 'files:' . $path . ':' . $ext; | ||
$files = $this->cache[$cache_key] ?? []; | ||
if (empty($files)) { | ||
foreach (\glob($path) as $file) { | ||
foreach (\glob($path . '*') as $file) { | ||
$name = \basename($file); | ||
if (\strpos($name, ".") === 0) continue; | ||
if (\is_dir($file)) { | ||
$files[$name] = $this->findPartials("{$file}/*", $ext); | ||
$files[$name] = $this->findPartials("{$file}/", $ext); | ||
} else { | ||
$file_data = []; | ||
$ext_pos = \strrpos($name, '.'); | ||
|
@@ -979,6 +979,7 @@ protected function findPartials(string $path, string $ext = null): \Wireframe\Pa | |
if (\is_array($files)) { | ||
$temp_files = $files; | ||
$files = new \Wireframe\Partials(); | ||
$files->setPath($path); | ||
foreach ($temp_files as $key => $file) { | ||
$files->{$key} = \is_object($file) ? $file : new \Wireframe\Partial($file); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,19 @@ | |
* | ||
* This class holds Partial objects and provides method access to rendering them with optional arguments. | ||
* | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
* @author Teppo Koivula <[email protected]> | ||
* @license Mozilla Public License v2.0 https://mozilla.org/MPL/2.0/ | ||
*/ | ||
class Partials extends \ProcessWire\WireArray { | ||
|
||
/** | ||
* Path to the root directory for partial files | ||
* | ||
* @var string | ||
*/ | ||
private $path; | ||
|
||
/** | ||
* Gateway for rendering partials with arguments | ||
* | ||
|
@@ -28,4 +35,50 @@ public function __call($method, $arguments) { | |
return parent::__call($method, $arguments); | ||
} | ||
|
||
/** | ||
* Enables derefencing of WireArray elements in object notation. | ||
* | ||
* Note that unlike regular WireArray, we're going to prioritize local data items. | ||
* | ||
* @param int|string $property | ||
* @return Partial|Partials|null Partial or Partials object or null if no matching item found | ||
* | ||
*/ | ||
public function __get($property) { | ||
$value = null; | ||
if ((\is_string($property) || \is_int($property)) && isset($this->data[$property])) { | ||
$value = $this->data[$property]; | ||
} else { | ||
$value = parent::__get($property); | ||
} | ||
if (\is_null($value)) { | ||
$ext = $this->wire('config')->templateExtension; | ||
return new Partial([ | ||
$ext => $this->path . $property . '.' . $ext, | ||
]); | ||
} | ||
return $value; | ||
} | ||
|
||
/** | ||
* Get a new/blank Partial object | ||
* | ||
* @return Partial | ||
* | ||
*/ | ||
public function makeBlankItem() { | ||
return new Partial([]); | ||
} | ||
|
||
/** | ||
* Set path | ||
* | ||
* @param string $path | ||
* @return Partials Self-reference | ||
*/ | ||
public function setPath(string $path): Partials { | ||
$this->path = $path; | ||
return $this; | ||
} | ||
|
||
} |