Skip to content

Commit 52cef93

Browse files
authored
Merge pull request #1042 from hydephp/update-InMemoryPage-class
Update InMemoryPage class documentation
2 parents 3b183ef + 53d6e9b commit 52cef93

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

packages/framework/src/Pages/InMemoryPage.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
* usually within the boot method of the package's service provider, or a page collection callback in an extension.
2121
* This is because these pages cannot be discovered by the auto discovery process as there's no source files to parse.
2222
*
23-
* This class is especially useful for one-off pages, like pagination pages and the like.
24-
* But if your usage grows, or if you need file-based autodiscovery, you may benefit
25-
* from creating a custom page class instead, as that will give you full control.
23+
* This class is especially useful for one-off custom pages. But if your usage grows, or if you want to utilize
24+
* Hyde autodiscovery, you may benefit from creating a custom page class instead, as that will give you full control.
2625
*/
2726
class InMemoryPage extends HydePage
2827
{
@@ -45,19 +44,20 @@ public static function make(string $identifier = '', FrontMatter|array $matter =
4544
}
4645

4746
/**
48-
* Create a new virtual page instance.
47+
* Create a new in-memory/virtual page instance.
4948
*
50-
* The virtual page class offers two content options. You can either pass a string to the $contents parameter,
49+
* The in-memory page class offers two content options. You can either pass a string to the $contents parameter,
5150
* Hyde will then save that literally as the page's contents. Alternatively, you can pass a view name to the $view parameter,
5251
* and Hyde will use that view to render the page contents with the supplied front matter during the static site build process.
5352
*
5453
* Note that $contents take precedence over $view, so if you pass both, only $contents will be used.
5554
* You can also register a macro with the name 'compile' to overload the default compile method.
5655
*
5756
* @param string $identifier The identifier of the page. This is used to generate the route key which is used to create the output filename.
58-
* If the identifier for a virtual page is "foo/bar" the page will be saved to "_site/foo/bar.html".
57+
* If the identifier for an in-memory page is "foo/bar" the page will be saved to "_site/foo/bar.html".
58+
* You can then also use the route helper to get a link to it by using the route key "foo/bar".
5959
* @param \Hyde\Markdown\Models\FrontMatter|array $matter The front matter of the page. When using the Blade view rendering option,
60-
* this will be passed to the view.
60+
* all this data will be passed to the view rendering engine.
6161
* @param string $contents The contents of the page. This will be saved as-is to the output file.
6262
* @param string $view The view key or Blade file for the view to use to render the page contents.
6363
*/
@@ -81,6 +81,10 @@ public function getBladeView(): string
8181

8282
/**
8383
* Get the contents that will be saved to disk for this page.
84+
*
85+
* In order to make your virtual page easy to use we provide a few options for how the page can be compiled.
86+
* If you want even more control, you can register a macro with the name 'compile' to overload the method,
87+
* or simply extend the class and override the method yourself, either in a standard or anonymous class.
8488
*/
8589
public function compile(): string
8690
{
@@ -89,13 +93,16 @@ public function compile(): string
8993
}
9094

9195
if (! $this->getContents() && $this->getBladeView()) {
92-
if (str_ends_with($this->view, '.blade.php')) {
96+
if (str_ends_with($this->getBladeView(), '.blade.php')) {
97+
// If the view key is for a Blade file path, we'll use the anonymous view compiler to compile it.
98+
// This allows you to use any arbitrary file, without needing to register its namespace or directory.
9399
return AnonymousViewCompiler::call($this->getBladeView(), $this->matter->toArray());
94100
}
95101

96102
return View::make($this->getBladeView(), $this->matter->toArray())->render();
97103
}
98104

105+
// If there's no macro or view configured, we'll just return the contents as-is.
99106
return $this->getContents();
100107
}
101108

0 commit comments

Comments
 (0)