Skip to content

Commit

Permalink
Merge pull request #546 from hydephp/develop
Browse files Browse the repository at this point in the history
Merge upcoming minor release
  • Loading branch information
caendesilva authored Jun 18, 2022
2 parents 8c6771f + f6c1c28 commit 13894ef
Show file tree
Hide file tree
Showing 104 changed files with 7,246 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ docker-compose.yml export-ignore
phpstan.src.neon.dist export-ignore
phpstan.types.neon.dist export-ignore
phpunit.xml.dist export-ignore

tests/ export-ignore
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<a href="https://packagist.org/packages/hyde/framework"><img style="display: inline; margin: 4px 2px;" src="https://img.shields.io/packagist/dt/hyde/framework" alt="Total Downloads on Packagist"></a>
<a href="https://github.com/hydephp/hyde/blob/master/LICENSE.md"> <img style="display: inline; margin: 4px 2px;" src="https://img.shields.io/github/license/hydephp/hyde" alt="License MIT"> </a>
<a href="https://hydephp.com/developer-tools/coverage-report/"><img style="display: inline; margin: 4px 2px;" src="https://cdn.desilva.se/microservices/coverbadges/badges/9b8f6a9a7a48a2df54e6751790bad8bd910015301e379f334d6ec74c4c3806d1.svg" alt="Test Coverage" title="Average coverage between categories"></a>
<a href="https://github.com/hydephp/develop/actions/workflows/test-build.yml"><img style="display: inline; margin: 4px 2px;" src="https://github.com/hydephp/develop/actions/workflows/test-build.yml/badge.svg" alt="Test Suite"></a>
<a href="https://github.com/hydephp/develop/actions/workflows/continuous-integration.yml"><img style="display: inline; margin: 4px 2px;" src="https://github.com/hydephp/develop/actions/workflows/continuous-integration.yml/badge.svg" alt="Test Suite"></a>
</p>


Expand Down Expand Up @@ -36,7 +36,7 @@ Hyde has already been featured in the [Laravel News Podcast](https://laravel-new
Heads up! HydePHP is very new and currently in beta. Please report any bugs and issues in the appropriate issue tracker. Versions in the 0.x series are not stable and may change at any time. No backwards compatibility guarantees are made and there will be breaking changes without notice.

Please wait until v1.0 for production use and remember to back up your source files before updating (use Git!).
See https://hydephp.com/docs/master/updating-hyde.html for the upgrade guide.
See https://hydephp.com/docs/master/updating-hyde for the upgrade guide.

## Resources

Expand Down
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
"Hyde\\Testing\\Framework\\": "tests/"
}
},
"authors": [
Expand All @@ -28,9 +28,6 @@
"spatie/yaml-front-matter": "^2.0.7",
"torchlight/torchlight-commonmark": "^0.5.5"
},
"require-dev": {
"phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.0"
},
"suggest": {
"hyde/hyde" : "The Framework package contains the Hyde Core. To create your site you should use the Hyde/Hyde project.",
"ext-simplexml": "Required to generate sitemaps and RSS feeds."
Expand Down
4 changes: 3 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ protected function registerBaseBindings(): void
*/
$this->app->singleton(PackageManifest::class, function () {
return new PackageManifest(
new Filesystem, $this->basePath(), $this->basePath('storage/framework/cache/packages.php')
new Filesystem,
$this->basePath(),
$this->basePath('storage/framework/cache/packages.php')
);
});
}
Expand Down
16 changes: 9 additions & 7 deletions src/Commands/HydeBuildSearchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ protected function createSearchPage(): void
$actionTime = microtime(true);

$this->comment('Generating search page...');
file_put_contents(Hyde::path('_site/'.config('docs.output_directory', 'docs').'/search.html'),
view('hyde::layouts.docs')->with([
'page' => new DocumentationPage([], '', 'Search', 'search'),
'title' => 'Search',
'markdown' => view('hyde::pages.documentation-search')->render(),
'currentPage' => ''.config('docs.output_directory', 'docs').'/search',
])->render());
file_put_contents(
Hyde::path('_site/'.config('docs.output_directory', 'docs').'/search.html'),
view('hyde::layouts.docs')->with([
'page' => new DocumentationPage([], '', 'Search', 'search'),
'title' => 'Search',
'markdown' => view('hyde::pages.documentation-search')->render(),
'currentPage' => ''.config('docs.output_directory', 'docs').'/search',
])->render()
);

$this->line(' > Created <info>_site/'.config('docs.output_directory', 'docs').'/search.html</> in '.
$this->getExecutionTimeInMs($actionTime)."ms\n");
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/HydeBuildStaticSiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ protected function printFinishMessage(float $time_start): void
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
$this->info('All done! Finished in '.number_format(
$execution_time,
2
).' seconds. ('.number_format(($execution_time * 1000), 2).'ms)');
$execution_time,
2
).' seconds. ('.number_format(($execution_time * 1000), 2).'ms)');

