Skip to content

Commit

Permalink
Custom Layout as Hook
Browse files Browse the repository at this point in the history
So that other extension(s) can remove it easily.
  • Loading branch information
taufik-nurrohman committed May 22, 2022
1 parent a32773b commit 6fcabcb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Layout Extension for [Mecha](https://github.com/mecha-cms/mecha)
Release Notes
-------------

### 2.0.0
### 2.0.1

- Moved from [./mecha-cms/mecha](https://github.com/mecha-cms/mecha).
2 changes: 1 addition & 1 deletion about.page
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Common automation features to speed up the site creation process.
icon: 'M13,3V9H21V3M13,21H21V11H13M3,21H11V15H3M3,13H11V3H3V13Z'
author: Taufik Nurrohman
type: Markdown
version: 2.0.0
version: 2.0.1
...

### Features
Expand Down
12 changes: 8 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ function get() {
}
}
}
function route($content, $path) {
\ob_start();
\ob_start("\\ob_gzhandler");
function page($content) {
if (\is_array($content) && \class_exists("\\Page")) {
$page = $GLOBALS['page'] ?? new \Page;
if ($page && $page instanceof \Page && ($layout = $page->layout)) {
if ($page && $page instanceof \Page && $page->exist() && ($layout = $page->layout)) {
// `$content = ['.\lot\y\log\page\gallery.php', [], 200];`
if (0 === \strpos($layout, ".\\")) {
$layout = \stream_resolve_include_path(\PATH . \D . \strtr(\substr($layout, 2), ["\\" => \D]));
Expand All @@ -73,6 +71,11 @@ function route($content, $path) {
$content[0] = $layout;
}
}
return $content;
}
function route($content, $path) {
\ob_start();
\ob_start("\\ob_gzhandler");
// `$content = ['page', [], 200];`
if (\is_array($content) && isset($content[0]) && \is_string($content[0])) {
if ($r = \Layout::get(...$content)) {
Expand All @@ -90,6 +93,7 @@ function route($content, $path) {
}
\Hook::set('content', __NAMESPACE__ . "\\content", 20);
\Hook::set('get', __NAMESPACE__ . "\\get", 0);
\Hook::set('route', __NAMESPACE__ . "\\page", 900);
\Hook::set('route', __NAMESPACE__ . "\\route", 1000);
}

Expand Down

0 comments on commit 6fcabcb

Please sign in to comment.