-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstoplight.py
More file actions
72 lines (61 loc) · 2.17 KB
/
Copy pathstoplight.py
File metadata and controls
72 lines (61 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import json
import typing as t
from .base import IDocumentationUI
class StopLightUI(IDocumentationUI):
@property
def name(self) -> str:
return "stoplight"
@property
def template_name(self) -> t.Optional[str]:
return None
@property
def path(self) -> str:
return self._path
@property
def template_context(self) -> dict:
return self._template_context
@property
def template_string(self) -> t.Optional[str]:
return """
<!doctype html>
<html lang="en">
<head>
<title>{{title}}</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" href="{{favicon_url}}">
<!-- Embed elements Elements via Web Component -->
<script src="{{stoplight_js_url}}" crossorigin></script>
<link rel="stylesheet" href="{{stoplight_css_url}}">
<script>
window.__element_config = {{ config | safe }}
</script>
</head>
<body>
<elements-api
apiDescriptionUrl="{{openapi_url}}"
...window.__element_config
/>
</body>
</html>
"""
def __init__(
self,
path: str = "elements",
title: str = "Ellar Stoplight",
stoplight_js_url: str = "https://unpkg.com/@stoplight/elements/web-components.min.js",
stoplight_css_url: str = "https://unpkg.com/@stoplight/elements/styles.min.css",
favicon_url: str = "https://eadwincode.github.io/ellar/img/Icon.svg",
config: t.Optional[dict] = None,
):
_config = config or {}
_config.setdefault("router", "hash")
_config.setdefault("layout", "sidebar")
self._path = path
self._template_context = {
"title": title,
"stoplight_js_url": stoplight_js_url,
"stoplight_css_url": stoplight_css_url,
"favicon_url": favicon_url,
"config": json.dumps(_config),
}