bare-script 3.8.8__tar.gz → 3.8.10__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.
Files changed (35) hide show
  1. {bare_script-3.8.8/src/bare_script.egg-info → bare_script-3.8.10}/PKG-INFO +1 -1
  2. {bare_script-3.8.8 → bare_script-3.8.10}/setup.cfg +1 -1
  3. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/args.bare +1 -1
  4. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/baredoc.bare +1 -1
  5. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/dataLineChart.bare +1 -1
  6. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/dataTable.bare +1 -1
  7. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/diff.bare +1 -1
  8. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/markdownUp.bare +10 -29
  9. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/pager.bare +1 -1
  10. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/schemaDoc.bare +136 -2
  11. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/unittestMock.bare +11 -22
  12. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/library.py +9 -9
  13. {bare_script-3.8.8 → bare_script-3.8.10/src/bare_script.egg-info}/PKG-INFO +1 -1
  14. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script.egg-info/SOURCES.txt +0 -1
  15. bare_script-3.8.8/src/bare_script/include/schemaDocApp.bare +0 -149
  16. {bare_script-3.8.8 → bare_script-3.8.10}/LICENSE +0 -0
  17. {bare_script-3.8.8 → bare_script-3.8.10}/README.md +0 -0
  18. {bare_script-3.8.8 → bare_script-3.8.10}/pyproject.toml +0 -0
  19. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/__init__.py +0 -0
  20. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/__main__.py +0 -0
  21. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/bare.py +0 -0
  22. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/baredoc.py +0 -0
  23. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/data.py +0 -0
  24. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/__init__.py +0 -0
  25. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/forms.bare +0 -0
  26. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/include/unittest.bare +0 -0
  27. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/model.py +0 -0
  28. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/options.py +0 -0
  29. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/parser.py +0 -0
  30. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/runtime.py +0 -0
  31. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script/value.py +0 -0
  32. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script.egg-info/dependency_links.txt +0 -0
  33. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script.egg-info/entry_points.txt +0 -0
  34. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script.egg-info/requires.txt +0 -0
  35. {bare_script-3.8.8 → bare_script-3.8.10}/src/bare_script.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bare-script
3
- Version: 3.8.8
3
+ Version: 3.8.10
4
4
  Summary: bare-script
5
5
  Home-page: https://github.com/craigahobbs/bare-script
6
6
  Author: Craig A. Hobbs
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = bare-script
3
- version = 3.8.8
3
+ version = 3.8.10
4
4
  url = https://github.com/craigahobbs/bare-script
5
5
  author = Craig A. Hobbs
6
6
  author_email = craigahobbs@gmail.com
@@ -6,7 +6,7 @@ include <dataTable.bare>
6
6
 
7
7
  # The URL arguments model
