-
-
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 #25 from wireframe-framework/feature-render-view
0.25.0
- Loading branch information
Showing
5 changed files
with
57 additions
and
5 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.24.2 | ||
* @version 0.25.0 | ||
* @author Teppo Koivula <[email protected]> | ||
* @license Mozilla Public License v2.0 https://mozilla.org/MPL/2.0/ | ||
*/ | ||
|
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* | ||
* @internal This class is only intended for use within the Wireframe internals. | ||
* | ||
* @version 0.2.0 | ||
* @version 0.3.0 | ||
* @author Teppo Koivula <[email protected]> | ||
* @license Mozilla Public License v2.0 https://mozilla.org/MPL/2.0/ | ||
*/ | ||
|
@@ -50,6 +50,9 @@ public function init() { | |
$this->addHookMethod('Page::getView', $this, 'pageView'); | ||
$this->addHookMethod('Page::setView', $this, 'pageView'); | ||
|
||
// helper method for rendering page with specified view | ||
$this->addHookMethod('Page::renderView', $this, 'pageRenderView'); | ||
|
||
// helper methods for getting or setting page view template | ||
$this->addHookMethod('Page::viewTemplate', $this, 'pageViewTemplate'); | ||
$this->addHookMethod('Page::getViewTemplate', $this, 'pageViewTemplate'); | ||
|
@@ -161,6 +164,23 @@ protected function pageView(HookEvent $event) { | |
} | ||
} | ||
|
||
/** | ||
* Render page with specified view | ||
* | ||
* @param HookEvent $event | ||
*/ | ||
protected function pageRenderView(HookEvent $event) { | ||
$original_layout = $event->object->_wireframe_layout; | ||
$original_view = $event->object->_wireframe_view; | ||
$original_view_template = $event->object->_wireframe_view_template; | ||
$event->object->_wireframe_layout = ''; | ||
$event->object->setView($event->arguments[0]); | ||
$event->return = $event->object->render(); | ||
$event->object->_wireframe_layout = $original_layout; | ||
$event->object->_wireframe_view = $original_view; | ||
$event->object->_wireframe_view_template = $original_view_template; | ||
} | ||
|
||
/** | ||
* This method is used by Page::viewTemplate(), Page::getViewTemplate(), and Page::setViewTemplate() | ||
* | ||
|
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
* @property ViewPlaceholders|null $placeholders ViewPlaceholders object. | ||
* @property Partials|null $partials Object containing partial paths. | ||
* | ||
* @version 0.8.2 | ||
* @version 0.9.0 | ||
* @author Teppo Koivula <[email protected]> | ||
* @license Mozilla Public License v2.0 https://mozilla.org/MPL/2.0/ | ||
*/ | ||
|
@@ -88,6 +88,29 @@ public function ___render() { | |
return $out; | ||
} | ||
|
||
/** | ||
* Render specified view file | ||
* | ||
* @param string $view View file name | ||
* @return string Rendered markup for the View. | ||
* | ||
* @throws Exception if provided view file cannot be located. | ||
*/ | ||
public function renderView(string $view): string { | ||
$original_layout = $this->getLayout(); | ||
$original_view = $this->getView(); | ||
$this->setLayout(null)->setView($view); | ||
if ($this->getView() !== $view) { | ||
throw new \Exception(sprintf( | ||
'View not found: "%s"', | ||
$view | ||
)); | ||
} | ||
$out = $this->render(); | ||
$this->setLayout($original_layout)->setView($original_view); | ||
return $out; | ||
} | ||
|
||
/** | ||
* Magic __set() method | ||
* | ||
|
@@ -354,7 +377,7 @@ public function getLayoutsPath(): ?string { | |
public function setViewsPath(string $views_path): View { | ||
if (!\is_dir($views_path)) { | ||
throw new \Exception(sprintf( | ||
'Missing or unreadable path to the views directory: "%"', | ||
'Missing or unreadable path to the views directory: "%s"', | ||
$views_path | ||
)); | ||
} | ||
|