Skip to content

Commit

Permalink
refactor: move logic to class
Browse files Browse the repository at this point in the history
  • Loading branch information
hanspagel committed Sep 9, 2024
1 parent 0cd7860 commit 88b0552
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 2 additions & 6 deletions resources/views/reference.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,11 @@
</head>

<body>
<script id="api-reference" data-url="{{ config('scalar.url') }}"></script>
<script id="api-reference" data-url="{{ Scalar::url() }}"></script>

<!-- Optional: You can set a full configuration object like this: -->
<script>
var configuration = {!! json_encode(
array_merge(config('scalar.configuration'), [
'theme' => config('scalar.configuration.theme') === 'laravel' ? 'none' : config('scalar.configuration.theme'),
]),
) !!}
var configuration = {!! Scalar::configurationJson() !!}
document.getElementById('api-reference').dataset.configuration =
JSON.stringify(configuration)
Expand Down
26 changes: 25 additions & 1 deletion src/Scalar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,28 @@

namespace Scalar\Scalar;

class Scalar {}
class Scalar
{
public static function url()
{
return config('scalar.url');
}

public static function configurationJson()
{
/** Get the Scalar API Reference configuration */
$configuration = config('scalar.configuration');

/** Don’t add a theme if `laravel` is selected */
$theme = config('scalar.configuration.theme') === 'laravel' ?
'none' :
config('scalar.configuration.theme');

/** Render as JSON */
return json_encode(
array_merge($configuration, [
'theme' => $theme,
]),
);
}
}

0 comments on commit 88b0552

Please sign in to comment.