Skip to content

Commit

Permalink
Merge pull request #333 from hydephp/merge-markdown-facade-into-model
Browse files Browse the repository at this point in the history
Merge Markdown facade into model hydephp/develop@9c1fbd3
  • Loading branch information
github-actions committed Aug 4, 2022
1 parent 324fa7e commit 0cd8537
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/Contracts/AbstractMarkdownPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Hyde\Framework\Contracts;

use Hyde\Framework\Actions\SourceFileParser;
use Hyde\Framework\Facades\Markdown as MarkdownFacade;
use Hyde\Framework\Models\FrontMatter;
use Hyde\Framework\Models\Markdown;
use Hyde\Framework\Models\Markdown as MarkdownFacade;

/**
* The base class for all Markdown-based Page Models.
Expand Down
1 change: 1 addition & 0 deletions src/Facades/Includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Hyde\Framework\Contracts\IncludeFacadeContract;
use Hyde\Framework\Hyde;
use Hyde\Framework\Models\Markdown;
use Illuminate\Support\Facades\Blade;

class Includes implements IncludeFacadeContract
Expand Down
37 changes: 0 additions & 37 deletions src/Facades/Markdown.php

This file was deleted.

22 changes: 19 additions & 3 deletions src/Models/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Hyde\Framework\Models;

use Hyde\Framework\Facades\Markdown as MarkdownFacade;
use Hyde\Framework\Modules\Markdown\MarkdownConverter;
use Hyde\Framework\Services\MarkdownService;
use Illuminate\Contracts\Support\Arrayable;

/**
Expand All @@ -24,9 +25,9 @@ public static function fromFile(string $localFilepath): static
return MarkdownDocument::parseFile($localFilepath)->markdown();
}

public function render(): string
public function compile(): string
{
return MarkdownFacade::render($this->body);
return static::render($this->body);
}

public function __toString(): string
Expand All @@ -48,4 +49,19 @@ public function body(): string
{
return $this->body;
}

/**
* Render a Markdown string into HTML.
*
* If a source model is provided, the Markdown will be converted using the dynamic MarkdownService,
* otherwise, the pre-configured singleton from the service container will be used instead.
*
* @return string $html
*/
public static function render(string $markdown, ?string $sourceModel = null): string
{
return $sourceModel !== null
? (new MarkdownService($markdown, $sourceModel))->parse()
: app(MarkdownConverter::class)->convert($markdown);
}
}
2 changes: 1 addition & 1 deletion tests/Feature/Services/HydeSmartDocsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Hyde\Framework\Testing\Feature\Services;

use Hyde\Framework\Facades\Markdown;
use Hyde\Framework\Hyde;
use Hyde\Framework\Models\Markdown;
use Hyde\Framework\Models\Pages\DocumentationPage;
use Hyde\Framework\Services\HydeSmartDocs;
use Hyde\Testing\TestCase;
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/MarkdownDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function test_magic_to_string_method_returns_body()
public function test_render_method_returns_rendered_html()
{
$document = new MarkdownDocument([], 'Hello, world!');
$this->assertEquals("<p>Hello, world!</p>\n", $document->markdown->render());
$this->assertEquals("<p>Hello, world!</p>\n", $document->markdown->compile());
}

public function test_parse_method_parses_a_file_using_the_markdown_file_service()
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MarkdownFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Hyde\Framework\Testing\Unit;

use Hyde\Framework\Facades\Markdown;
use Hyde\Framework\Models\Markdown;
use Hyde\Testing\TestCase;

/**
* Class MarkdownConverterTest.
*
* @covers \Hyde\Framework\Facades\Markdown
* @covers \Hyde\Framework\Models\Markdown
*/
class MarkdownFacadeTest extends TestCase
{
Expand Down

0 comments on commit 0cd8537

Please sign in to comment.