Skip to content

Commit

Permalink
Merge pull request #527 from tighten/kdd/fix-temp-remote-item-filenames
Browse files Browse the repository at this point in the history
Use string key as remote collection item temporary filename, if present
  • Loading branch information
damiani authored Jan 5, 2021
2 parents 2d73f5c + 4536089 commit e829f7d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Collection/CollectionRemoteItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class CollectionRemoteItem
{
private $item;
private $index;
private $prefix;
private $collectionName;

public function __construct($item, $index = 0, $collectionName = null)
{
$this->item = $item;
$this->index = $index;
$this->prefix = $collectionName . '_';
$this->collectionName = $collectionName;
}

public function getContent()
Expand All @@ -27,7 +27,11 @@ public function getContent()

public function getFilename()
{
return Arr::get($this->item, 'filename', $this->prefix . ($this->index + 1)) . '.blade.md';
$default = is_int($this->index)
? $this->collectionName . '-' . ($this->index + 1)
: $this->index;

return Arr::get($this->item, 'filename', $default) . '.blade.md';
}

protected function getHeader()
Expand Down
31 changes: 31 additions & 0 deletions tests/RemoteCollectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,37 @@ public function filename_for_output_file_is_set_to_collection_name_plus_index_if
$this->assertTrue($files->hasChild('build/test/test-2.html'));
}

/**
* @test
*/
public function filename_for_output_file_is_set_to_collection_name_plus_array_key_if_filename_not_specified_and_key_is_string()
{
$config = collect([
'collections' => [
'test' => [
'extends' => '_layouts.master',
'items' => [
'foo' => [
'content' => 'item 1',
],
'bar' => [
'content' => 'item 2',
],
],
],
],
]);
$files = $this->setupSource([
'_layouts' => [
'master.blade.php' => "<div>@yield('content')</div>",
],
]);
$this->buildSite($files, $config);

$this->assertTrue($files->hasChild('build/test/foo.html'));
$this->assertTrue($files->hasChild('build/test/bar.html'));
}

/**
* @test
*/
Expand Down

0 comments on commit e829f7d

Please sign in to comment.