-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #270 from MotivoZwolle/feature/custom-markdown-par…
…ser-support Retrieve Markdown parser from Application
- Loading branch information
Showing
7 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace BinaryTorch\LaRecipe\Contracts; | ||
|
||
interface MarkdownParser | ||
{ | ||
/** | ||
* Parse the given source to Markdown, using your Markdown parser of choice. | ||
* | ||
* @param string $source | ||
* @return null|string|string[] | ||
*/ | ||
public function parse($source); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace BinaryTorch\LaRecipe\Services; | ||
|
||
use ParsedownExtra; | ||
use BinaryTorch\LaRecipe\Contracts\MarkdownParser; | ||
|
||
class ParseDownMarkdownParser implements MarkdownParser | ||
{ | ||
/** | ||
* Parse the given source to Markdown, using your Markdown parser of choice. | ||
* | ||
* @param string $source Markdown source contents | ||
* @return null|string|string[] HTML output | ||
*/ | ||
public function parse($source) | ||
{ | ||
return (new ParsedownExtra)->text($source); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace BinaryTorch\LaRecipe\Tests\Feature; | ||
|
||
use Illuminate\Support\Str; | ||
use Illuminate\Support\Facades\App; | ||
use Illuminate\Support\Facades\Config; | ||
use BinaryTorch\LaRecipe\Tests\TestCase; | ||
use BinaryTorch\LaRecipe\Contracts\MarkdownParser; | ||
use BinaryTorch\LaRecipe\Tests\Fixtures\HelloWorldMarkdownParser; | ||
|
||
class InterchangeableMarkdownParserTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function a_parser_is_accepted_as_long_as_the_contract_matches() | ||
{ | ||
// set the docs path and landing | ||
Config::set('larecipe.docs.path', 'tests/views/docs'); | ||
Config::set('larecipe.docs.landing', 'foo'); | ||
|
||
// set auth to false | ||
Config::set('larecipe.settings.auth', false); | ||
|
||
// Provide a dummy parser | ||
$randomId = (string) Str::uuid(); | ||
App::instance(MarkdownParser::class, new HelloWorldMarkdownParser($randomId)); | ||
|
||
// guest can view foo page | ||
$this->get('/docs/1.0') | ||
->assertViewHasAll([ | ||
'title', | ||
'index', | ||
'content', | ||
'currentVersion', | ||
'versions', | ||
'currentSection', | ||
'canonical' | ||
]) | ||
->assertSee("<h1>{$randomId}</h1>", false) | ||
->assertDontSee('<h1>Foo</h1>', false) | ||
->assertStatus(200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
namespace BinaryTorch\LaRecipe\Tests\Fixtures; | ||
|
||
use BinaryTorch\LaRecipe\Contracts\MarkdownParser; | ||
|
||
class HelloWorldMarkdownParser implements MarkdownParser | ||
{ | ||
private $suffix; | ||
|
||
public function __construct(string $suffix) | ||
{ | ||
$this->suffix = $suffix; | ||
} | ||
|
||
public function parse($source) | ||
{ | ||
return <<<HTML | ||
<h1>{$this->suffix}</h1> | ||
This is a test client, don't use in any other application! | ||
HTML; | ||
} | ||
} |