From 4fd2a2645ab26eb24f6dc0f8777fd05275e92fd4 Mon Sep 17 00:00:00 2001 From: shalvah Date: Fri, 21 Apr 2023 14:51:56 +0200 Subject: [PATCH 1/2] Internationalization: Extract strings --- lang/en.json | 32 +++++++++++++++++++ resources/js/tryitout.js | 5 ++- resources/views/markdown/auth.blade.php | 4 +-- resources/views/markdown/intro.blade.php | 4 +-- .../views/themes/default/endpoint.blade.php | 32 +++++++++---------- .../views/themes/default/sidebar.blade.php | 6 ++-- .../views/themes/elements/endpoint.blade.php | 18 +++++------ .../themes/elements/try_it_out.blade.php | 2 +- src/Extracting/ApiDetails.php | 30 +++++++---------- src/ScribeServiceProvider.php | 5 +++ src/Writing/HtmlWriter.php | 4 +-- .../Responses/UseApiResourceTagsTest.php | 7 +--- .../Responses/UseResponseAttributesTest.php | 4 +-- tests/Unit/HtmlWriterTest.php | 4 +-- 14 files changed, 92 insertions(+), 65 deletions(-) create mode 100644 lang/en.json diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 00000000..2765e705 --- /dev/null +++ b/lang/en.json @@ -0,0 +1,32 @@ +{ + "scribe::auth.instruction.query": "To authenticate requests, include a query parameter **`:parameterName`** in the request.", + "scribe::auth.instruction.body": "To authenticate requests, include a parameter **`:parameterName`** in the body of the request.", + "scribe::auth.instruction.query_or_body": "To authenticate requests, include a parameter **`:parameterName`** either in the query string or in the request body.", + "scribe::auth.instruction.bearer": "To authenticate requests, include an **`Authorization`** header with the value **`\"Bearer :placeholder\"`**.", + "scribe::auth.instruction.basic": "To authenticate requests, include an **`Authorization`** header in the form **`\"Basic {credentials}\"`**. The value of `{credentials}` should be your username/id and your password, joined with a colon (:), and then base64-encoded.", + "scribe::auth.instruction.header": "To authenticate requests, include a **`:parameterName`** header with the value **`\":placeholder\"`**.", + "scribe::auth.details": "All authenticated endpoints are marked with a `requires authentication` badge in the documentation below.", + "scribe::search": "Search", + "scribe::base_url": "Base URL", + "scribe::headers.introduction": "Introduction", + "scribe::headers.auth": "Authenticating requests", + "scribe::no_auth": "This API is not authenticated.", + "scribe::example_request": "Example request", + "scribe::example_response": "Example response", + "scribe::example_response.binary": "Binary data", + "scribe::example_response.empty": "Empty response", + "scribe::endpoint.request": "Request", + "scribe::endpoint.headers": "Headers", + "scribe::endpoint.url_parameters": "URL Parameters", + "scribe::endpoint.body_parameters": "Body Parameters", + "scribe::endpoint.query_parameters": "Query Parameters", + "scribe::endpoint.response": "Response", + "scribe::endpoint.response_fields": "Response Fields", + "scribe::try_it_out.open": "Try it out ⚡", + "scribe::try_it_out.cancel": "Cancel 🛑", + "scribe::try_it_out.send": "Send Request 💥", + "scribe::try_it_out.received_response": "Received response", + "scribe::try_it_out.request_failed": "Request failed with error", + "scribe::links.postman": "View Postman collection", + "scribe::links.openapi": "View OpenAPI spec" +} diff --git a/resources/js/tryitout.js b/resources/js/tryitout.js index b618617d..21ee28e7 100644 --- a/resources/js/tryitout.js +++ b/resources/js/tryitout.js @@ -38,8 +38,9 @@ function getCookie(name) { function tryItOut(endpointId) { document.querySelector(`#btn-tryout-${endpointId}`).hidden = true; - document.querySelector(`#btn-executetryout-${endpointId}`).hidden = false; document.querySelector(`#btn-canceltryout-${endpointId}`).hidden = false; + const executeBtn = document.querySelector(`#btn-executetryout-${endpointId}`).hidden = false; + executeBtn.disabled = false; // Show all input fields document.querySelectorAll(`input[data-endpoint=${endpointId}],label[data-endpoint=${endpointId}]`) @@ -177,6 +178,7 @@ function handleError(endpointId, err) { async function executeTryOut(endpointId, form) { const executeBtn = document.querySelector(`#btn-executetryout-${endpointId}`); executeBtn.textContent = "⏱ Sending..."; + executeBtn.disabled = true; executeBtn.scrollIntoView({behavior: "smooth", block: "center"}); let body; @@ -266,6 +268,7 @@ async function executeTryOut(endpointId, form) { handleError(endpointId, err); }) .finally(() => { + executeBtn.disabled = false; executeBtn.textContent = "Send Request 💥"; }); } diff --git a/resources/views/markdown/auth.blade.php b/resources/views/markdown/auth.blade.php index 3117dccd..3bc8d96e 100644 --- a/resources/views/markdown/auth.blade.php +++ b/resources/views/markdown/auth.blade.php @@ -1,7 +1,7 @@ -# Authenticating requests +# {{ __("scribe::headers.auth") }} @if(!$isAuthed) -This API is not authenticated. +{!! __("scribe::no_auth") !!} @else {!! $authDescription !!} diff --git a/resources/views/markdown/intro.blade.php b/resources/views/markdown/intro.blade.php index 9386e70c..febe2b99 100644 --- a/resources/views/markdown/intro.blade.php +++ b/resources/views/markdown/intro.blade.php @@ -1,9 +1,9 @@ -# Introduction +# {{ __("scribe::headers.introduction") }} {!! $description !!} {!! $introText !!} diff --git a/resources/views/themes/default/endpoint.blade.php b/resources/views/themes/default/endpoint.blade.php index 1765d184..d6874602 100644 --- a/resources/views/themes/default/endpoint.blade.php +++ b/resources/views/themes/default/endpoint.blade.php @@ -12,7 +12,7 @@ {!! Parsedown::instance()->text($endpoint->metadata->description ?: '') !!} -
Example request:
+
{{ __("scribe::example_request") }}:
@foreach($metadata['example_languages'] as $language) @@ -27,7 +27,7 @@ @if($endpoint->isGet() || $endpoint->hasResponses()) @foreach($endpoint->responses as $response)
-

Example response ({{ $response->fullDescription() }}):

+

{{ __("scribe::example_response") }} ({{ $response->fullDescription() }}):

@if(count($response->headers))
@@ -39,9 +39,9 @@ @endforeach
@endif
 @if(is_string($response->content) && Str::startsWith($response->content, "<>"))
-[Binary data] - {{ htmlentities(str_replace("<>", "", $response->content)) }}
+{!! __("scribe::example_response.binary") !!} - {{ htmlentities(str_replace("<>", "", $response->content)) }}
 @elseif($response->status == 204)
-[Empty response]
+{!! __("scribe::example_response.empty") !!}
 @else
 @php($parsed = json_decode($response->content))
 {{-- If response is a JSON string, prettify it. Otherwise, just print it --}}
@@ -51,13 +51,13 @@
 @endif
 
 
 
 

- Request    + {{ __("scribe::endpoint.request") }}    @if($metadata['try_it_out']['enabled'] ?? false)    @endif

@@ -93,7 +93,7 @@

@endforeach @if(count($endpoint->headers)) -

Headers

+

{{ __("scribe::endpoint.headers") }}

@foreach($endpoint->headers as $name => $example) urlParameters)) -

