Skip to content

Commit

Permalink
Breaking: Rename class DataCollections to DataCollection
Browse files Browse the repository at this point in the history
See #1712
  • Loading branch information
caendesilva committed Jun 24, 2024
1 parent 22c4b66 commit 4245ba5
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 66 deletions.
13 changes: 10 additions & 3 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This serves two purposes:
### Changed
- **Breaking:** The internals of the navigation system has been rewritten into a new Navigation API. This change is breaking for custom navigation implementations. For more information, see below.
- **Breaking:** The `hyde.features` configuration format has changed to use Enums instead of static method calls. For more information, see below.
- **Breaking:** Renamed class `DataCollections` to `DataCollection`. For more information, see below.
- Minor: Navigation menu items are now no longer filtered by duplicates (meaning two items with the same label can now exist in the same menu) in https://github.com/hydephp/develop/pull/1573
- Minor: Due to changes in the navigation system, it is possible that existing configuration files will need to be adjusted in order for menus to look the same (in terms of ordering etc.)
- Minor: The documentation article component now supports disabling the semantic rendering using a falsy value in https://github.com/hydephp/develop/pull/1566
Expand All @@ -25,7 +26,7 @@ This serves two purposes:
- Changed how the documentation search is generated, to be an `InMemoryPage` instead of a post-build task.
- Media asset files are now copied using the new build task instead of the deprecated `BuildService::transferMediaAssets()` method.
- Calling the `Include::path()` method will no longer create the includes directory in https://github.com/hydephp/develop/pull/1707
- Calling the `DataCollections` methods will no longer create the data collections directory in https://github.com/hydephp/develop/pull/1732
- Calling the `DataCollection` methods will no longer create the data collections directory in https://github.com/hydephp/develop/pull/1732

### Deprecated
- for soon-to-be removed features.
Expand Down Expand Up @@ -220,8 +221,14 @@ For example, if you triggered the media transfer with a build service method cal

### DataCollection API changes

The DataCollections feature has been reworked to improve the developer experience and make it more consistent with the rest of the API.
The DataCollection feature has been reworked to improve the developer experience and make it more consistent with the rest of the API.

Unfortunately, this means that existing setups may need to be adjusted to work with the new API.

- Calling the `DataCollections` methods will no longer create the data collections directory automatically
#### Upgrade guide

- The `DataCollections` class has been renamed to `DataCollection`. If you have used the `DataCollections` class in your code, you will need to update your code to use the new class name.

#### Minor impact

- Calling the `DataCollection` methods will no longer create the data collections directory automatically
2 changes: 1 addition & 1 deletion _ide_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Features extends \Hyde\Facades\Features {}
class Config extends \Hyde\Facades\Config {}
/** @mixin \Illuminate\Filesystem\Filesystem */
class Filesystem extends \Hyde\Facades\Filesystem {}
class DataCollections extends \Hyde\Support\DataCollections {}
class DataCollection extends \Hyde\Support\DataCollection {}
class Includes extends \Hyde\Support\Includes {}
/** @mixin \Hyde\Foundation\Kernel\RouteCollection */
class Routes extends \Hyde\Foundation\Facades\Routes {}
Expand Down
2 changes: 1 addition & 1 deletion app/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
'MarkdownPage' => \Hyde\Pages\MarkdownPage::class,
'MarkdownPost' => \Hyde\Pages\MarkdownPost::class,
'DocumentationPage' => \Hyde\Pages\DocumentationPage::class,
'DataCollections' => \Hyde\Support\DataCollections::class,
'DataCollection' => \Hyde\Support\DataCollection::class,
'Includes' => \Hyde\Support\Includes::class,
'Feature' => \Hyde\Enums\Feature::class,
],
Expand Down
32 changes: 16 additions & 16 deletions docs/digging-deeper/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ navigation:

## Introduction to Hyde Data Collections

