chisel 1.2.7__tar.gz → 1.3.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chisel
3
- Version: 1.2.7
3
+ Version: 1.3.0
4
4
  Summary: Lightweight WSGI application framework, schema-validated JSON APIs, and API documentation
5
5
  Home-page: https://github.com/craigahobbs/chisel
6
6
  Author: Craig A. Hobbs
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = chisel
3
- version = 1.2.7
3
+ version = 1.3.0
4
4
  url = https://github.com/craigahobbs/chisel
5
5
  author = Craig A. Hobbs
6
6
  author_email = craigahobbs@gmail.com
@@ -30,6 +30,11 @@ package_dir =
30
30
  install_requires =
31
31
  schema-markdown >= 1.2.0
32
32
 
33
+ [options.package_data]
34
+ chisel =
35
+ static/*.bare
36
+ static/*.html
37
+
33
38
  [egg_info]
34
39
  tag_build =
35
40
  tag_date = 0
@@ -53,7 +53,7 @@ class Application:
53
53
 
54
54
  #: Set to True to validate request output. Individual requests can use this application state as they see fit. For
55
55
  #: example, :class:`~chisel.Action` requests schema-validate return content data when this value is True.
56
- #: is True.
56
+ #: Default is True.
57
57
  self.validate_output = True
58
58
 
59
59
  #: The chisel application's map of request name to :class:`~chisel.Request` object map.
@@ -5,6 +5,8 @@
5
5
  Chisel documentation application
6
6
  """
7
7
 
8
+ import importlib.resources
9
+
8
10
  from schema_markdown import get_referenced_types
9
11
  from schema_markdown.type_model import TYPE_MODEL
10
12
 
@@ -12,62 +14,6 @@ from .action import Action, ActionError
12
14
  from .request import RedirectRequest, StaticRequest
13
15
 
14
16
 
15
- # The chisel-doc application's HTML stub
16
- CHISEL_DOC_HTML = b'''\
17
- <!DOCTYPE html>
18
- <html lang="en">
19
- <head>
20
- <title>Chisel Documentation Application</title>
21
- <meta charset="UTF-8">
22
- <meta name="description" content="Chisel Documentation Application">
23
- <meta name="viewport" content="width=device-width, initial-scale=1">
24
- <link rel="stylesheet" href="https://craigahobbs.github.io/markdown-up/app.css">
25
-
26
- <!-- Preloads -->
27
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/data.js" as="script">
28
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/library.js" as="script">
29
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/model.js" as="script">
30
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/options.js" as="script">
31
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/parser.js" as="script">
32
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/runtime.js" as="script">
33
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/runtimeAsync.js" as="script">
34
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/value.js" as="script">
35
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/element-model/lib/elementModel.js" as="script">
36
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/app.js" as="script">
37
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/dataTable.js" as="script">
38
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/dataUtil.js" as="script">
39
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/lineChart.js" as="script">
40
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/script.js" as="script">
41
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/scriptLibrary.js" as="script">
42
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/markdown-model/lib/elements.js" as="script">
43
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/markdown-model/lib/parser.js" as="script">
44
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown-doc/lib/schemaMarkdownDoc.js" as="script">
45
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/encode.js" as="script">
46
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/parser.js" as="script">
47
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/schema.js" as="script">
48
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/schemaUtil.js" as="script">
49
- <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/typeModel.js" as="script">
50
- <link rel="preload" href="https://craigahobbs.github.io/markdown-up/app.css" as="style">
51
- <link rel="preload" href="https://craigahobbs.github.io/markdown-up/markdown-model/static/markdown-model.css" as="style">
52
- </head>
53
- <body>
54
- </body>
55
- <script type="module">
56
- import {MarkdownUp} from 'https://craigahobbs.github.io/markdown-up/lib/app.js';
57
- const app = new MarkdownUp(window, {
58
- 'markdownText': `\
59
- ~~~ markdown-script
60
- include 'https://craigahobbs.github.io/chisel/doc/app.mds'
61
-
62
- chiselDoc()
63
- ~~~
64
- `});
65
- app.run();
66
- </script>
67
- </html>
68
- '''
69
-
70
-
71
17
  def create_doc_requests(requests=None, root_path='/doc', api=True, app=True):
72
18
  """
73
19
  Yield a series of requests for use with :meth:`~chisel.Application.add_requests` comprising the Chisel
@@ -86,13 +32,25 @@ def create_doc_requests(requests=None, root_path='/doc', api=True, app=True):
86
32
  yield DocIndex(requests=requests, urls=(('GET', root_path + '/doc_index'),))
87
33
  yield DocRequest(requests=requests, urls=(('GET', root_path + '/doc_request'),))
88
34
  if app:
89
- yield RedirectRequest((('GET', root_path),), root_path + '/', doc_group='Documentation')
90
- yield StaticRequest(
91
- 'chisel_doc',
92
- CHISEL_DOC_HTML,
93
- urls=(('GET', root_path + '/'), ('GET', root_path + '/index.html')),
94
- doc_group='Documentation'
95
- )
35
+ yield RedirectRequest((('GET', root_path),), root_path + '/', name='chisel_doc_redirect', doc_group='Documentation')
36
+ with importlib.resources.files('chisel.static').joinpath('index.html').open('rb') as fh:
37
+ yield StaticRequest(
38
+ 'chisel_doc',
39
+ fh.read(),
40
+ 'text/html; charset=utf-8',
41
+ (('GET', root_path + '/'), ('GET', root_path + '/index.html')),
42
+ 'The Chisel documentation HTML',
43
+ 'Documentation'
44
+ )
45
+ with importlib.resources.files('chisel.static').joinpath('chiselDoc.bare').open('rb') as fh:
46
+ yield StaticRequest(
47
+ 'chisel_doc_app',
48
+ fh.read(),
49
+ 'text/plain; charset=utf-8',
50
+ (('GET', root_path + '/chiselDoc.bare'),),
51
+ 'The Chisel documentation application',
52
+ 'Documentation'
53
+ )
96
54
 
97
55
 
98
56
  class DocIndex(Action):
@@ -0,0 +1,87 @@
1
+ # Licensed under the MIT License
2
+ # https://github.com/craigahobbs/chisel/blob/main/LICENSE
3
+
4
+ include <args.mds>
5
+
6
+
7
+ # The Chisel documentation application main entry point
8
+ async function chiselDoc():
9
+ args = argsParse(chiselDocArguments)
10
+ name = objectGet(args, 'name')
11
+ if name != null:
12
+ chiselDocRequestPage(name)
13
+ else:
14
+ chiselDocIndexPage()
15
+ endif
16
+ endfunction
17
+
18
+
19
+ # The Chisel documentation application arguments
20
+ chiselDocArguments = argsValidate(arrayNew( \
21
+ objectNew('name', 'name') \
22
+ ))
23
+
24
+
25
+ # Render the Chisel documentation application index page
26
+ async function chiselDocIndexPage():
27
+ # Fetch the documentation index API
28
+ indexURL = 'doc_index'
29
+ docIndexJSON = systemFetch(indexURL)
30
+ docIndex = if(docIndexJSON != null, jsonParse(docIndexJSON))
31
+ if docIndex == null:
32
+ markdownPrint('**Error:** Failed to fetch chisel index API "' + indexURL + '"')
33
+ return
34
+ endif
35
+ title = objectGet(docIndex, 'title')
36
+ groups = objectGet(docIndex, 'groups')
37
+
38
+ # Render the index page
39
+ documentSetTitle(title)
40
+ markdownPrint('# ' + markdownEscape(title))
41
+ for groupName in arraySort(objectKeys(groups)):
42
+ markdownPrint('', '## ' + markdownEscape(groupName))
43
+ for requestName in arraySort(objectGet(groups, groupName)):
44
+ markdownPrint('', argsLink(chiselDocArguments, requestName, objectNew('name', requestName)))
45
+ endfor
46
+ endfor
47
+ endfunction
48
+
49
+
50
+ # Render the Chisel documentation application request page
51
+ async function chiselDocRequestPage(typeName):
52
+ # Fetch the request API
53
+ requestURL = 'doc_request?name=' + urlEncodeComponent(typeName)
54
+ docRequestJSON = systemFetch(requestURL)
55
+ docRequest = if(docRequestJSON != null, jsonParse(docRequestJSON))
56
+ if docRequest == null:
57
+ markdownPrint('**Error:** Failed to fetch chisel request API "' + requestURL + '"')
58
+ return
59
+ endif
60
+ doc = objectGet(docRequest, 'doc')
61
+ urls = objectGet(docRequest, 'urls')
62
+ types = objectGet(docRequest, 'types')
63
+
64
+ # Render the request page
65
+ documentSetTitle(typeName)
66
+ markdownPrint(argsLink(chiselDocArguments, 'Index', objectNew('name', null)))
67
+
68
+ # Action request?
69
+ if types != null:
70
+ elementModelRender(schemaElements(types, typeName, urls))
71
+ return
72
+ endif
73
+
74
+ # Non-action request
75
+ markdownPrint('', '# ' + markdownEscape(typeName))
76
+ if doc != null:
77
+ markdownPrint('', doc)
78
+ endif
79
+ if urls != null && arrayLength(urls) > 0:
80
+ markdownPrint('', '**Note:** The request is exposed at the following ' + if(arrayLength(urls) == 1, 'URL:', 'URLs:'))
81
+ for requestURL in urls:
82
+ method = objectGet(requestURL, 'method', '')
83
+ path = objectGet(requestURL, 'path')
84
+ markdownPrint('', '&nbsp;&nbsp;[' + markdownEscape(method) + ' ' + markdownEscape(path) + '](' + path + ')')
85
+ endfor
86
+ endif
87
+ endfunction
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>Chisel Documentation Application</title>
5
+ <meta charset="UTF-8">
6
+ <meta name="description" content="Chisel Documentation Application">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8
+ <link rel="stylesheet" href="https://craigahobbs.github.io/markdown-up/app.css">
9
+
10
+ <!-- Preloads -->
11
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/data.js" as="script">
12
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/library.js" as="script">
13
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/model.js" as="script">
14
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/options.js" as="script">
15
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/parser.js" as="script">
16
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/runtime.js" as="script">
17
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/runtimeAsync.js" as="script">
18
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/bare-script/lib/value.js" as="script">
19
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/element-model/lib/elementModel.js" as="script">
20
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/app.js" as="script">
21
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/dataTable.js" as="script">
22
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/dataUtil.js" as="script">
23
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/lineChart.js" as="script">
24
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/script.js" as="script">
25
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/scriptLibrary.js" as="script">
26
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/markdown-model/lib/elements.js" as="script">
27
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/markdown-model/lib/parser.js" as="script">
28
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown-doc/lib/schemaMarkdownDoc.js" as="script">
29
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/encode.js" as="script">
30
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/parser.js" as="script">
31
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/schema.js" as="script">
32
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/schemaUtil.js" as="script">
33
+ <link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/schema-markdown/lib/typeModel.js" as="script">
34
+ <link rel="preload" href="https://craigahobbs.github.io/markdown-up/app.css" as="style">
35
+ <link rel="preload" href="https://craigahobbs.github.io/markdown-up/markdown-model/static/markdown-model.css" as="style">
36
+ </head>
37
+ <body>
38
+ </body>
39
+ <script type="module">
40
+ import {MarkdownUp} from 'https://craigahobbs.github.io/markdown-up/lib/app.js';
41
+ const app = new MarkdownUp(window, {
42
+ 'markdownText': `\
43
+ ~~~ markdown-script
44
+ include 'chiselDoc.bare'
45
+
46
+ chiselDoc()
47
+ ~~~
48
+ `});
49
+ app.run();
50
+ </script>
51
+ </html>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chisel
3
- Version: 1.2.7
3
+ Version: 1.3.0
4
4
  Summary: Lightweight WSGI application framework, schema-validated JSON APIs, and API documentation
5
5
  Home-page: https://github.com/craigahobbs/chisel
6
6
  Author: Craig A. Hobbs
@@ -11,4 +11,6 @@ src/chisel.egg-info/PKG-INFO
11
11
  src/chisel.egg-info/SOURCES.txt
12
12
  src/chisel.egg-info/dependency_links.txt
13
13
  src/chisel.egg-info/requires.txt
14
- src/chisel.egg-info/top_level.txt
14
+ src/chisel.egg-info/top_level.txt
15
+ src/chisel/static/chiselDoc.bare
16
+ src/chisel/static/index.html
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes