Skip to content

Commit 22f1116

Browse files
author
github-actions
committed
Merge pull request #222 from hydephp/186-datacollectionmarkdown-helper-should-not-filter-out-files-starting-with-_underscores
Remove underscore filter from Markdown DataCollections hydephp/develop@0dd86b1
1 parent 4c2fe07 commit 22f1116

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/Modules/DataCollections/DataCollection.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Illuminate\Support\Collection;
99

1010
/**
11-
* Generates Laravel Collections from static data files,
12-
* such as Markdown components and YAML files.
11+
* Automatically generates Laravel Collections from static data files,
12+
* such as Markdown components and YAML files using Hyde Autodiscovery.
1313
*
1414
* @see \Hyde\Framework\Testing\Feature\DataCollectionTest
1515
*/
@@ -56,11 +56,9 @@ public static function markdown(string $key): DataCollection
5656
{
5757
$collection = new DataCollection($key);
5858
foreach ($collection->getMarkdownFiles() as $file) {
59-
if (! str_starts_with(basename($file), '_')) {
60-
$collection->push(
61-
(new MarkdownFileService($file))->get()
62-
);
63-
}
59+
$collection->push(
60+
(new MarkdownFileService($file))->get()
61+
);
6462
}
6563

6664
return $collection->getCollection();

tests/Feature/DataCollectionTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ public function test_get_markdown_files_method_does_not_include_files_with_exten
113113
File::deleteDirectory(Hyde::path('_data/foo'));
114114
}
115115

116+
// test get markdown files method does not remove files starting with an underscore
117+
public function test_get_markdown_files_method_does_not_remove_files_starting_with_an_underscore()
118+
{
119+
mkdir(Hyde::path('_data/foo'));
120+
Hyde::touch(('_data/foo/_foo.md'));
121+
122+
$this->assertEquals([
123+
Hyde::path('_data/foo/_foo.md'),
124+
], (new DataCollection('foo'))->getMarkdownFiles());
125+
File::deleteDirectory(Hyde::path('_data/foo'));
126+
}
127+
116128
public function test_static_markdown_helper_returns_new_data_collection_instance()
117129
{
118130
$this->assertInstanceOf(DataCollection::class, DataCollection::markdown('foo'));
@@ -131,12 +143,12 @@ public function test_static_markdown_helper_discovers_and_parses_markdown_files_
131143
File::deleteDirectory(Hyde::path('_data/foo'));
132144
}
133145

134-
public function test_static_markdown_helper_ignores_files_starting_with_an_underscore()
146+
public function test_static_markdown_helper_doest_not_ignore_files_starting_with_an_underscore()
135147
{
136148
mkdir(Hyde::path('_data/foo'));
137149
Hyde::touch(('_data/foo/foo.md'));
138150
Hyde::touch(('_data/foo/_bar.md'));
139-
$this->assertCount(1, DataCollection::markdown('foo'));
151+
$this->assertCount(2, DataCollection::markdown('foo'));
140152
File::deleteDirectory(Hyde::path('_data/foo'));
141153
}
142154

0 commit comments

Comments
 (0)