Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/Writing/HtmlWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Knuckles\Scribe\Writing;

use http\Exception\InvalidArgumentException;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Str;
use Knuckles\Camel\Output\OutputEndpointData;
Expand All @@ -28,7 +29,8 @@ public function __construct(?DocumentationConfig $config = null)
{
$this->config = $config ?: new DocumentationConfig(config('scribe', []));
$this->markdownParser = new MarkdownParser;
$this->baseUrl = $this->config->get('base_url') ?? config('app.url');
$baseUrl = $this->config->get('base_url') ?? config('app.url');
$this->baseUrl = Str::contains($baseUrl, ['{{', '{!!', '@']) ? Blade::render($baseUrl) : $baseUrl;
// If they're using the default static path,
// then use '../docs/{asset}', so assets can work via Laravel app or via index.html
$this->assetPathPrefix = '../docs/';
Expand Down
26 changes: 26 additions & 0 deletions tests/Unit/HtmlWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,30 @@ public function sets_last_updated_correctly()
$commit = mb_trim(shell_exec('git rev-parse --short HEAD'));
$this->assertEquals("Last updated on {$date} (Git commit {$commit})", $lastUpdated);
}

/** @test */
public function renders_blade_syntax_in_base_url()
{
config()->set('app.url', 'https://resolved.example.com');

$writer = new HtmlWriter(new DocumentationConfig([
'base_url' => "{{ config('app.url') }}/api",
'title' => 'API Docs',
]));

$baseUrl = (new \ReflectionClass($writer))->getProperty('baseUrl')->getValue($writer);
$this->assertEquals('https://resolved.example.com/api', $baseUrl);
}

/** @test */
public function leaves_plain_base_url_untouched()
{
$writer = new HtmlWriter(new DocumentationConfig([
'base_url' => 'https://plain.example.com',
'title' => 'API Docs',
]));

$baseUrl = (new \ReflectionClass($writer))->getProperty('baseUrl')->getValue($writer);
$this->assertEquals('https://plain.example.com', $baseUrl);
}
}