Hyde provides `DataCollections`, a subset of [Laravel Collections](https://laravel.com/docs/10.x/collections) giving you a similar developer experience to working with Eloquent Collections.
Hyde provides `DataCollection`, a subset of [Laravel Collections](https://laravel.com/docs/10.x/collections) giving you a similar developer experience to working with Eloquent Collections.
However, instead of accessing a database, it's all entirely file-based using static data files such as Markdown, Yaml, and JSON files which get
parsed into objects that you can easily work with.

Expand All @@ -24,7 +24,7 @@ In short, HydePHP finds files in the specified directory, turns each file into a
To make collections easy to use and understand, Hyde makes a few assumptions about the structure of your collections.
Follow these conventions and creating dynamic static sites will be a breeze.

1. Collections are accessed through static methods in the `DataCollections` class.
1. Collections are accessed through static methods in the `DataCollection` class.
2. Collections are stored as files in subdirectories of the `resources/collections` directory.
3. To get a collection, specify name of the subdirectory the files are stored in.
4. Data will be parsed into differing objects depending on which facade method you use. See the table below.
Expand All @@ -41,9 +41,9 @@ Follow these conventions and creating dynamic static sites will be a breeze.
The following facade methods for creating data collections are available:

```php
\Hyde\Support\DataCollections::markdown(string $name);
\Hyde\Support\DataCollections::yaml(string $name);
\Hyde\Support\DataCollections::json(string $name, bool $asArray = false);
\Hyde\Support\DataCollection::markdown(string $name);
\Hyde\Support\DataCollection::yaml(string $name);
\Hyde\Support\DataCollection::json(string $name, bool $asArray = false);
```

### Quick Reference Table
Expand All @@ -60,15 +60,15 @@ The following facade methods for creating data collections are available:
### Usage

```php
$collection = \Hyde\Support\DataCollections::markdown('name');
$collection = \Hyde\Support\DataCollection::markdown('name');
```

### Example returns

Here is an approximation of the data types contained by the variable created above:

```php
\Hyde\Support\DataCollections {
\Hyde\Support\DataCollection {
"testimonials/1.md" => Hyde\Markdown\Models\MarkdownDocument
"testimonials/2.md" => Hyde\Markdown\Models\MarkdownDocument
"testimonials/3.md" => Hyde\Markdown\Models\MarkdownDocument
Expand Down Expand Up @@ -107,15 +107,15 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit...
### Usage

```php
$collection = \Hyde\Support\DataCollections::yaml('name');
$collection = \Hyde\Support\DataCollection::yaml('name');
```

### Example returns

Here is an approximation of the data types contained by the variable created above:

```php
\Hyde\Support\DataCollections {
\Hyde\Support\DataCollection {
"authors/1.yaml" => Hyde\Markdown\Models\FrontMatter {
+data: array:1 [
"name" => "John Doe",
Expand All @@ -137,13 +137,13 @@ email: "[email protected]"
### Usage
```php
$collection = \Hyde\Support\DataCollections::json('name');
$collection = \Hyde\Support\DataCollection::json('name');
```

By default, the entries will be returned as `stdClass` objects. If you want to return an associative array instead, pass `true` as the second parameter:

```php
$collection = \Hyde\Support\DataCollections::json('name', true);
$collection = \Hyde\Support\DataCollection::json('name', true);
```

Since both return values use native PHP types, there are no example returns added here, as I'm sure you can imagine what they look like.
Expand Down Expand Up @@ -186,18 +186,18 @@ resources/collections

#### Using the Facade to Access the Collections

Now for the fun part! We will use the `DataCollections::markdown()` to access all our files into a convenient object.
Now for the fun part! We will use the `DataCollection::markdown()` to access all our files into a convenient object.
The class is registered with an alias, so you don't need to include any namespaces when in a Blade file.

The general syntax to use the facade is as follows:

```blade
DataCollections::markdown('subdirectory_name')
DataCollection::markdown('subdirectory_name')
```

This will return a Hyde DataCollections object, containing our Markdown files as MarkdownDocument objects. Here is a quick look at the object the facade returns:
This will return a Hyde DataCollection object, containing our Markdown files as MarkdownDocument objects. Here is a quick look at the object the facade returns:

<pre style="display: block; white-space: pre-wrap; padding: 1rem 1.5rem; overflow: initial !important; background-color: rgb(24, 23, 27); color: rgb(255, 132, 0); font: 400 12px Menlo, Monaco, Consolas, monospace; overflow-wrap: break-word; position: relative; z-index: 99999; word-break: break-all; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="sf-dump-default" style="display: inline; background-color: rgb(24, 23, 27); color: rgb(255, 132, 0); font: 12px Menlo, Monaco, Consolas, monospace; overflow-wrap: break-word; white-space: pre-wrap; position: relative; z-index: 99999; word-break: break-all;">^</span><span class="sf-dump-default" style="display: inline; background-color: rgb(24, 23, 27); color: rgb(255, 132, 0); font: 12px Menlo, Monaco, Consolas, monospace; overflow-wrap: break-word; white-space: pre-wrap; position: relative; z-index: 99999; word-break: break-all;"> </span><span style="display: inline; color: rgb(18, 153, 218);">Hyde\Support\DataCollections</span> {<span style="text-decoration: none; border: 0px; outline: none; color: rgb(160, 160, 160);">#651 <span style="display: inline;">▼</span></span><samp>
<pre style="display: block; white-space: pre-wrap; padding: 1rem 1.5rem; overflow: initial !important; background-color: rgb(24, 23, 27); color: rgb(255, 132, 0); font: 400 12px Menlo, Monaco, Consolas, monospace; overflow-wrap: break-word; position: relative; z-index: 99999; word-break: break-all; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="sf-dump-default" style="display: inline; background-color: rgb(24, 23, 27); color: rgb(255, 132, 0); font: 12px Menlo, Monaco, Consolas, monospace; overflow-wrap: break-word; white-space: pre-wrap; position: relative; z-index: 99999; word-break: break-all;">^</span><span class="sf-dump-default" style="display: inline; background-color: rgb(24, 23, 27); color: rgb(255, 132, 0); font: 12px Menlo, Monaco, Consolas, monospace; overflow-wrap: break-word; white-space: pre-wrap; position: relative; z-index: 99999; word-break: break-all;"> </span><span style="display: inline; color: rgb(18, 153, 218);">Hyde\Support\DataCollection</span> {<span style="text-decoration: none; border: 0px; outline: none; color: rgb(160, 160, 160);">#651 <span style="display: inline;">▼</span></span><samp>
#<span style="display: inline; color: rgb(255, 255, 255);">items</span>: <span style="display: inline; color: rgb(18, 153, 218);">array:3</span> [<span style="text-decoration: none; border: 0px; outline: none; color: rgb(160, 160, 160);"><span style="display: inline;">▼</span></span><samp>
"<span style="display: inline; color: rgb(86, 219, 58);">testimonials/1.md</span>" =&gt; <span style="display: inline; color: rgb(18, 153, 218);"><span>Hyde\Markdown\Models</span><span style="display: inline-block; text-overflow: ellipsis; max-width: none; white-space: nowrap; overflow: hidden; vertical-align: top; color: rgb(18, 153, 218);">\</span>MarkdownDocument</span> {<span style="text-decoration: none; border: 0px; outline: none; color: rgb(160, 160, 160);">#653 <span style="display: inline;">▼</span></span><samp>
+<span style="display: inline; color: rgb(255, 255, 255);">matter</span>: <span style="display: inline; color: rgb(18, 153, 218);"><span>Hyde\Markdown\Models</span><span style="display: inline-block; text-overflow: ellipsis; max-width: none; white-space: nowrap; overflow: hidden; vertical-align: top; color: rgb(18, 153, 218);">\</span>FrontMatter</span> {<span style="text-decoration: none; border: 0px; outline: none; color: rgb(160, 160, 160);">#652 <span style="display: inline;">▶</span></span>}
Expand All @@ -222,7 +222,7 @@ we are able to get the author from the front matter, and the content from the bo

```blade
// filepath _pages/testimonials.blade.php
@foreach(DataCollections::markdown('testimonials') as $testimonial)
@foreach(DataCollection::markdown('testimonials') as $testimonial)
<blockquote>
<p>{{ $testimonial->body }}</p>
<small>{{ $testimonial->matter['author'] }}</small>
Expand Down
10 changes: 5 additions & 5 deletions docs/digging-deeper/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ Note that these helpers targets those who write custom code and Blade templates,

## File-based Collections

Hyde provides `DataCollections`, a subset of [Laravel Collections](https://laravel.com/docs/10.x/collections) giving you a similar developer experience to working with Eloquent Collections. However, instead of accessing a database,
Hyde provides `DataCollection`, a subset of [Laravel Collections](https://laravel.com/docs/10.x/collections) giving you a similar developer experience to working with Eloquent Collections. However, instead of accessing a database,
it's all entirely file-based using static data files such as Markdown, Yaml, and JSON files which get parsed into objects that you can easily work with.

```php
use Hyde\Support\DataCollections;
use Hyde\Support\DataCollection;

// Gets all Markdown files in resources/collections/$name directory
DataCollections::markdown(string $name);
DataCollection::markdown(string $name);

// Gets all YAML files in resources/collections/$name directory
DataCollections::yaml(string $name);
DataCollection::yaml(string $name);

// Gets all JSON files in resources/collections/$name directory
DataCollections::json(string $name, bool $asArray = false);
DataCollection::json(string $name, bool $asArray = false);
```

See the [File-based Collections](collections) documentation for the full details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* All collections are indexed by their filename, which is relative
* to the configured data collection source directory.
*/
class DataCollections extends Collection
class DataCollection extends Collection
{
/**
* The base directory for all data collections. Can be modified using a service provider.
Expand All @@ -44,7 +44,7 @@ class DataCollections extends Collection
*
* Each Markdown file will be parsed into a MarkdownDocument with front matter.
*
* @return DataCollections<string, \Hyde\Markdown\Models\MarkdownDocument>
* @return DataCollection<string, \Hyde\Markdown\Models\MarkdownDocument>
*/
public static function markdown(string $name): static
{
Expand All @@ -58,7 +58,7 @@ public static function markdown(string $name): static
*
* Each YAML file will be parsed into a FrontMatter object.
*
* @return DataCollections<string, \Hyde\Markdown\Models\FrontMatter>
* @return DataCollection<string, \Hyde\Markdown\Models\FrontMatter>
*/
public static function yaml(string $name): static
{
Expand All @@ -78,7 +78,7 @@ public static function yaml(string $name): static
*
* Each JSON file will be parsed into a stdClass object, or an associative array, depending on the second parameter.
*
* @return DataCollections<string, \stdClass|array>
* @return DataCollection<string, \stdClass|array>
*/
public static function json(string $name, bool $asArray = false): static
{
Expand Down
Loading

0 comments on commit 4245ba5

Please sign in to comment.