Skip to content

Commit f04524f

Browse files
authored
Merge pull request #880 from hydephp/datacollections-package-updates
Make DataCollections part of the Framework core
2 parents 511c7bd + 3c35c00 commit f04524f

File tree

11 files changed

+12
-100
lines changed

11 files changed

+12
-100
lines changed

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
'MarkdownPost' => \Hyde\Pages\MarkdownPost::class,
107107
'DocumentationPage' => \Hyde\Pages\DocumentationPage::class,
108108
'Filesystem' => \Hyde\Facades\Filesystem::class,
109+
'MarkdownCollection' => \Hyde\Framework\Features\DataCollections\Facades\MarkdownCollection::class,
109110
],
110111

111112
];

config/hyde.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
Features::bladePages(),
8787
Features::markdownPages(),
8888
Features::documentationPages(),
89-
// Features::dataCollections(),
9089

9190
// Frontend Features
9291
Features::darkmode(),

docs/digging-deeper/collections.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ navigation:
88

99
>info This article covers advanced usage intended for those who are writing their own Blade views, and is not required as Hyde comes pre-packaged with many templates for you to use.
1010
11-
>warning This feature was added in v0.43.0-beta.
1211

1312
## Introduction to Hyde Data Collections
1413

@@ -18,30 +17,17 @@ You get the have access to all Laravel Collection methods so you are encouraged
1817

1918
Currently only a Markdown collection type is added, but more types like YAML are planned.
2019

21-
### Enabling the feature
22-
23-
You may need to enable the module by adding the feature to your Hyde configuration file's `features` array:
24-
25-
```php
26-
// filepath config/hyde.php
27-
28-
'features' => [
29-
Features::dataCollections(),
30-
],
31-
32-
```
33-
3420
### High-Level Concept Overview
3521

3622
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.
3723

3824
1. Collections are stored in the new `resources/collections` directory.
3925
2. Each subdirectory in here can be a collection.
40-
3. Data collections are automatically generated when you use the Facade you will learn about below.
26+
3. Data collections are automatically generated from the source files when you use the Facade you will learn about below.
4127
4. When using one of the facades, you need to specify the collection name, this name is the name of the subdirectory.
4228
5. Each subdirectory should probably only have the same filetype to prevent developer confusion, but this is not enforced.
4329
6. Unlike Markdown pages, files starting with underscores are not ignored.
44-
7. You can customize the base `resources/collections` directory through a service provider.
30+
7. You can customize the source directory for collections through a service provider.
4531

4632

4733
### Markdown Collections - Hands on Guide
@@ -52,7 +38,7 @@ I think the best way to explain DataCollections is through examples. Let's creat
5238

5339
We start by setting up our directory structure. We will create a `testimonials` subdirectory, which will be the collection name.
5440

55-
In it we will place Markdown files. Each file will be a testimonial. The Markdown will be parsed into a MarkdownDocument object which parses any optional YAML front matter.
41+
In it we will place Markdown files. Each file will be a testimonial. The Markdown will be parsed into a `MarkdownDocument` object which parses any optional YAML front matter.
5642

5743
Here is the sample Markdown we will use:
5844

@@ -79,7 +65,7 @@ resources/collections
7965

8066
#### Using the Facade to Access the Collections
8167

82-
Now for the fun part! We will use the `MarkdownCollection` facade to access all our files into a convenient object. The class is already aliased to the facade, so you don't need to use any namespaces.
68+
Now for the fun part! We will use the `MarkdownCollection` facade 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.
8369

8470
The general syntax to use the facade is as follows:
8571

packages/framework/config/hyde.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
Features::bladePages(),
8787
Features::markdownPages(),
8888
Features::documentationPages(),
89-
// Features::dataCollections(),
9089

9190
// Frontend Features
9291
Features::darkmode(),

packages/framework/src/Facades/Features.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ public static function hasDocumentationPages(): bool
8080
return static::enabled(static::documentationPages());
8181
}
8282

83-
public static function hasDataCollections(): bool
84-
{
85-
return static::enabled(static::dataCollections());
86-
}
87-
8883
public static function hasDocumentationSearch(): bool
8984
{
9085
return static::enabled(static::documentationSearch())
@@ -142,11 +137,6 @@ public static function documentationSearch(): string
142137
return 'documentation-search';
143138
}
144139