URL Parameters

+

{{ __("scribe::endpoint.url_parameters") }}

@foreach($endpoint->urlParameters as $attribute => $parameter)
@component('scribe::components.field-details', [ @@ -136,7 +136,7 @@ @endforeach @endif @if(count($endpoint->queryParameters)) -

Query Parameters

+

{{ __("scribe::endpoint.query_parameters") }}

@foreach($endpoint->queryParameters as $attribute => $parameter) nestedBodyParameters)) -

Body Parameters

+

{{ __("scribe::endpoint.body_parameters") }}

@@ -169,8 +169,8 @@ @if(count($endpoint->responseFields)) -

Response

-

Response Fields

+

{{ __("scribe::endpoint.response") }}

+

{{ __("scribe::endpoint.response_fields") }}

- +
@@ -52,10 +52,10 @@ diff --git a/resources/views/themes/elements/endpoint.blade.php b/resources/views/themes/elements/endpoint.blade.php index 1e3502b4..d3757cbd 100644 --- a/resources/views/themes/elements/endpoint.blade.php +++ b/resources/views/themes/elements/endpoint.blade.php @@ -48,7 +48,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') } @if(count($endpoint->headers))

- Headers + {{ __("scribe::endpoint.headers") }}

@foreach($endpoint->headers as $header => $value) @@ -70,7 +70,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') } @if(count($endpoint->urlParameters))
-