$this->info('Congratulations! 🎉 Your static site has been built!');
$this->line(
Expand Down
6 changes: 4 additions & 2 deletions src/Concerns/Internal/FluentPathHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public static function getSiteOutputPath(string $path = ''): string
public static function pathToRelative(string $path): string
{
return str_starts_with($path, static::path()) ? trim(str_replace(
static::path(), '', $path), '/\\'
) : $path;
static::path(),
'',
$path
), '/\\') : $path;
}
}
5 changes: 3 additions & 2 deletions src/Helpers/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public static function property(string $property, string $content): string

public static function render(array $overridesGlobalMeta = []): string
{
return implode("\n",
static::filterUnique(
return implode(
"\n",
static::filterUnique(
array_merge(
static::getGlobalMeta(),
$overridesGlobalMeta
Expand Down
3 changes: 2 additions & 1 deletion src/HydeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function () {
$this->discoverBladeViewsIn('_pages');

$this->storeCompiledSiteIn(config(
'hyde.site_output_path', Hyde::path('_site')
'hyde.site_output_path',
Hyde::path('_site')
));

$this->commands([
Expand Down
3 changes: 2 additions & 1 deletion src/Services/HydeSmartDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ protected function addDynamicFooterContent(): self

protected function renderSourceLink(): string
{
return sprintf('<p class="edit-page-link"><a href="%s">%s</a></p>',
return sprintf(
'<p class="edit-page-link"><a href="%s">%s</a></p>',
$this->page->getOnlineSourcePath(),
config('docs.edit_source_link_text', 'Edit page')
);
Expand Down
9 changes: 6 additions & 3 deletions src/Services/Markdown/CodeblockFilepathProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public static function preprocess(string $markdown): string
if (static::lineMatchesPattern($line) && ! str_contains($line, '{"shortcodes": false}')) {
// Add the meta-block two lines before the pattern, placing it just above the code block.
// This prevents the meta-block from interfering with other processes.
$lines[$index - 2] .= sprintf("\n<!-- HYDE[Filepath]%s -->",
$lines[$index - 2] .= sprintf(
"\n<!-- HYDE[Filepath]%s -->",
trim(str_replace(static::$patterns, '', $line))
);

Expand Down Expand Up @@ -78,8 +79,10 @@ protected static function lineMatchesPattern(string $line): bool
protected static function trimHydeDirective(string $line): string
{
return trim(str_replace('-->', '', str_replace(
'<!-- HYDE[Filepath]', '', $line))
);
'<!-- HYDE[Filepath]',
'',
$line
)));
}

protected static function resolveTemplate(string $path, string $line): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public static function resolve(string $input): string

protected static function expand(string $input): string
{
return sprintf('<blockquote class="%s">%s</blockquote>',
return sprintf(
'<blockquote class="%s">%s</blockquote>',
static::getClassNameFromSignature(static::signature()),
trim(substr($input, strlen(static::signature())), ' ')
);
Expand Down
9 changes: 6 additions & 3 deletions src/Services/RssFeedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ protected function addAdditionalChannelData(): void
protected function getDescription(): string
{
return static::xmlEscape(
config('hyde.rss_description',
static::getTitle().' RSS Feed')
config(
'hyde.rss_description',
static::getTitle().' RSS Feed'
)
);
}

Expand All @@ -120,7 +122,8 @@ public static function getLink(): string
{
return static::xmlEscape(
rtrim(
config('hyde.site_url') ?? 'http://localhost', '/'
config('hyde.site_url') ?? 'http://localhost',
'/'
)
);
}
Expand Down
53 changes: 53 additions & 0 deletions tests/Feature/Actions/ChecksIfConfigIsUpToDateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Hyde\Testing\Framework\Feature\Actions;

use Hyde\Framework\Actions\ChecksIfConfigIsUpToDate;
use Hyde\Testing\TestCase;

/**
* @covers \Hyde\Framework\Actions\ChecksIfConfigIsUpToDate
*/
class ChecksIfConfigIsUpToDateTest extends TestCase
{
public function test_it_returns_true_if_config_is_up_to_date()
{
$action = new ChecksIfConfigIsUpToDate();

$action->hydeConfig = $this->makeConfig();
$action->frameworkConfig = $this->makeConfig();

$this->assertTrue($action->execute());
}

public function test_it_returns_false_if_config_is_not_up_to_date()
{
$action = new ChecksIfConfigIsUpToDate();

$action->hydeConfig = $this->makeConfig();
$action->frameworkConfig = 'foo';

$this->assertFalse($action->execute());
}

protected function makeConfig(): string
{
return <<<'EOF'
<?php return [
/*
|--------------------------------------------------------------------------
| Foo Bar
|--------------------------------------------------------------------------
|
*/
/*
|--------------------------------------------------------------------------
| Second Option
|--------------------------------------------------------------------------
|
*/
];
EOF;
}
}
143 changes: 143 additions & 0 deletions tests/Feature/Actions/CreatesNewPageSourceFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

namespace Hyde\Testing\Framework\Feature\Actions;

use Hyde\Framework\Actions\CreatesNewPageSourceFile;
use Hyde\Framework\Exceptions\FileConflictException;
use Hyde\Framework\Exceptions\UnsupportedPageTypeException;
use Hyde\Framework\Hyde;
use Hyde\Framework\Models\BladePage;
use Hyde\Framework\Models\DocumentationPage;
use Hyde\Testing\TestCase;

/**
* @covers \Hyde\Framework\Actions\CreatesNewPageSourceFile
*/
class CreatesNewPageSourceFileTest extends TestCase
{
protected function tearDown(): void
{
if (file_exists(Hyde::path('_pages/682072b-test-page.md'))) {
unlink(Hyde::path('_pages/682072b-test-page.md'));
}

if (file_exists(Hyde::path('_pages/682072b-test-page.blade.php'))) {
unlink(Hyde::path('_pages/682072b-test-page.blade.php'));
}

parent::tearDown();
}

public function test_class_can_be_instantiated()
{
$this->assertInstanceOf(
CreatesNewPageSourceFile::class,
new CreatesNewPageSourceFile('682072b Test Page')
);
}

public function test_that_a_slug_is_generated_from_the_title()
{
$this->assertEquals(
'682072b-test-page',
(new CreatesNewPageSourceFile('682072b Test Page'))->slug
);
}

public function test_that_an_exception_is_thrown_for_invalid_page_type()
{
$this->expectException(UnsupportedPageTypeException::class);
$this->expectExceptionMessage('The page type must be either "markdown", "blade", or "documentation"');

(new CreatesNewPageSourceFile('682072b Test Page', 'invalid'));
}

public function test_that_an_exception_is_thrown_if_file_already_exists_and_overwrite_is_false()
{
$path = Hyde::path('_pages/foo.md');
file_put_contents($path, 'foo');

$this->expectException(FileConflictException::class);
$this->expectExceptionMessage("File already exists: $path");
$this->expectExceptionCode(409);

new CreatesNewPageSourceFile('foo');

unlink($path);
}

public function test_that_can_save_file_returns_true_if_file_already_exists_and_overwrite_is_true()
{
$path = Hyde::path('_pages/foo.md');
file_put_contents($path, 'foo');

new CreatesNewPageSourceFile('foo', force: true);

$this->assertTrue(true);
unlink($path);
}

public function test_that_a_markdown_file_can_be_created_and_contains_expected_content()
{
(new CreatesNewPageSourceFile('682072b Test Page'));

$this->assertFileExists(
Hyde::path('_pages/682072b-test-page.md')
);

$this->assertEquals(
"---\ntitle: 682072b Test Page\n---\n\n# 682072b Test Page\n",
file_get_contents(Hyde::path('_pages/682072b-test-page.md'))
);
}

public function test_that_a_blade_file_can_be_created_and_contains_expected_content()
{
(new CreatesNewPageSourceFile('682072b Test Page', BladePage::class));

$this->assertFileExists(
Hyde::path('_pages/682072b-test-page.blade.php')
);

$fileContent = file_get_contents(Hyde::path('_pages/682072b-test-page.blade.php'));
$this->assertStringContainsString(
'@extends(\'hyde::layouts.app\')',
$fileContent
);
$this->assertStringContainsString(
'@php($title = "682072b Test Page")',
$fileContent
);
$this->assertStringContainsString(
'<h1 class="text-center text-3xl font-bold">682072b Test Page</h1>',
$fileContent
);
}

public function test_that_a_documentation_file_can_be_created_and_contains_expected_content()
{
(new CreatesNewPageSourceFile('682072b Test Page', DocumentationPage::class));

$this->assertFileExists(
Hyde::path('_docs/682072b-test-page.md')
);

$this->assertEquals(
"# 682072b Test Page\n",
file_get_contents(Hyde::path('_docs/682072b-test-page.md'))
);
}

public function test_that_the_file_path_can_be_returned()
{
$this->assertEquals(
Hyde::path('_pages/682072b-test-page.md'),
(new CreatesNewPageSourceFile('682072b Test Page'))->outputPath
);

$this->assertEquals(
Hyde::path('_pages/682072b-test-page.blade.php'),
(new CreatesNewPageSourceFile('682072b Test Page', BladePage::class))->outputPath
);
}
}
Loading

0 comments on commit 13894ef

Please sign in to comment.