8
8
  argsTypes = schemaParse( \
9
- 'group "<args.bare>"', \
9
+ 'group "args.bare"', \
10
10
  '', \
11
11
  '', \
12
12
  '# An argument model list', \
@@ -6,7 +6,7 @@ include <schemaDoc.bare>
6
6
 
7
7
 
8
8
  # $function: baredocMain
9
- # $group: baredocMain.bare
9
+ # $group: baredoc.bare
10
10
  # $doc: The BareScript library documentation application main entry point
11
11
  # $arg url: The library documentation JSON resource URL
12
12
  # $arg title: The library title
@@ -4,7 +4,7 @@
4
4
 
5
5
  # The line chart model
6
6
  dataLineChartTypes = schemaParse( \
7
- 'group "Line Chart"', \
7
+ 'group "data"', \
8
8
  '', \
9
9
  '', \
10
10
  '# A line chart model', \
@@ -4,7 +4,7 @@
4
4
 
5
5
  # The data table model's Schema Markdown
6
6
  dataTableTypes = schemaParse( \
7
- 'group "<dataTable.bare>"', \
7
+ 'group "dataTable.bare"', \
8
8
  '', \
9
9
  '', \
10
10
  '# A data table model', \
@@ -4,7 +4,7 @@
4
4
 
5
5
  # The text line difference model
6
6
  diffTypes = schemaParse( \
7
- 'group "<diff.bare>"', \
7
+ 'group "diff.bare"', \
8
8
  '', \
9
9
  '', \
10
10
  '# A list of text line differences', \
@@ -441,6 +441,16 @@ endfunction
441
441
  #
442
442
 
443
443
 
444
+ # $function: markdownElements
445
+ # $group: Markdown
446
+ # $doc: Generate an element model from a Markdown model
447
+ # $arg markdownModel: The [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
448
+ # $arg generic: Optional (default is false). If true, render markdown elements in a generic context.
449
+ # $return: The rendered Markdown [element model](https://github.com/craigahobbs/element-model#readme)
450
+ function markdownElements():
451
+ endfunction
452
+
453
+
444
454
  # $function: markdownEscape
445
455
  # $group: markdownUp.bare: markdown
446
456
  # $doc: Escape text for inclusion in Markdown text
@@ -509,35 +519,6 @@ function markdownTitle():
509
519
  endfunction
510
520
 
511
521
 
512
- #
513
- # Schema functions
514
- #
515
-
516
-
517
- # $function: schemaElements
518
- # $group: markdownUp.bare: schema
519
- # $doc: Get a schema type's documentation [element model](https://github.com/craigahobbs/element-model#readme).
520
- # $doc: Render the element model with the [elementModelRender](#var.vName='elementModelRender') function.
521
- # $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
522
- # $arg typeName: The type name
523
- # $arg actionURLs: Optional (default is null). The
524
- # $arg actionURLs: [action URL overrides](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='ActionURL').
525
- # $arg actionCustom: Optional (default is false). If true, the action has a custom response.
526
- # $return: The schema type's documentation [element model](https://github.com/craigahobbs/element-model#readme)
527
- function schemaElements(types, typeName):
528
- userType = objectGet(types, typeName)
529
- userTypeKey = arrayGet(objectKeys(userType), 0)
530
- if userTypeKey == 'struct' && objectGet(objectGet(userType, 'struct'), 'union'):
531
- userTypeKey = 'union'
532
- endif
533
- return [ \
534
- [ \
535
- {'html': 'h1', 'elem': {'text': userTypeKey + ' ' + typeName}} \
536
- ] \
537
- ]
538
- endfunction
539
-
540
-
541
522
  #
542
523
  # Session storage functions
543
524
  #
@@ -7,7 +7,7 @@ include <args.bare>
7
7
 
8
8
  # The pager model
9
9
  pagerTypes = schemaParse( \
10
- 'group "<pager.bare>"', \
10
+ 'group "pager.bare"', \
11
11
  '', \
12
12
  '', \
13
13
  '# A pager application model', \
@@ -1,16 +1,150 @@
1
1
  # Licensed under the MIT License
2
2
  # https://github.com/craigahobbs/bare-script/blob/main/LICENSE
3
3
 
4
+ include <args.bare>
4
5
  include <dataTable.bare>
6
+ include <schemaDoc.bare>
7
+
8
+
9
+ # $function: schemaDocMain
10
+ # $group: schemaDoc.bare
11
+ # $doc: The Schema Markdown documentation viewer main entry point
12
+ # $arg url: Optional (default is null). The Schema Markdown text or JSON resource URL. If null, the Schema Markdown type model is displayed.
13
+ # $arg title: Optional. The schema title.
14
+ # $arg hideNoGroup: Optional (default is false). If true, hide types with no group.
15
+ async function schemaDocMain(url, title, hideNoGroup):
16
+ # Parse arguments
17
+ args = argsParse(schemaDocArguments)
18
+ name = objectGet(args, 'name')
19
+ publish = objectGet(args, 'publish')
20
+ single = objectGet(args, 'single')
21
+ url = objectGet(args, 'url', url)
22
+ title = if(title != null && !objectHas(args, 'url'), title, url)
23
+
24
+ # If no URL was provided, use the Schema Markdown type model schema
25
+ if !url:
26
+ types = schemaTypeModel()
27
+ title = 'The Schema Markdown Type Model'
28
+ else:
29
+ # Fetch the Schema Markdown resource
30
+ types = null
31
+ schemaText = systemFetch(url)
32
+ if schemaText != null:
33
+ if stringEndsWith(url, '.json'):
34
+ schemaJSON = jsonParse(schemaText)
35
+ if schemaJSON != null:
36
+ types = schemaValidateTypeModel(schemaJSON)
37
+ endif
38
+ else:
39
+ types = schemaParse(schemaText)
40
+ endif
41
+ endif
42
+
43
+ # Error?
44
+ if types == null:
45
+ markdownPrint('**Error:** Failed to fetch Schema Markdown resource "' + url + '"')
46
+ return
47
+ endif
48
+ endif
49
+
50
+ # Type page?
51
+ if name:
52
+ # Set the type page title
53
+ documentSetTitle(title + ' - ' + name)
54
+ markdownPrint(argsLink(schemaDocArguments, 'Index', {'name': null}))
55
+
56
+ # Type exist?
57
+ if !objectHas(types, name):
58
+ markdownPrint('', '**Error:** Unknown type "' + name + '"')
59
+ return
60
+ endif
61
+
62
+ # Render the type's documentation
63
+ markdownPrint(schemaDocMarkdown(types, name))
64
+ return
65
+ endif
66
+
67
+ # Render the index page title
68
+ documentSetTitle(title)
69
+ markdownPrint('# ' + markdownEscape(title))
70
+
71
+ # Render the single page toggle
72
+ if !publish:
73
+ markdownPrint('', argsLink(schemaDocArguments, if(single, 'Multi Page', 'Single Page'), {'single': !single}))
74
+ endif
75
+
76
+ # Group the types
77
+ groups = {}
78
+ typeNames = arraySort(objectKeys(types))
79
+ typeGroups = {'action': 'Actions', 'enum': 'Enums', 'struct': 'Structs', 'typedef': 'Typedefs'}
80
+ for typeName in typeNames:
81
+ type = objectGet(types, typeName)
82
+ group = objectGet(objectGet(type, arrayGet(objectKeys(type), 0)), 'docGroup')
83
+
84
+ # No group? Use the type's default group.
85
+ if group == null:
86
+ if hideNoGroup:
87
+ continue
88
+ endif
89
+ group = objectGet(typeGroups, arrayGet(objectKeys(type), 0))
90
+ endif
91
+
92
+ # Add the type to the group
93
+ if !objectHas(groups, group):
94
+ objectSet(groups, group, [])
95
+ endif
96
+ arrayPush(objectGet(groups, group), type)
97
+ endfor
98
+ groupNames = arraySort(objectKeys(groups))
99
+
100
+ # The table of contents
101
+ if single:
102
+ markdownPrint('', '## Table of Contents', '')
103
+ for groupName in groupNames:
104
+ markdownPrint('- ' + argsLink(schemaDocArguments, groupName, null, false, groupName))
105
+ endfor
106
+ endif
107
+
108
+ # Render the index groups
109
+ for groupName in groupNames:
110
+ if single:
111
+ markdownPrint('', '---')
112
+ endif
113
+ markdownPrint('', '## ' + markdownEscape(groupName))
114
+ if single && !publish:
115
+ markdownPrint('', argsLink(schemaDocArguments, 'Back to top', null, false, '_top'))
116
+ endif
117
+
118
+ # Render the group type links
119
+ groupTypes = objectGet(groups, groupName)
120
+ for groupType in groupTypes:
121
+ groupTypeName = objectGet(objectGet(groupType, arrayGet(objectKeys(groupType), 0)), 'name')
122
+ if single:
123
+ markdownPrint('', schemaDocMarkdown(types, groupTypeName, {'headerPrefix': '###', 'hideReferenced': true}))
124
+ else:
125
+ markdownPrint('', argsLink(schemaDocArguments, groupTypeName, {'name': groupTypeName}, false, '_top'))
126
+ endif
127
+ endfor
128
+ endfor
129
+ endfunction
130
+
131
+
132
+ # The Schema Markdown documentation viewer arguments
133
+ schemaDocArguments = argsValidate([ \
134
+ {'name': 'name'}, \
135
+ {'name': 'publish', 'type': 'bool', 'default': false}, \
136
+ {'name': 'single', 'type': 'bool', 'default': false}, \
137
+ {'name': 'url', 'global': 'vURL'} \
138
+ ])
5
139
 
6
140
 
7
141
  # $function: schemaDocMarkdown
8
142
  # $group: schemaDoc.bare
9
143
  # $doc: Generate the Schema Markdown user type documentation as an array of Markdown text lines
10
- # $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
144
+ # $arg types: The [type model](https://craigahobbs.github.io/bare-script/model/#var.vName='Types'&var.vURL='')
11
145
  # $arg typeName: The type name
12
146
  # $arg options: Optional (default is null). The options object with optional members:
13
- # $arg options: - **actionURLs** - The [action URLs](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='ActionURL') override
147
+ # $arg options: - **actionURLs** - The [action URLs](https://craigahobbs.github.io/bare-script/model/#var.vName='ActionURL'&var.vURL='') override
14
148
  # $arg options: - **actionCustom** - If true, the action has a custom response (default is false)
15
149
  # $arg options: - **headerPrefix** - The top-level header prefix string (default is "#")
16
150
  # $arg options: - **hideReferenced** - If true, referenced types are not rendered (default is false)
@@ -31,6 +31,7 @@ unittestMockState = objectCopy(unittestMockStateDefault)
31
31
  # $arg data: Optional (default is null). The map of function name to mock function data.
32
32
  # $arg data: The following functions make use of mock data:
33
33
  # $arg data: - **documentInputValue** - map of id to return value
34
+ # $arg data: - **markdownElements** - array of return values
34
35
  # $arg data: - **markdownParse** - array of return values
35
36
  # $arg data: - **markdownTitle** - array of return values
36
37
  # $arg data: - **systemFetch** - map of URL to response text
@@ -80,15 +81,13 @@ function unittestMockAll(data):
80
81
  unittestMockOne('localStorageSet', unittestMock_localStorageSet)
81
82
 
82
83
  # Markdown
84
+ unittestMockOne('markdownElements', systemPartial(unittestMock_markdownElements, if(data != null, objectGet(data, 'markdownElements'))))
83
85
  unittestMockOne('markdownEscape', unittestMock_markdownEscape)
84
86
  unittestMockOne('markdownHeaderId', unittestMock_markdownHeaderId)
85
87
  unittestMockOne('markdownParse', systemPartial(unittestMock_markdownParse, if(data != null, objectGet(data, 'markdownParse'))))
86
88
  unittestMockOneGeneric('markdownPrint')
87
89
  unittestMockOne('markdownTitle', systemPartial(unittestMock_markdownTitle, if(data != null, objectGet(data, 'markdownTitle'))))
88
90
 
89
- # Schema
90
- unittestMockOne('schemaElements', unittestMock_schemaElements)
91
-
92
91
  # Session Storage
93
92
  unittestMockOne('sessionStorageClear', unittestMock_sessionStorageClear)
94
93
  unittestMockOne('sessionStorageGet', unittestMock_sessionStorageGet)
@@ -287,6 +286,15 @@ endfunction
287
286
  #
288
287
 
289
288
 
289
+ function unittestMock_markdownElements(data, args...):
290
+ # Record the mocked function call
291
+ arrayPush(unittestMockCalls, ['markdownElements', args])
292
+
293
+ # Return the mocked markdownElements response
294
+ return if(data != null, arrayShift(data))
295
+ endfunction
296
+
297
+
290
298
  function unittestMock_markdownEscape(text):
291
299
  return regexReplace(unittestMock_markdownEscapeRegex, text, '\\$1')
292
300
  endfunction
@@ -326,25 +334,6 @@ function unittestMock_markdownTitle(data, args...):
326
334
  endfunction
327
335
 
328
336
 
329
- #
330
- # Schema functions
331
- #
332
-
333
-
334
- function unittestMock_schemaElements(types, typeName):
335
- userType = objectGet(types, typeName)
336
- userTypeKey = arrayGet(objectKeys(userType), 0)
337
- if userTypeKey == 'struct' && objectGet(objectGet(userType, 'struct'), 'union'):
338
- userTypeKey = 'union'
339
- endif
340
- return [ \
341
- [ \
342
- {'html': 'h1', 'elem': {'text': userTypeKey + ' ' + typeName}} \
343
- ] \
344
- ]
345
- endfunction
346
-
347
-
348
337
  #
349
338
  # Session Storage functions
350
339
  #
@@ -1483,7 +1483,7 @@ _REGEX_SPLIT_ARGS = value_args_model([
1483
1483
  # $doc: Parse the [Schema Markdown](https://craigahobbs.github.io/schema-markdown-js/language/) text
1484
1484
  # $arg lines...: The [Schema Markdown](https://craigahobbs.github.io/schema-markdown-js/language/)
1485
1485
  # $arg lines...: text lines (may contain nested arrays of un-split lines)
1486
- # $return: The schema's [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
1486
+ # $return: The schema's [type model](https://craigahobbs.github.io/bare-script-py/model/#var.vName='Types'&var.vURL='')
1487
1487
  def _schema_parse(args, unused_options):
1488
1488
  return parse_schema_markdown(args)
1489
1489
 
@@ -1493,9 +1493,9 @@ def _schema_parse(args, unused_options):
1493
1493
  # $doc: Parse the [Schema Markdown](https://craigahobbs.github.io/schema-markdown-js/language/) text with options
1494
1494
  # $arg lines: The array of [Schema Markdown](https://craigahobbs.github.io/schema-markdown-js/language/)
1495
1495
  # $arg lines: text lines (may contain nested arrays of un-split lines)
1496
- # $arg types: Optional. The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types').
1496
+ # $arg types: Optional. The [type model](https://craigahobbs.github.io/bare-script-py/model/#var.vName='Types'&var.vURL='').
1497
1497
  # $arg filename: Optional (default is ""). The file name.
1498
- # $return: The schema's [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
1498
+ # $return: The schema's [type model](https://craigahobbs.github.io/bare-script-py/model/#var.vName='Types'&var.vURL='')
1499
1499
  def _schema_parse_ex(args, unused_options):
1500
1500
  lines, types, filename = value_args_validate(_SCHEMA_PARSE_EX_ARGS, args)
1501
1501
  lines_type = value_type(lines)
@@ -1514,8 +1514,8 @@ _SCHEMA_PARSE_EX_ARGS = value_args_model([
1514
1514
 
1515
1515
  # $function: schemaTypeModel
1516
1516
  # $group: schema
1517
- # $doc: Get the [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
1518
- # $return: The [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
1517
+ # $doc: Get the [Schema Markdown Type Model](https://craigahobbs.github.io/bare-script-py/model/#var.vName='Types'&var.vURL='')
1518
+ # $return: The [Schema Markdown Type Model](https://craigahobbs.github.io/bare-script-py/model/#var.vName='Types'&var.vURL='')
1519
1519
  def _schema_type_model(unused_args, unused_options):
1520
1520
  return TYPE_MODEL
1521
1521
 
@@ -1523,7 +1523,7 @@ def _schema_type_model(unused_args, unused_options):
1523
1523
  # $function: schemaValidate
1524
1524
  # $group: schema
1525
1525
  # $doc: Validate an object to a schema type
1526
- # $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
1526
+ # $arg types: The [type model](https://craigahobbs.github.io/bare-script-py/model/#var.vName='Types'&var.vURL='')
1527
1527
  # $arg typeName: The type name
1528
1528
  # $arg value: The object to validate
1529
1529
  # $return: The validated object or null if validation fails
@@ -1541,9 +1541,9 @@ _SCHEMA_VALIDATE_ARGS = value_args_model([
1541
1541
 
1542
1542
  # $function: schemaValidateTypeModel
1543
1543
  # $group: schema
1544
- # $doc: Validate a [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
1545
- # $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types') to validate
1546
- # $return: The validated [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
1544
+ # $doc: Validate a [Schema Markdown Type Model](https://craigahobbs.github.io/bare-script-py/model/#var.vName='Types'&var.vURL='')
1545
+ # $arg types: The [type model](https://craigahobbs.github.io/bare-script-py/model/#var.vName='Types'&var.vURL='') to validate
1546
+ # $return: The validated [type model](https://craigahobbs.github.io/bare-script-py/model/#var.vName='Types'&var.vURL='')
1547
1547
  def _schema_validate_type_model(args, unused_options):
1548
1548
  types, = value_args_validate(_SCHEMA_VALIDATE_TYPE_MODEL_ARGS, args)
1549
1549
  return validate_type_model(types)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bare-script
3
- Version: 3.8.8
3
+ Version: 3.8.10
4
4
  Summary: bare-script
5
5
  Home-page: https://github.com/craigahobbs/bare-script
6
6
  Author: Craig A. Hobbs
@@ -29,6 +29,5 @@ src/bare_script/include/forms.bare
29
29
  src/bare_script/include/markdownUp.bare
30
30
  src/bare_script/include/pager.bare
31
31
  src/bare_script/include/schemaDoc.bare
32
- src/bare_script/include/schemaDocApp.bare
33
32
  src/bare_script/include/unittest.bare
34
33
  src/bare_script/include/unittestMock.bare
@@ -1,149 +0,0 @@
1
- # Licensed under the MIT License
2
- # https://github.com/craigahobbs/bare-script/blob/main/LICENSE
3
-
4
- include <args.bare>
5
- include <schemaDoc.bare>
6
-
7
-
8
- # $function: schemaDocAppMain
9
- # $group: schemaDocApp.bare
10
- # $doc: The Schema Markdown documentation viewer main entry point
11
- # $arg url: Optional (default is null). The Schema Markdown text or JSON resource URL. If null, the Schema Markdown type model is displayed.
12
- # $arg title: Optional. The schema title.
13
- # $arg hideNoGroup: Optional (default is false). If true, hide types with no group.
14
- async function schemaDocAppMain(url, title, hideNoGroup):
15
- # Parse arguments
16
- args = argsParse(schemaDocAppArguments)
17
- name = objectGet(args, 'name')
18
- url = objectGet(args, 'url', url)
19
- title = if(title != null && !objectHas(args, 'url'), title, url)
20
-
21
- # If no URL was provided, use the Schema Markdown type model schema
22
- if url == null || url == '':
23
- types = schemaTypeModel()
24
- title = 'The Schema Markdown Type Model'
25
- else:
26
- # Fetch the Schema Markdown resource
27
- types = null
28
- schemaText = systemFetch(url)
29
- if schemaText != null:
30
- if stringEndsWith(url, '.json'):
31
- schemaJSON = jsonParse(schemaText)
32
- if schemaJSON != null:
33
- types = schemaValidateTypeModel(schemaJSON)
34
- endif
35
- else:
36
- types = schemaParse(schemaText)
37
- endif
38
- endif
39
-
40
- # Error?
41
- if types == null:
42
- markdownPrint('**Error:** Failed to fetch Schema Markdown resource "' + url + '"')
43
- return
44
- endif
45
- endif
46
-
47
- # Render the page
48
- if name != null:
49
- schemaDocAppTypePage(types, title, name)
50
- else:
51
- schemaDocAppIndexPage(args, types, title, hideNoGroup)
52
- endif
53
- endfunction
54
-
55
-
56
- # The Schema Markdown documentation viewer arguments
57
- schemaDocAppArguments = argsValidate([ \
58
- {'name': 'name'}, \
59
- {'name': 'publish', 'type': 'bool', 'default': false}, \
60
- {'name': 'single', 'type': 'bool', 'default': false}, \
61
- {'name': 'url', 'global': 'vURL'} \
62
- ])
63
-
64
-
65
- # Render the Schema Markdown documentation viewer index page
66
- function schemaDocAppIndexPage(args, types, title, hideNoGroup):
67
- publish = objectGet(args, 'publish')
68
- single = objectGet(args, 'single')
69
-
70
- # Set the page title
71
- documentSetTitle(title)
72
- markdownPrint('# ' + markdownEscape(title))
73
-
74
- # Render the single page toggle
75
- if !publish:
76
- markdownPrint('', argsLink(schemaDocAppArguments, if(single, 'Multi Page', 'Single Page'), {'single': !single}))
77
- endif
78
-
79
- # Group the types
80
- groups = {}
81
- typeNames = arraySort(objectKeys(types))
82
- typeGroups = {'action': 'Actions', 'enum': 'Enums', 'struct': 'Structs', 'typedef': 'Typedefs'}
83
- for typeName in typeNames:
84
- type = objectGet(types, typeName)
85
- group = objectGet(objectGet(type, arrayGet(objectKeys(type), 0)), 'docGroup')
86
-
87
- # No group? Use the type's default group.
88
- if group == null:
89
- if hideNoGroup:
90
- continue
91
- endif
92
- group = objectGet(typeGroups, arrayGet(objectKeys(type), 0))
93
- endif
94
-
95
- # Add the type to the group
96
- if !objectHas(groups, group):
97
- objectSet(groups, group, [])
98
- endif
99
- arrayPush(objectGet(groups, group), type)
100
- endfor
101
- groupNames = arraySort(objectKeys(groups))
102
-
103
- # The table of contents
104
- if single:
105
- markdownPrint('', '## Table of Contents', '')
106
- for groupName in groupNames:
107
- markdownPrint('- ' + argsLink(schemaDocAppArguments, groupName, null, false, groupName))
108
- endfor
109
- endif
110
-
111
- # Render the index groups
112
- for groupName in groupNames:
113
- if single:
114
- markdownPrint('', '---')
115
- endif
116
- markdownPrint('', '## ' + markdownEscape(groupName))
117
- if single && !publish:
118
- markdownPrint('', argsLink(schemaDocAppArguments, 'Back to top', null, false, '_top'))
119
- endif
120
-
121
- # Render the group type links
122
- groupTypes = objectGet(groups, groupName)
123
- for groupType in groupTypes:
124
- groupTypeName = objectGet(objectGet(groupType, arrayGet(objectKeys(groupType), 0)), 'name')
125
- if single:
126
- markdownPrint('', schemaDocMarkdown(types, groupTypeName, {'headerPrefix': '###', 'hideReferenced': true}))
127
- else:
128
- markdownPrint('', argsLink(schemaDocAppArguments, groupTypeName, {'name': groupTypeName}, false, '_top'))
129
- endif
130
- endfor
131
- endfor
132
- endfunction
133
-
134
-
135
- # Render the Schema Markdown documentation viewer type page
136
- function schemaDocAppTypePage(types, title, typeName):
137
- # Set the page title
138
- documentSetTitle(title + ' - ' + typeName)
139
- markdownPrint(argsLink(schemaDocAppArguments, 'Index', {'name': null}))
140
-
141
- # Type exist?
142
- if !objectHas(types, typeName):
143
- markdownPrint('', '**Error:** Unknown type "' + typeName + '"')
144
- return
145
- endif
146
-
147
- # Render the type's documentation
148
- markdownPrint(schemaDocMarkdown(types, typeName))
149
- endfunction
File without changes
File without changes
File without changes