Skip to content

Commit 9ff167b

Browse files
authored
Merge pull request #91 from RonasIT/elements-install
Elements install
2 parents ee2675e + ce57383 commit 9ff167b

File tree

8 files changed

+76
-2
lines changed

8 files changed

+76
-2
lines changed

config/auto-doc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@
105105
*/
106106
'driver' => env('SWAGGER_DRIVER', 'local'),
107107

108+
/*
109+
|--------------------------------------------------------------------------
110+
| OpenAPI Spec viewer
111+
|--------------------------------------------------------------------------
112+
|
113+
| Tool for rendering API documentation in HTML format.
114+
| Available values: "swagger", "elements"
115+
*/
116+
'documentation_viewer' => env('SWAGGER_SPEC_VIEWER', 'swagger'),
117+
108118
'drivers' => [
109119
'local' => [
110120
'class' => LocalDriver::class,

resources/assets/elements/styles.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/elements/web-components.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- HTML for static distribution bundle build -->
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7+
<title>Elements in HTML</title>
8+
<!-- Embed elements Elements via Web Component -->
9+
<script src="{{ config('auto-doc.global_prefix') }}/auto-doc/web-components.min.js"></script>
10+
<link rel="stylesheet" href="{{ config('auto-doc.global_prefix') }}/auto-doc/styles.min.css">
11+
</head>
12+
13+
<body>
14+
<elements-api apiDescriptionUrl="/auto-doc/documentation" router="hash" layout="sidebar"/>
15+
</body>
16+
</html>

src/Http/Controllers/AutoDocController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
class AutoDocController extends BaseController
1111
{
1212
protected $service;
13+
protected $documentationViewer;
1314

1415
public function __construct()
1516
{
1617
$this->service = app(SwaggerService::class);
18+
$this->documentationViewer = config('auto-doc.documentation_viewer');
1719
}
1820

1921
public function documentation()
@@ -28,15 +30,15 @@ public function index()
2830
$currentEnvironment = config('app.env');
2931

3032
if (in_array($currentEnvironment, config('auto-doc.display_environments'))) {
31-
return view('auto-doc::documentation');
33+
return view("auto-doc::documentation-{$this->documentationViewer}");
3234
}
3335

3436
return response('Forbidden.', 403);
3537
}
3638

3739
public function getFile(Request $request, $file)
3840
{
39-
$filePath = __DIR__ . '/../../../resources/assets/swagger/' . $file;
41+
$filePath = __DIR__ . "/../../../resources/assets/{$this->documentationViewer}/" . $file;
4042

4143
if (!file_exists($filePath)) {
4244
throw new NotFoundHttpException();

tests/AutoDocControllerTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ public function testGetViewDocumentation()
8585
$this->assertEqualsFixture('rendered_documentation.html', $response->getContent());
8686
}
8787

88+
public function testGetViewElementsDocumentation()
89+
{
90+
config([
91+
'auto-doc.display_environments' => ['testing'],
92+
'auto-doc.documentation_viewer' => 'elements'
93+
]);
94+
95+
$response = $this->get('/');
96+
97+
$response->assertStatus(Response::HTTP_OK);
98+
99+
$this->assertEqualsFixture('rendered_elements_documentation.html', $response->getContent());
100+
}
101+
88102
public function testGetViewDocumentationEnvironmentDisable()
89103
{
90104
$response = $this->get('/');
@@ -118,6 +132,19 @@ public function testGetSwaggerAssetFile()
118132
$response->assertHeader('Content-Type', 'text/html; charset=UTF-8');
119133
}
120134

135+
public function testGetElementsAssetFile()
136+
{
137+
config(['auto-doc.documentation_viewer' => 'elements']);
138+
139+
$response = $this->get('/auto-doc/web-components.min.js');
140+
141+
$response->assertStatus(Response::HTTP_OK);
142+
143+
$this->assertEquals($response->getContent(), file_get_contents(resource_path('/assets/elements/web-components.min.js')));
144+
145+
$response->assertHeader('Content-Type', 'text/html; charset=UTF-8');
146+
}
147+
121148
public function testGetFileNotExists()
122149
{
123150
$response = $this->get('/auto-doc/non-existent-file.js');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- HTML for static distribution bundle build -->
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7+
<title>Elements in HTML</title>
8+
<!-- Embed elements Elements via Web Component -->
9+
<script src="/auto-doc/web-components.min.js"></script>
10+
<link rel="stylesheet" href="/auto-doc/styles.min.css">
11+
</head>
12+
13+
<body>
14+
<elements-api apiDescriptionUrl="/auto-doc/documentation" router="hash" layout="sidebar"/>
15+
</body>
16+
</html>

0 commit comments

Comments
 (0)