Skip to content

Commit

Permalink
Merge pull request #5 from wireframe-framework/dev
Browse files Browse the repository at this point in the history
Release 0.11.0
  • Loading branch information
teppokoivula authored May 13, 2020
2 parents c98649a + a4a58c3 commit 522a08e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.11.0] - 2020-05-13

### Changed
- Partials class now detects if a missing partial is being requested and throws an exception.

## [0.10.2] - 2020-03-13

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Wireframe.info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "Wireframe",
"summary": "Wireframe is an output framework for ProcessWire CMS/CMF.",
"version": "0.10.2",
"version": "0.11.0",
"author": "Teppo Koivula",
"href": "https://wireframe-framework.com",
"requires": [
Expand Down
9 changes: 5 additions & 4 deletions Wireframe.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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, '.');
Expand All @@ -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);
}
Expand Down
55 changes: 54 additions & 1 deletion lib/Partials.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
}

}

0 comments on commit 522a08e

Please sign in to comment.