URL Parameters

+

{{ __("scribe::endpoint.url_parameters") }}

@foreach($endpoint->urlParameters as $attribute => $parameter) @@ -93,7 +93,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') } @if(count($endpoint->queryParameters))
-

Query Parameters

+

{{ __("scribe::endpoint.query_parameters") }}

@foreach($endpoint->queryParameters as $attribute => $parameter) @@ -115,7 +115,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') } @if(count($endpoint->nestedBodyParameters))
-

Body Parameters

+

{{ __("scribe::endpoint.body_parameters") }}

@component('scribe::themes.elements.components.nested-fields', [ @@ -129,7 +129,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') } @if(count($endpoint->responseFields))
-

Response Fields

+

{{ __("scribe::endpoint.response_fields") }}

@component('scribe::themes.elements.components.nested-fields', [ @@ -157,7 +157,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
- Request sample: + {{ __("scribe::example_request") }}: @endif @if(is_string($response->content) && Str::startsWith($response->content, "<>")) -
[Binary data] - {{ htmlentities(str_replace("<>", "", $response->content)) }}
+
[{{ __("scribe::example_response.binary") }}] - {{ htmlentities(str_replace("<>", "", $response->content)) }}
@elseif($response->status == 204) -
[Empty response]
+
[{{ __("scribe::example_response.empty") }}]
@else @php($parsed = json_decode($response->content)) {{-- If response is a JSON string, prettify it. Otherwise, just print it --}} diff --git a/resources/views/themes/elements/try_it_out.blade.php b/resources/views/themes/elements/try_it_out.blade.php index c11868b7..284ec2d9 100644 --- a/resources/views/themes/elements/try_it_out.blade.php +++ b/resources/views/themes/elements/try_it_out.blade.php @@ -260,7 +260,7 @@ class="sl-relative sl-w-full sl-h-md sl-text-base sl-pr-2.5 sl-pl-2.5 sl-rounded
diff --git a/src/Extracting/ApiDetails.php b/src/Extracting/ApiDetails.php index c0d13bd6..9c2995f3 100644 --- a/src/Extracting/ApiDetails.php +++ b/src/Extracting/ApiDetails.php @@ -2,7 +2,7 @@ namespace Knuckles\Scribe\Extracting; -use Knuckles\Scribe\Tools\ConsoleOutputUtils; +use Knuckles\Scribe\Tools\ConsoleOutputUtils as c; use Knuckles\Scribe\Tools\DocumentationConfig; /** @@ -36,7 +36,7 @@ public function __construct(DocumentationConfig $config = null, bool $preserveUs public function writeMarkdownFiles(): void { - ConsoleOutputUtils::info('Extracting intro and auth Markdown files to: ' . $this->markdownOutputPath); + c::info('Extracting intro and auth Markdown files to: ' . $this->markdownOutputPath); if (!is_dir($this->markdownOutputPath)) { mkdir($this->markdownOutputPath, 0777, true); @@ -49,7 +49,7 @@ public function writeMarkdownFiles(): void $this->writeContentsTrackingFile(); - ConsoleOutputUtils::success('Extracted intro and auth Markdown files to: ' . $this->markdownOutputPath); + c::success('Extracted intro and auth Markdown files to: ' . $this->markdownOutputPath); } public function writeIntroMarkdownFile(): void @@ -57,11 +57,11 @@ public function writeIntroMarkdownFile(): void $introMarkdownFile = $this->markdownOutputPath . '/intro.md'; if ($this->hasFileBeenModified($introMarkdownFile)) { if ($this->preserveUserChanges) { - ConsoleOutputUtils::warn("Skipping modified file $introMarkdownFile"); + c::warn("Skipping modified file $introMarkdownFile"); return; } - ConsoleOutputUtils::warn("Discarding manual changes for file $introMarkdownFile because you specified --force"); + c::warn("Discarding manual changes for file $introMarkdownFile because you specified --force"); } $introMarkdown = view('scribe::markdown.intro') @@ -76,11 +76,11 @@ public function writeAuthMarkdownFile(): void $authMarkdownFile = $this->markdownOutputPath . '/auth.md'; if ($this->hasFileBeenModified($authMarkdownFile)) { if ($this->preserveUserChanges) { - ConsoleOutputUtils::warn("Skipping modified file $authMarkdownFile"); + c::warn("Skipping modified file $authMarkdownFile"); return; } - ConsoleOutputUtils::warn("Discarding manual changes for file $authMarkdownFile because you specified --force"); + c::warn("Discarding manual changes for file $authMarkdownFile because you specified --force"); } $isAuthed = $this->config->get('auth.enabled', false); @@ -90,17 +90,11 @@ public function writeAuthMarkdownFile(): void if ($isAuthed) { $strategy = $this->config->get('auth.in'); $parameterName = $this->config->get('auth.name'); - $authDescription = "To authenticate requests, include "; - $authDescription .= match ($strategy) { - 'query' => "a query parameter **`$parameterName`** in the request.", - 'body' => "a parameter **`$parameterName`** in the body of the request.", - 'query_or_body' => "a parameter **`$parameterName`** either in the query string or in the request body.", - 'bearer' => sprintf('an **`Authorization`** header with the value **`"Bearer %s"`**.', $this->config->get('auth.placeholder') ?: 'your-token'), - 'basic' => "an **`Authorization`** header in the form **`\"Basic {credentials}\"`**. The value of `{credentials}` should be your username/id and your password, joined with a colon (:), and then base64-encoded.", - 'header' => sprintf('a **`%s`** header with the value **`"%s"`**.', $parameterName, $this->config->get('auth.placeholder') ?: 'your-token'), - default => '', - }; - $authDescription .= "\n\nAll authenticated endpoints are marked with a `requires authentication` badge in the documentation below."; + $authDescription = __("scribe::auth.instruction.$strategy", [ + 'parameterName' => $parameterName, + 'placeholder' => $this->config->get('auth.placeholder') ?: 'your-token'] + ); + $authDescription .= "\n\n".__("scribe::auth.details"); $extraInfo = $this->config->get('auth.extra_info', ''); } diff --git a/src/ScribeServiceProvider.php b/src/ScribeServiceProvider.php index 7f6a7b8b..f7d5ac23 100644 --- a/src/ScribeServiceProvider.php +++ b/src/ScribeServiceProvider.php @@ -24,6 +24,11 @@ public function boot() $this->registerCommands(); + $this->loadJsonTranslationsFrom(__DIR__.'/../lang'); + $this->publishes([ + __DIR__.'/../lang' => $this->app->langPath('vendor/scribe'), + ], 'scribe-translations'); + // Bind the route matcher implementation $this->app->bind(RouteMatcherInterface::class, config('scribe.routeMatcher', RouteMatcher::class)); diff --git a/src/Writing/HtmlWriter.php b/src/Writing/HtmlWriter.php index 0f6f3a17..d1f52160 100644 --- a/src/Writing/HtmlWriter.php +++ b/src/Writing/HtmlWriter.php @@ -112,11 +112,11 @@ public function getMetadata(): array // NB:These paths are wrong for laravel type but will be set correctly by the Writer class if ($this->config->get('postman.enabled', true)) { - $links[] = "assetPathPrefix}collection.json\">View Postman collection"; + $links[] = "assetPathPrefix}collection.json\">".__("scribe::links.postman").""; $postmanCollectionUrl = "{$this->assetPathPrefix}collection.json"; } if ($this->config->get('openapi.enabled', false)) { - $links[] = "assetPathPrefix}openapi.yaml\">View OpenAPI spec"; + $links[] = "assetPathPrefix}openapi.yaml\">".__("scribe::links.openapi").""; $openApiSpecUrl = "{$this->assetPathPrefix}openapi.yaml"; } diff --git a/tests/Strategies/Responses/UseApiResourceTagsTest.php b/tests/Strategies/Responses/UseApiResourceTagsTest.php index 7e8d1257..abe8bf33 100644 --- a/tests/Strategies/Responses/UseApiResourceTagsTest.php +++ b/tests/Strategies/Responses/UseApiResourceTagsTest.php @@ -23,12 +23,7 @@ class UseApiResourceTagsTest extends BaseLaravelTest protected function getPackageProviders($app) { - $providers = [ - ScribeServiceProvider::class, - ]; - if (class_exists(\Dingo\Api\Provider\LaravelServiceProvider::class)) { - $providers[] = \Dingo\Api\Provider\LaravelServiceProvider::class; - } + $providers = parent::getPackageProviders($app); if (class_exists(\Illuminate\Database\Eloquent\LegacyFactoryServiceProvider::class)) { $providers[] = \Illuminate\Database\Eloquent\LegacyFactoryServiceProvider ::class; } diff --git a/tests/Strategies/Responses/UseResponseAttributesTest.php b/tests/Strategies/Responses/UseResponseAttributesTest.php index aea687ec..2734bb45 100644 --- a/tests/Strategies/Responses/UseResponseAttributesTest.php +++ b/tests/Strategies/Responses/UseResponseAttributesTest.php @@ -28,9 +28,7 @@ class UseResponseAttributesTest extends BaseLaravelTest protected function getPackageProviders($app) { - $providers = [ - ScribeServiceProvider::class, - ]; + $providers = parent::getPackageProviders($app); if (class_exists(\Illuminate\Database\Eloquent\LegacyFactoryServiceProvider::class)) { $providers[] = \Illuminate\Database\Eloquent\LegacyFactoryServiceProvider ::class; } diff --git a/tests/Unit/HtmlWriterTest.php b/tests/Unit/HtmlWriterTest.php index 741f3211..3b04315d 100644 --- a/tests/Unit/HtmlWriterTest.php +++ b/tests/Unit/HtmlWriterTest.php @@ -2,11 +2,11 @@ namespace Knuckles\Scribe\Tests\Unit; +use Knuckles\Scribe\Tests\BaseLaravelTest; use Knuckles\Scribe\Tools\DocumentationConfig; use Knuckles\Scribe\Writing\HtmlWriter; -use PHPUnit\Framework\TestCase; -class HtmlWriterTest extends TestCase +class HtmlWriterTest extends BaseLaravelTest { /** @test */ public function sets_last_updated_correctly() From 55eb9a589827a833dc9e1c08b996e379af880e2b Mon Sep 17 00:00:00 2001 From: shalvah Date: Sat, 22 Apr 2023 20:27:37 +0200 Subject: [PATCH 2/2] Internationalization: Extract JS-set strings --- lang/en.json | 2 ++ resources/js/tryitout.js | 18 +++++++-------- .../views/themes/default/endpoint.blade.php | 10 ++++++--- .../views/themes/default/index.blade.php | 2 +- .../views/themes/elements/index.blade.php | 8 +++---- .../themes/elements/try_it_out.blade.php | 22 ++++++------------- 6 files changed, 29 insertions(+), 33 deletions(-) diff --git a/lang/en.json b/lang/en.json index 2765e705..2a8afc8e 100644 --- a/lang/en.json +++ b/lang/en.json @@ -25,8 +25,10 @@ "scribe::try_it_out.open": "Try it out ⚡", "scribe::try_it_out.cancel": "Cancel 🛑", "scribe::try_it_out.send": "Send Request 💥", + "scribe::try_it_out.loading": "⏱ Sending...", "scribe::try_it_out.received_response": "Received response", "scribe::try_it_out.request_failed": "Request failed with error", + "scribe::try_it_out.error_help": "Tip: Check that you're properly connected to the network.\nIf you're a maintainer of ths API, verify that your API is running and you've enabled CORS.\nYou can check the Dev Tools console for debugging information.", "scribe::links.postman": "View Postman collection", "scribe::links.openapi": "View OpenAPI spec" } diff --git a/resources/js/tryitout.js b/resources/js/tryitout.js index 21ee28e7..a3feb1bd 100644 --- a/resources/js/tryitout.js +++ b/resources/js/tryitout.js @@ -64,7 +64,7 @@ function cancelTryOut(endpointId) { document.querySelector(`#btn-tryout-${endpointId}`).hidden = false; const executeBtn = document.querySelector(`#btn-executetryout-${endpointId}`); executeBtn.hidden = true; - executeBtn.textContent = "Send Request 💥"; + executeBtn.textContent = executeBtn.dataset.initialText; document.querySelector(`#btn-canceltryout-${endpointId}`).hidden = true; // Hide inputs document.querySelectorAll(`input[data-endpoint=${endpointId}],label[data-endpoint=${endpointId}]`) @@ -89,7 +89,7 @@ function makeAPICall(method, path, body = {}, query = {}, headers = {}, endpoint body = JSON.stringify(body) } - const url = new URL(window.baseUrl + '/' + path.replace(/^\//, '')); + const url = new URL(window.tryItOutBaseUrl + '/' + path.replace(/^\//, '')); // We need this function because if you try to set an array or object directly to a URLSearchParams object, // you'll get [object Object] or the array.toString() @@ -119,7 +119,7 @@ function makeAPICall(method, path, body = {}, query = {}, headers = {}, endpoint headers, body: method === 'GET' ? undefined : body, signal: window.abortControllers[endpointId].signal, - referrer: window.baseUrl, + referrer: window.tryItOutBaseUrl, mode: 'cors', credentials: 'same-origin', }) @@ -150,7 +150,7 @@ function handleResponse(endpointId, response, status, headers) { } catch (e) { } - responseContentEl.textContent = response === '' ? '' : response; + responseContentEl.textContent = response === '' ? responseContentEl.dataset.emptyResponseText : response; isJson && window.hljs.highlightElement(responseContentEl); const statusEl = document.querySelector('#execution-response-status-' + endpointId); statusEl.textContent = ` (${status})`; @@ -165,10 +165,8 @@ function handleError(endpointId, err) { // Show error views let errorMessage = err.message || err; - errorMessage += "\n\nTip: Check that you're properly connected to the network."; - errorMessage += "\nIf you're a maintainer of ths API, verify that your API is running and you've enabled CORS."; - errorMessage += "\nYou can check the Dev Tools console for debugging information."; - document.querySelector('#execution-error-message-' + endpointId).textContent = errorMessage; + const $errorMessageEl = document.querySelector('#execution-error-message-' + endpointId); + $errorMessageEl.textContent = errorMessage + $errorMessageEl.textContent; const errorEl = document.querySelector('#execution-error-' + endpointId); errorEl.hidden = false; errorEl.scrollIntoView({behavior: "smooth", block: "center"}); @@ -177,7 +175,7 @@ function handleError(endpointId, err) { async function executeTryOut(endpointId, form) { const executeBtn = document.querySelector(`#btn-executetryout-${endpointId}`); - executeBtn.textContent = "⏱ Sending..."; + executeBtn.textContent = executeBtn.dataset.loadingText; executeBtn.disabled = true; executeBtn.scrollIntoView({behavior: "smooth", block: "center"}); @@ -269,6 +267,6 @@ async function executeTryOut(endpointId, form) { }) .finally(() => { executeBtn.disabled = false; - executeBtn.textContent = "Send Request 💥"; + executeBtn.textContent = executeBtn.dataset.initialText; }); } diff --git a/resources/views/themes/default/endpoint.blade.php b/resources/views/themes/default/endpoint.blade.php index d6874602..faff5037 100644 --- a/resources/views/themes/default/endpoint.blade.php +++ b/resources/views/themes/default/endpoint.blade.php @@ -54,11 +54,12 @@
{{ __("scribe::try_it_out.received_response") }}:
-
+
" style="max-height: 400px;">
   @endif diff --git a/resources/views/themes/default/index.blade.php b/resources/views/themes/default/index.blade.php index ef73219e..d0f46344 100644 --- a/resources/views/themes/default/index.blade.php +++ b/resources/views/themes/default/index.blade.php @@ -33,7 +33,7 @@ @if($tryItOut['enabled'] ?? true) diff --git a/resources/views/themes/elements/index.blade.php b/resources/views/themes/elements/index.blade.php index 68b74b24..bc1ba060 100644 --- a/resources/views/themes/elements/index.blade.php +++ b/resources/views/themes/elements/index.blade.php @@ -27,7 +27,7 @@ @if($tryItOut['enabled'] ?? true) @@ -75,9 +75,9 @@ function tryItOut(btnElement) { responsePanel.hidden = true; let form = btnElement.form; - let { method, path, hasjsonbody } = form.dataset; + let { method, path, hasjsonbody: hasJsonBody} = form.dataset; let body = {}; - if (hasjsonbody === "1") { + if (hasJsonBody === "1") { body = form.querySelector('.code-editor').textContent; } else if (form.dataset.hasfiles === "1") { body = new FormData(); @@ -118,7 +118,7 @@ function tryItOut(btnElement) { let contentEl = responsePanel.querySelector(`.response-content`); if (responseContent === '') { - contentEl.textContent = '' + contentEl.textContent = contentEl.dataset.emptyResponseText; return; } diff --git a/resources/views/themes/elements/try_it_out.blade.php b/resources/views/themes/elements/try_it_out.blade.php index 284ec2d9..6033c677 100644 --- a/resources/views/themes/elements/try_it_out.blade.php +++ b/resources/views/themes/elements/try_it_out.blade.php @@ -279,23 +279,13 @@ class="svg-inline--fa fa-caret-down fa-fw sl-icon" role="img" d="M310.6 246.6l-127.1 128C176.4 380.9 168.2 384 160 384s-16.38-3.125-22.63-9.375l-127.1-128C.2244 237.5-2.516 223.7 2.438 211.8S19.07 192 32 192h255.1c12.94 0 24.62 7.781 29.58 19.75S319.8 237.5 310.6 246.6z">
- Error + {{ __("scribe::try_it_out.request_failed") }}
-

-

1. Double check that your computer is connected to - the internet.

-

2. Make sure the API is actually running and - available under the specified URL.

-

3. If you've checked all of the above and still experiencing issues, - check if the API supports CORS. -

+

+

{{ __("scribe::try_it_out.error_help") }}

@@ -314,13 +304,15 @@ class="svg-inline--fa fa-caret-down fa-fw sl-icon" role="img" d="M310.6 246.6l-127.1 128C176.4 380.9 168.2 384 160 384s-16.38-3.125-22.63-9.375l-127.1-128C.2244 237.5-2.516 223.7 2.438 211.8S19.07 192 32 192h255.1c12.94 0 24.62 7.781 29.58 19.75S319.8 237.5 310.6 246.6z">
- Response + {{ __("scribe::try_it_out.received_response") }}

-
+
"
+                                       style="max-height: 300px;">