Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow outputting URLs with trailing slash #692

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Collection extends BaseCollection

public static function withSettings(IterableObject $settings, $name)
{
$collection = new static();
$collection = new static;
$collection->settings = $settings;
$collection->name = $name;

Expand Down
2 changes: 1 addition & 1 deletion src/Console/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function fire()
$cacheExists = $this->app[TemporaryFilesystem::class]->hasTempDirectory();

if ($this->input->getOption('pretty') === 'true' && $this->app->config->get('pretty') !== false) {
$this->app->instance('outputPathResolver', new PrettyOutputPathResolver());
$this->app->instance('outputPathResolver', new PrettyOutputPathResolver);
}

if ($this->input->getOption('quiet')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Events/EventBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function fire($event, Jigsaw $jigsaw)
if (is_callable($task)) {
$task($jigsaw);
} else {
(new $task())->handle($jigsaw);
(new $task)->handle($jigsaw);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/File/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function getFinder($directory, $match = [], $ignore = [], $ignore_dotf
$finder->notPath($this->getWildcardRegex($pattern));
});

return $finder;
return $finder->sortByName();
}

protected function getWildcardRegex($pattern)
Expand Down
2 changes: 1 addition & 1 deletion src/File/TemporaryFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TemporaryFilesystem
public function __construct($tempPath, $filesystem = null)
{
$this->tempPath = $tempPath;
$this->filesystem = $filesystem ?: new Filesystem();
$this->filesystem = $filesystem ?: new Filesystem;
}

public function buildTempPath($filename, $extension)
Expand Down
24 changes: 20 additions & 4 deletions src/PageVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function __call($method, $args)
public function getPath($key = null)
{
if (($key || $this->_meta->extending) && $this->_meta->path instanceof IterableObject) {
return $this->_meta->path->get($key ?: $this->getExtending());
return $this->enforceTrailingSlash($this->_meta->path->get($key ?: $this->getExtending()));
}

return (string) $this->_meta->path;
return $this->enforceTrailingSlash((string) $this->_meta->path);
}

public function getPaths()
Expand All @@ -46,10 +46,10 @@ public function getPaths()
public function getUrl($key = null)
{
if (($key || $this->_meta->extending) && $this->_meta->path instanceof IterableObject) {
return $this->_meta->url->get($key ?: $this->getExtending());
return $this->enforceTrailingSlash($this->_meta->url->get($key ?: $this->getExtending()));
}

return (string) $this->_meta->url;
return $this->enforceTrailingSlash((string) $this->_meta->url);
}

public function getUrls()
Expand All @@ -61,4 +61,20 @@ protected function missingHelperError($functionName)
{
return 'No function named "' . $functionName . '" was found in the file "config.php".';
}

protected function enforceTrailingSlash($path)
{
return $path && app()->config->get('trailing_slash') && ! $this->pathIsFile($path)
? Str::finish($path, '/')
: $path;
}

protected function pathIsFile($path)
{
$final_extension = $this->_meta->extending
? (Str::contains(Str::afterLast($path, '/'), '.') ? Str::afterLast($path, '.') : null)
: Str::afterLast($this->_meta->extension, '.');

return $final_extension && $final_extension !== 'md' && $final_extension !== 'php';
}
}
2 changes: 1 addition & 1 deletion src/Scaffold/PresetPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(DefaultInstaller $default, CustomInstaller $custom,
$this->defaultInstaller = $default;
$this->customInstaller = $custom;
$this->process = $process;
$this->files = new Filesystem();
$this->files = new Filesystem;
}