145-
public static function dataCollections(): string
146-
{
147-
return 'data-collections';
148-
}
149-
150140
public static function darkmode(): string
151141
{
152142
return 'darkmode';

packages/framework/src/Framework/Features/DataCollections/DataCollectionServiceProvider.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

packages/framework/src/Framework/Features/DataCollections/Facades/MarkdownCollection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/**
1010
* @see \Hyde\Framework\Testing\Feature\DataCollectionTest
11+
* @deprecated Since this class is so simple, it could easily be inlined.
1112
*/
1213
class MarkdownCollection
1314
{

packages/framework/src/Framework/HydeServiceProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Hyde\Facades\Features;
99
use Hyde\Foundation\HydeKernel;
1010
use Hyde\Framework\Concerns\RegistersFileLocations;
11-
use Hyde\Framework\Features\DataCollections\DataCollectionServiceProvider;
1211
use Hyde\Framework\Services\AssetService;
1312
use Hyde\Framework\Services\YamlConfigurationService;
1413
use Hyde\Framework\Views\Components\LinkComponent;
@@ -142,6 +141,5 @@ protected function registerPageModels(): void
142141
protected function registerModuleServiceProviders(): void
143142
{
144143
$this->app->register(HydeConsoleServiceProvider::class);
145-
$this->app->register(DataCollectionServiceProvider::class);
146144
}
147145
}

packages/framework/tests/Feature/ConfigurableFeaturesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function test_to_array_method_contains_all_settings()
8585
$this->assertArrayHasKey('documentation-search', $array);
8686
$this->assertArrayHasKey('torchlight', $array);
8787

88-
$this->assertCount(9, $array);
88+
$this->assertCount(8, $array);
8989
}
9090

9191
public function test_features_can_be_mocked()

packages/framework/tests/Feature/DataCollectionTest.php

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
namespace Hyde\Framework\Testing\Feature;
66

77
use ArgumentCountError;
8-
use Hyde\Facades\Features;
98
use Hyde\Framework\Features\DataCollections\DataCollection;
10-
use Hyde\Framework\Features\DataCollections\DataCollectionServiceProvider;
119
use Hyde\Framework\Features\DataCollections\Facades\MarkdownCollection;
1210
use Hyde\Hyde;
1311
use Hyde\Markdown\Models\MarkdownDocument;
@@ -18,7 +16,6 @@
1816

1917
/**
2018
* @covers \Hyde\Framework\Features\DataCollections\DataCollection
21-
* @covers \Hyde\Framework\Features\DataCollections\DataCollectionServiceProvider
2219
* @covers \Hyde\Framework\Features\DataCollections\Facades\MarkdownCollection
2320
*/
2421
class DataCollectionTest extends TestCase
@@ -27,8 +24,9 @@ protected function setUp(): void
2724
{
2825
parent::setUp();
2926

30-
config(['hyde.features' => [Features::dataCollections()]]);
31-
(new DataCollectionServiceProvider($this->app))->boot();
27+
if (! is_dir(Hyde::path('resources/collections'))) {
28+
mkdir(Hyde::path('resources/collections'));
29+
}
3230
}
3331

3432
public function test_constructor_creates_new_data_collection_instance()
@@ -162,30 +160,6 @@ public function test_data_collection_service_provider_registers_the_facade_as_an
162160
$this->assertContains(MarkdownCollection::class, AliasLoader::getInstance()->getAliases());
163161
}
164162

165-
public function test_data_collection_service_provider_creates_the__data_directory_if_it_does_not_exist_and_feature_is_enabled()
166-
{
167-
config(['hyde.features' => [Features::dataCollections()]]);
168-
169-
File::deleteDirectory(Hyde::path('resources/collections'));
170-
$this->assertFileDoesNotExist(Hyde::path('resources/collections'));
171-
172-
(new DataCollectionServiceProvider($this->app))->boot();
173-
174-
$this->assertFileExists(Hyde::path('resources/collections'));
175-
}
176-
177-
public function test_data_collection_service_provider_does_not_create_the__data_directory_feature_is_disabled()
178-
{
179-
File::deleteDirectory(Hyde::path('resources/collections'));
180-
$this->assertFileDoesNotExist(Hyde::path('resources/collections'));
181-
182-
config(['hyde.features' => []]);
183-
$this->app['config']->set('hyde.data_collection.enabled', false);
184-
(new DataCollectionServiceProvider($this->app))->boot();
185-
186-
$this->assertFileDoesNotExist(Hyde::path('resources/collections'));
187-
}
188-
189163
public function test_class_has_static_source_directory_property()
190164
{
191165
$this->assertEquals('resources/collections', DataCollection::$sourceDirectory);

0 commit comments

Comments
 (0)