flask-openapi-elements 9.0.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ __version__ = "9.0.15"
@@ -0,0 +1,35 @@
1
+ import os
2
+
3
+ from flask import Blueprint, render_template_string, current_app
4
+ from flask_openapi.plugins import BasePlugin
5
+
6
+ from .templates import elements_html_string
7
+
8
+
9
+ class RegisterPlugin(BasePlugin):
10
+ name = "elements"
11
+ display_name = "Elements"
12
+
13
+ @classmethod
14
+ def register(cls, doc_url: str) -> Blueprint:
15
+ _here = os.path.dirname(__file__)
16
+ template_folder = os.path.join(_here, "templates")
17
+ static_folder = os.path.join(template_folder, cls.name)
18
+ blueprint = Blueprint(
19
+ cls.name,
20
+ __name__,
21
+ template_folder=template_folder,
22
+ static_folder=static_folder
23
+ )
24
+
25
+ blueprint.add_url_rule(
26
+ rule=f"/{cls.name}",
27
+ endpoint=cls.name,
28
+ view_func=lambda: render_template_string(
29
+ current_app.config.get("ELEMENTS_HTML_STRING") or elements_html_string,
30
+ doc_url=doc_url,
31
+ elements_config=current_app.config.get("ELEMENTS_CONFIG")
32
+ )
33
+ )
34
+
35
+ return blueprint
@@ -0,0 +1,28 @@
1
+ elements_html_string = """
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</title>
8
+ <link rel="shortcut icon" href="elements/images/elements.svg">
9
+ <script src="elements/js/web-components.min.js"></script>
10
+ <link rel="stylesheet" href="elements/css/styles.min.css">
11
+ </head>
12
+ <body>
13
+ <elements-api
14
+ apiDescriptionUrl="{{ doc_url }}"
15
+ router="hash"
16
+ />
17
+ <script>
18
+ const elements_config = JSON.parse(`{{ elements_config|default('{}')|tojson }}`);
19
+ var elementsDoc = document.querySelector("elements-api");
20
+ var specUrl = new URL("{{ doc_url }}", window.location.href).href;
21
+ elementsDoc.setAttribute("apiDescriptionUrl", specUrl);
22
+ for(var k in elements_config) {
23
+ elementsDoc.setAttribute(k, elements_config[k]);
24
+ }
25
+ </script>
26
+ </body>
27
+ </html>
28
+ """