public function init($preset, PresetScaffoldBuilder $builder)
Expand Down
2 changes: 1 addition & 1 deletion src/SiteData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class SiteData extends IterableObject
{
public static function build(Collection $config)
{
$siteData = new static();
$siteData = new static;
$siteData->putIterable('collections', $config->get('collections'));
$siteData->putIterable('page', $config);

Expand Down
2 changes: 1 addition & 1 deletion src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function url(string $path): string
function dd(...$args)
{
foreach ($args as $x) {
(new VarDumper())->dump($x);
(new VarDumper)->dump($x);
}

exit(1);
Expand Down
2 changes: 1 addition & 1 deletion tests/CustomCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function custom_command_with_no_arguments()
{
$this->createSource([]);
$command = $this->app->make(CustomCommand::class);
$command->setApplication(new Application());
$command->setApplication(new Application);

$console = new CommandTester($command);
$console->execute([]);
Expand Down
72 changes: 36 additions & 36 deletions tests/CustomScaffoldInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class CustomScaffoldInstallerTest extends TestCase
public function custom_installer_installs_basic_scaffold_files()
{
$this->createSource([]);
$builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner);
$builder->setBase($this->tmp);

$this->assertCount(0, app('files')->filesAndDirectories($this->tmp));

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup();

$this->assertFileExists($this->tmpPath('source'));
Expand All @@ -36,10 +36,10 @@ public function custom_installer_installs_basic_scaffold_files()
public function installer_deletes_single_base_file_specified_in_delete_array()
{
$this->createSource([]);
$builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->delete('config.php');

Expand All @@ -51,10 +51,10 @@ public function installer_deletes_single_base_file_specified_in_delete_array()
public function installer_deletes_multiple_base_files_specified_in_delete_array()
{
$this->createSource([]);
$builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->delete([
'config.php',
Expand All @@ -70,10 +70,10 @@ public function installer_deletes_multiple_base_files_specified_in_delete_array(
public function installer_deletes_base_directories_specified_in_delete_array()
{
$this->createSource([]);
$builder = new PresetScaffoldBuilder(new Filesystem(), Mockery::mock(PresetPackage::class), new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, Mockery::mock(PresetPackage::class), new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->delete([
'source',
Expand All @@ -96,10 +96,10 @@ public function installer_copies_all_preset_files_if_copy_has_no_parameter()
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->copy();

Expand All @@ -122,10 +122,10 @@ public function installer_copies_individual_preset_file_if_copy_parameter_is_str
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->copy('preset-file.php');

Expand All @@ -148,10 +148,10 @@ public function installer_copies_multiple_preset_files_if_copy_parameter_is_arra
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->copy([
'preset-file.php',
Expand All @@ -175,10 +175,10 @@ public function installer_can_copy_files_using_a_wildcard()
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->copy([
'preset-file-*.php',
Expand All @@ -203,10 +203,10 @@ public function installer_can_call_copy_multiple_times()
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->copy('.dotfile')
->copy('source');
Expand Down Expand Up @@ -234,10 +234,10 @@ public function installer_copies_from_specified_directory_to_root_if_from_is_spe
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->from('themes/directory-2')
->copy();
Expand All @@ -260,10 +260,10 @@ public function installer_can_ignore_preset_files_when_copying()
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->ignore('.dotfile')
->copy();
Expand All @@ -287,10 +287,10 @@ public function installer_can_call_ignore_multiple_times()
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->ignore('.dotfile')
->ignore('preset-file.php')
Expand Down Expand Up @@ -318,10 +318,10 @@ public function original_composer_json_is_not_deleted()
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->delete('composer.json');

Expand Down Expand Up @@ -353,10 +353,10 @@ public function original_composer_json_is_merged_with_new_composer_json_after_co
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->copy();

Expand Down Expand Up @@ -400,10 +400,10 @@ public function composer_json_files_are_merged_when_copying_multiple_times()
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->copy()
->from('theme')
Expand Down Expand Up @@ -432,10 +432,10 @@ public function empty_composer_json_is_created_if_it_was_not_present_before_pres
]);
$package = Mockery::mock(PresetPackage::class);
$package->path = $this->tmp . '/package';
$builder = new PresetScaffoldBuilder(new Filesystem(), $package, new ProcessRunner());
$builder = new PresetScaffoldBuilder(new Filesystem, $package, new ProcessRunner);
$builder->setBase($this->tmp);

(new CustomInstaller())->install($builder)
(new CustomInstaller)->install($builder)
->setup()
->copy();

Expand All @@ -454,7 +454,7 @@ public function installer_can_ask_for_user_input()
$console = Mockery::spy(ConsoleSession::class);
$builder = Mockery::spy(PresetScaffoldBuilder::class);

(new CustomInstaller())->setConsole($console)
(new CustomInstaller)->setConsole($console)
->install($builder)
->setup()
->ask('What is your name?');
Expand All @@ -470,7 +470,7 @@ public function installer_can_ask_for_user_input_with_choices()
$console = Mockery::spy(ConsoleSession::class);
$builder = Mockery::spy(PresetScaffoldBuilder::class);

(new CustomInstaller())->setConsole($console)
(new CustomInstaller)->setConsole($console)
->install($builder)
->setup()
->ask(
Expand All @@ -495,7 +495,7 @@ public function installer_can_ask_for_user_confirmation()
$console = Mockery::spy(ConsoleSession::class);
$builder = Mockery::spy(PresetScaffoldBuilder::class);

(new CustomInstaller())->setConsole($console)
(new CustomInstaller)->setConsole($console)
->install($builder)
->setup()
->confirm('Continue?');
Expand All @@ -511,7 +511,7 @@ public function installer_runs_specified_commands_from_init()
$package = Mockery::mock(PresetPackage::class);
$builder = Mockery::spy(PresetScaffoldBuilder::class);

(new CustomInstaller())->setConsole(null)
(new CustomInstaller)->setConsole(null)
->install($builder)
->setup()
->run('yarn');
Expand Down
Loading