bare-script 3.5.5__tar.gz → 3.7.1__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.
- {bare_script-3.5.5/src/bare_script.egg-info → bare_script-3.7.1}/PKG-INFO +20 -21
- {bare_script-3.5.5 → bare_script-3.7.1}/README.md +19 -19
- {bare_script-3.5.5 → bare_script-3.7.1}/setup.cfg +1 -2
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/bare.py +4 -9
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/include/args.bare +8 -8
- bare_script-3.7.1/src/bare_script/include/dataTable.bare +211 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/include/diff.bare +1 -1
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/include/markdownUp.bare +8 -117
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/include/pager.bare +3 -3
- bare_script-3.7.1/src/bare_script/include/unittest.bare +505 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/library.py +75 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/model.py +64 -8
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/options.py +1 -1
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/parser.py +222 -87
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/runtime.py +91 -42
- {bare_script-3.5.5 → bare_script-3.7.1/src/bare_script.egg-info}/PKG-INFO +20 -21
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script.egg-info/SOURCES.txt +1 -0
- bare_script-3.5.5/src/bare_script/include/unittest.bare +0 -229
- {bare_script-3.5.5 → bare_script-3.7.1}/LICENSE +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/pyproject.toml +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/__init__.py +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/__main__.py +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/baredoc.py +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/data.py +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/include/__init__.py +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/include/forms.bare +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/include/unittestMock.bare +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script/value.py +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script.egg-info/dependency_links.txt +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script.egg-info/entry_points.txt +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/src/bare_script.egg-info/requires.txt +0 -0
- {bare_script-3.5.5 → bare_script-3.7.1}/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.
|
|
3
|
+
Version: 3.7.1
|
|
4
4
|
Summary: bare-script
|
|
5
5
|
Home-page: https://github.com/craigahobbs/bare-script
|
|
6
6
|
Author: Craig A. Hobbs
|
|
@@ -10,7 +10,6 @@ Keywords: bare-script
|
|
|
10
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
12
|
Classifier: Operating System :: OS Independent
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
@@ -62,7 +61,7 @@ function. Then execute the script using the
|
|
|
62
61
|
[execute_script](https://craigahobbs.github.io/bare-script-py/scripts.html#execute-script)
|
|
63
62
|
function. For example:
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
``` python
|
|
66
65
|
from bare_script import execute_script, parse_script
|
|
67
66
|
|
|
68
67
|
# Parse the script
|
|
@@ -78,13 +77,13 @@ return N + ' times 2 is ' + double(N)
|
|
|
78
77
|
# Execute the script
|
|
79
78
|
globals = {'N': 10}
|
|
80
79
|
print(execute_script(script, {'globals': globals}))
|
|
81
|
-
|
|
80
|
+
```
|
|
82
81
|
|
|
83
82
|
This outputs:
|
|
84
83
|
|
|
85
|
-
|
|
84
|
+
```
|
|
86
85
|
10 times 2 is 20
|
|
87
|
-
|
|
86
|
+
```
|
|
88
87
|
|
|
89
88
|
|
|
90
89
|
### The BareScript Library
|
|
@@ -98,7 +97,7 @@ of the
|
|
|
98
97
|
[arrayLength](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='Array'&arraylength)
|
|
99
98
|
functions.
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
``` python
|
|
102
101
|
import urllib.request
|
|
103
102
|
|
|
104
103
|
from bare_script import execute_script, fetch_http, parse_script
|
|
@@ -114,13 +113,13 @@ return 'The BareScript Library has ' + arrayLength(objectGet(docs, 'functions'))
|
|
|
114
113
|
|
|
115
114
|
# Execute the script
|
|
116
115
|
print(execute_script(script, {'fetchFn': fetch_http}))
|
|
117
|
-
|
|
116
|
+
```
|
|
118
117
|
|
|
119
118
|
This outputs:
|
|
120
119
|
|
|
121
|
-
|
|
120
|
+
```
|
|
122
121
|
The BareScript Library has 105 functions
|
|
123
|
-
|
|
122
|
+
```
|
|
124
123
|
|
|
125
124
|
|
|
126
125
|
## Evaluating BareScript Expressions
|
|
@@ -139,7 +138,7 @@ a set of built-in, spreadsheet-like functions.
|
|
|
139
138
|
|
|
140
139
|
For example:
|
|
141
140
|
|
|
142
|
-
|
|
141
|
+
``` python
|
|
143
142
|
from bare_script import evaluate_expression, parse_expression
|
|
144
143
|
|
|
145
144
|
# Parse the expression
|
|
@@ -148,13 +147,13 @@ expr = parse_expression('2 * max(a, b, c)')
|
|
|
148
147
|
# Evaluate the expression
|
|
149
148
|
variables = {'a': 1, 'b': 2, 'c': 3}
|
|
150
149
|
print(evaluate_expression(expr, None, variables))
|
|
151
|
-
|
|
150
|
+
```
|
|
152
151
|
|
|
153
152
|
This outputs:
|
|
154
153
|
|
|
155
|
-
|
|
154
|
+
```
|
|
156
155
|
6
|
|
157
|
-
|
|
156
|
+
```
|
|
158
157
|
|
|
159
158
|
|
|
160
159
|
## The BareScript Command-Line Interface (CLI)
|
|
@@ -162,9 +161,9 @@ This outputs:
|
|
|
162
161
|
You can run BareScript from the command line using the BareScript CLI, "bare". BareScript script
|
|
163
162
|
files use the ".bare" file extension.
|
|
164
163
|
|
|
165
|
-
|
|
164
|
+
```
|
|
166
165
|
bare script.bare
|
|
167
|
-
|
|
166
|
+
```
|
|
168
167
|
|
|
169
168
|
**Note:** In the BareScript CLI, import statements and the
|
|
170
169
|
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='System'&systemfetch)
|
|
@@ -187,15 +186,15 @@ with functions for dynamically rendering Markdown text, drawing SVG images, etc.
|
|
|
187
186
|
|
|
188
187
|
For example:
|
|
189
188
|
|
|
190
|
-
|
|
189
|
+
~~~
|
|
191
190
|
# Markdown Application
|
|
192
191
|
|
|
193
192
|
This is a Markdown document with embedded BareScript:
|
|
194
193
|
|
|
195
|
-
|
|
194
|
+
``` markdown-script
|
|
196
195
|
markdownPrint('Hello, Markdown!')
|
|
197
|
-
~~~
|
|
198
196
|
```
|
|
197
|
+
~~~
|
|
199
198
|
|
|
200
199
|
|
|
201
200
|
## Development
|
|
@@ -203,6 +202,6 @@ markdownPrint('Hello, Markdown!')
|
|
|
203
202
|
This package is developed using [python-build](https://github.com/craigahobbs/python-build#readme).
|
|
204
203
|
It was started using [python-template](https://github.com/craigahobbs/python-template#readme) as follows:
|
|
205
204
|
|
|
206
|
-
|
|
205
|
+
```
|
|
207
206
|
template-specialize python-template/template/ bare-script-py/ -k package bare-script -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs'
|
|
208
|
-
|
|
207
|
+
```
|
|
@@ -36,7 +36,7 @@ function. Then execute the script using the
|
|
|
36
36
|
[execute_script](https://craigahobbs.github.io/bare-script-py/scripts.html#execute-script)
|
|
37
37
|
function. For example:
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
``` python
|
|
40
40
|
from bare_script import execute_script, parse_script
|
|
41
41
|
|
|
42
42
|
# Parse the script
|
|
@@ -52,13 +52,13 @@ return N + ' times 2 is ' + double(N)
|
|
|
52
52
|
# Execute the script
|
|
53
53
|
globals = {'N': 10}
|
|
54
54
|
print(execute_script(script, {'globals': globals}))
|
|
55
|
-
|
|
55
|
+
```
|
|
56
56
|
|
|
57
57
|
This outputs:
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
```
|
|
60
60
|
10 times 2 is 20
|
|
61
|
-
|
|
61
|
+
```
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
### The BareScript Library
|
|
@@ -72,7 +72,7 @@ of the
|
|
|
72
72
|
[arrayLength](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='Array'&arraylength)
|
|
73
73
|
functions.
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
``` python
|
|
76
76
|
import urllib.request
|
|
77
77
|
|
|
78
78
|
from bare_script import execute_script, fetch_http, parse_script
|
|
@@ -88,13 +88,13 @@ return 'The BareScript Library has ' + arrayLength(objectGet(docs, 'functions'))
|
|
|
88
88
|
|
|
89
89
|
# Execute the script
|
|
90
90
|
print(execute_script(script, {'fetchFn': fetch_http}))
|
|
91
|
-
|
|
91
|
+
```
|
|
92
92
|
|
|
93
93
|
This outputs:
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
```
|
|
96
96
|
The BareScript Library has 105 functions
|
|
97
|
-
|
|
97
|
+
```
|
|
98
98
|
|
|
99
99
|
|
|
100
100
|
## Evaluating BareScript Expressions
|
|
@@ -113,7 +113,7 @@ a set of built-in, spreadsheet-like functions.
|
|
|
113
113
|
|
|
114
114
|
For example:
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
``` python
|
|
117
117
|
from bare_script import evaluate_expression, parse_expression
|
|
118
118
|
|
|
119
119
|
# Parse the expression
|
|
@@ -122,13 +122,13 @@ expr = parse_expression('2 * max(a, b, c)')
|
|
|
122
122
|
# Evaluate the expression
|
|
123
123
|
variables = {'a': 1, 'b': 2, 'c': 3}
|
|
124
124
|
print(evaluate_expression(expr, None, variables))
|
|
125
|
-
|
|
125
|
+
```
|
|
126
126
|
|
|
127
127
|
This outputs:
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
```
|
|
130
130
|
6
|
|
131
|
-
|
|
131
|
+
```
|
|
132
132
|
|
|
133
133
|
|
|
134
134
|
## The BareScript Command-Line Interface (CLI)
|
|
@@ -136,9 +136,9 @@ This outputs:
|
|
|
136
136
|
You can run BareScript from the command line using the BareScript CLI, "bare". BareScript script
|
|
137
137
|
files use the ".bare" file extension.
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
```
|
|
140
140
|
bare script.bare
|
|
141
|
-
|
|
141
|
+
```
|
|
142
142
|
|
|
143
143
|
**Note:** In the BareScript CLI, import statements and the
|
|
144
144
|
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='System'&systemfetch)
|
|
@@ -161,15 +161,15 @@ with functions for dynamically rendering Markdown text, drawing SVG images, etc.
|
|
|
161
161
|
|
|
162
162
|
For example:
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
~~~
|
|
165
165
|
# Markdown Application
|
|
166
166
|
|
|
167
167
|
This is a Markdown document with embedded BareScript:
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
``` markdown-script
|
|
170
170
|
markdownPrint('Hello, Markdown!')
|
|
171
|
-
~~~
|
|
172
171
|
```
|
|
172
|
+
~~~
|
|
173
173
|
|
|
174
174
|
|
|
175
175
|
## Development
|
|
@@ -177,6 +177,6 @@ markdownPrint('Hello, Markdown!')
|
|
|
177
177
|
This package is developed using [python-build](https://github.com/craigahobbs/python-build#readme).
|
|
178
178
|
It was started using [python-template](https://github.com/craigahobbs/python-template#readme) as follows:
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
```
|
|
181
181
|
template-specialize python-template/template/ bare-script-py/ -k package bare-script -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs'
|
|
182
|
-
|
|
182
|
+
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = bare-script
|
|
3
|
-
version = 3.
|
|
3
|
+
version = 3.7.1
|
|
4
4
|
url = https://github.com/craigahobbs/bare-script
|
|
5
5
|
author = Craig A. Hobbs
|
|
6
6
|
author_email = craigahobbs@gmail.com
|
|
@@ -13,7 +13,6 @@ classifiers =
|
|
|
13
13
|
Development Status :: 5 - Production/Stable
|
|
14
14
|
Intended Audience :: Developers
|
|
15
15
|
Operating System :: OS Independent
|
|
16
|
-
Programming Language :: Python :: 3.9
|
|
17
16
|
Programming Language :: Python :: 3.10
|
|
18
17
|
Programming Language :: Python :: 3.11
|
|
19
18
|
Programming Language :: Python :: 3.12
|
|
@@ -40,7 +40,6 @@ def main(argv=None):
|
|
|
40
40
|
|
|
41
41
|
status_code = 0
|
|
42
42
|
inline_count = 0
|
|
43
|
-
error_name = None
|
|
44
43
|
try:
|
|
45
44
|
# Evaluate the global variable expression arguments
|
|
46
45
|
globals_ = {}
|
|
@@ -66,21 +65,19 @@ def main(argv=None):
|
|
|
66
65
|
raise ValueError(f'Failed to load "{script_value}"')
|
|
67
66
|
else:
|
|
68
67
|
inline_count += 1
|
|
69
|
-
script_name = f'
|
|
68
|
+
script_name = f'<string{inline_count if inline_count > 1 else ""}>'
|
|
70
69
|
script_source = script_value
|
|
71
70
|
|
|
72
71
|
# Parse the script source
|
|
73
|
-
|
|
74
|
-
script = parse_script(script_source)
|
|
72
|
+
script = parse_script(script_source, 1, script_name)
|
|
75
73
|
|
|
76
74
|
# Run the bare-script linter?
|
|
77
75
|
if args.static or args.debug:
|
|
78
76
|
warnings = lint_script(script)
|
|
79
|
-
warning_prefix = f'BareScript: Static analysis "{script_name}" ...'
|
|
80
77
|
if not warnings:
|
|
81
|
-
print(f'{
|
|
78
|
+
print(f'BareScript: Static analysis "{script_name}" ... OK')
|
|
82
79
|
else:
|
|
83
|
-
print(f'{
|
|
80
|
+
print(f'BareScript: Static analysis "{script_name}" ... {len(warnings)} warning{"s" if len(warnings) > 1 else ""}:')
|
|
84
81
|
for warning in warnings:
|
|
85
82
|
print(f'BareScript: {warning}')
|
|
86
83
|
if args.static:
|
|
@@ -114,8 +111,6 @@ def main(argv=None):
|
|
|
114
111
|
break
|
|
115
112
|
|
|
116
113
|
except Exception as exc:
|
|
117
|
-
if error_name is not None:
|
|
118
|
-
print(f'{error_name}:')
|
|
119
114
|
print(str(exc).strip())
|
|
120
115
|
status_code = 1
|
|
121
116
|
|
|
@@ -67,7 +67,7 @@ function argsValidate(arguments):
|
|
|
67
67
|
name = objectGet(argument, 'name')
|
|
68
68
|
if objectHas(argNames, name):
|
|
69
69
|
validatedArguments = null
|
|
70
|
-
systemLogDebug('
|
|
70
|
+
systemLogDebug('args.bare: Duplicate argument "' + name + '"')
|
|
71
71
|
else:
|
|
72
72
|
objectSet(argNames, name, true)
|
|
73
73
|
endif
|
|
@@ -151,7 +151,7 @@ function argsURL(arguments, args, explicit, headerText, url):
|
|
|
151
151
|
if args != null:
|
|
152
152
|
for name in objectKeys(args):
|
|
153
153
|
if !objectHas(argNames, name):
|
|
154
|
-
systemLogDebug('
|
|
154
|
+
systemLogDebug('args.bare: Unknown argument "' + name + '"')
|
|
155
155
|
endif
|
|
156
156
|
endfor
|
|
157
157
|
endif
|
|
@@ -279,7 +279,7 @@ function argsValidateValue(value, type, global, warn):
|
|
|
279
279
|
value = !!value
|
|
280
280
|
elif valueType != 'boolean':
|
|
281
281
|
if warn != false:
|
|
282
|
-
systemLogDebug('
|
|
282
|
+
systemLogDebug('args.bare: Invalid value ' + jsonStringify(value) + ' for URL argument "' + global + '"')
|
|
283
283
|
endif
|
|
284
284
|
value = null
|
|
285
285
|
endif
|
|
@@ -291,7 +291,7 @@ function argsValidateValue(value, type, global, warn):
|
|
|
291
291
|
endif
|
|
292
292
|
if valueType != 'datetime' || datetimeHour(value) != 0 || datetimeMinute(value) != 0 || datetimeSecond(value) != 0:
|
|
293
293
|
if warn != false:
|
|
294
|
-
systemLogDebug('
|
|
294
|
+
systemLogDebug('args.bare: Invalid value ' + jsonStringify(valueOrig) + ' for URL argument "' + global + '"')
|
|
295
295
|
endif
|
|
296
296
|
value = null
|
|
297
297
|
endif
|
|
@@ -303,21 +303,21 @@ function argsValidateValue(value, type, global, warn):
|
|
|
303
303
|
endif
|
|
304
304
|
if valueType != 'datetime':
|
|
305
305
|
if warn != false:
|
|
306
|
-
systemLogDebug('
|
|
306
|
+
systemLogDebug('args.bare: Invalid value ' + jsonStringify(valueOrig) + ' for URL argument "' + global + '"')
|
|
307
307
|
endif
|
|
308
308
|
value = null
|
|
309
309
|
endif
|
|
310
310
|
elif type == 'float':
|
|
311
311
|
if valueType != 'number':
|
|
312
312
|
if warn != false:
|
|
313
|
-
systemLogDebug('
|
|
313
|
+
systemLogDebug('args.bare: Invalid value ' + jsonStringify(value) + ' for URL argument "' + global + '"')
|
|
314
314
|
endif
|
|
315
315
|
value = null
|
|
316
316
|
endif
|
|
317
317
|
elif type == 'int':
|
|
318
318
|
if valueType != 'number' || value != mathFloor(value):
|
|
319
319
|
if warn != false:
|
|
320
|
-
systemLogDebug('
|
|
320
|
+
systemLogDebug('args.bare: Invalid value ' + jsonStringify(value) + ' for URL argument "' + global + '"')
|
|
321
321
|
endif
|
|
322
322
|
value = null
|
|
323
323
|
endif
|
|
@@ -325,7 +325,7 @@ function argsValidateValue(value, type, global, warn):
|
|
|
325
325
|
# type == 'string'
|
|
326
326
|
if valueType != 'string':
|
|
327
327
|
if warn != false:
|
|
328
|
-
systemLogDebug('
|
|
328
|
+
systemLogDebug('args.bare: Invalid value ' + jsonStringify(value) + ' for URL argument "' + global + '"')
|
|
329
329
|
endif
|
|
330
330
|
value = null
|
|
331
331
|
endif
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Licensed under the MIT License
|
|
2
|
+
# https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Include sentinel
|
|
6
|
+
if systemGlobalGet('dataTableSentinel'):
|
|
7
|
+
return
|
|
8
|
+
endif
|
|
9
|
+
dataTableSentinel = true
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# The data table model's Schema Markdown
|
|
13
|
+
dataTableTypes = schemaParse( \
|
|
14
|
+
'group "Data Table"', \
|
|
15
|
+
'', \
|
|
16
|
+
'', \
|
|
17
|
+
'# A data table model', \
|
|
18
|
+
'struct DataTable', \
|
|
19
|
+
'', \
|
|
20
|
+
" # The table's fields", \
|
|
21
|
+
' optional string[len > 0] fields', \
|
|
22
|
+
'', \
|
|
23
|
+
" # The table's category fields", \
|
|
24
|
+
' optional string[len > 0] categories', \
|
|
25
|
+
'', \
|
|
26
|
+
' # The field formatting for "categories" and "fields"', \
|
|
27
|
+
' optional DataTableFieldFormat{len > 0} formats', \
|
|
28
|
+
'', \
|
|
29
|
+
' # The numeric formatting precision (default is 2)', \
|
|
30
|
+
' optional int(>= 0) precision', \
|
|
31
|
+
'', \
|
|
32
|
+
' # The datetime format', \
|
|
33
|
+
' optional DataTableDatetimeFormat datetime', \
|
|
34
|
+
'', \
|
|
35
|
+
' # If true, trim formatted values (default is true)', \
|
|
36
|
+
' optional bool trim', \
|
|
37
|
+
'', \
|
|
38
|
+
'', \
|
|
39
|
+
'# A data table field formatting model', \
|
|
40
|
+
'struct DataTableFieldFormat', \
|
|
41
|
+
'', \
|
|
42
|
+
' # The field alignment', \
|
|
43
|
+
' optional DataTableFieldAlignment align', \
|
|
44
|
+
'', \
|
|
45
|
+
" # If true, don't wrap text", \
|
|
46
|
+
' optional bool nowrap', \
|
|
47
|
+
'', \
|
|
48
|
+
' # If true, format the field as Markdown', \
|
|
49
|
+
' optional bool markdown', \
|
|
50
|
+
'', \
|
|
51
|
+
' # The field header (default is the field name)', \
|
|
52
|
+
' optional string header', \
|
|
53
|
+
'', \
|
|
54
|
+
'', \
|
|
55
|
+
'# A field alignment', \
|
|
56
|
+
'enum DataTableFieldAlignment', \
|
|
57
|
+
' left', \
|
|
58
|
+
' right', \
|
|
59
|
+
' center', \
|
|
60
|
+
'', \
|
|
61
|
+
'', \
|
|
62
|
+
'# A datetime format', \
|
|
63
|
+
'enum DataTableDatetimeFormat', \
|
|
64
|
+
'', \
|
|
65
|
+
' # ISO datetime year format', \
|
|
66
|
+
' year', \
|
|
67
|
+
'', \
|
|
68
|
+
' # ISO datetime month format', \
|
|
69
|
+
' month', \
|
|
70
|
+
'', \
|
|
71
|
+
' # ISO datetime day format', \
|
|
72
|
+
' day' \
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# $function: dataTableMarkdown
|
|
77
|
+
# $group: dataTable.bare
|
|
78
|
+
# $doc: Create the array of Markdown table line strings
|
|
79
|
+
# $arg data: The array of row objects
|
|
80
|
+
# $arg model: The [data table model](includeModel.html#var.vName='DataTable')
|
|
81
|
+
# $return: The array of Markdown table line strings
|
|
82
|
+
function dataTableMarkdown(data, model):
|
|
83
|
+
# Validate the data
|
|
84
|
+
data = dataValidate(data)
|
|
85
|
+
if data == null:
|
|
86
|
+
return null
|
|
87
|
+
endif
|
|
88
|
+
|
|
89
|
+
# Validate the table model
|
|
90
|
+
if model != null && !schemaValidate(dataTableTypes, 'DataTable', model):
|
|
91
|
+
return null
|
|
92
|
+
endif
|
|
93
|
+
|
|
94
|
+
# Determine the table fields
|
|
95
|
+
fields = arrayNew()
|
|
96
|
+
modelFields = if(model != null, objectGet(model, 'fields'))
|
|
97
|
+
modelCategories = if(model != null, objectGet(model, 'categories'))
|
|
98
|
+
if modelFields != null || modelCategories != null:
|
|
99
|
+
if modelCategories != null:
|
|
100
|
+
arrayExtend(fields, modelCategories)
|
|
101
|
+
endif
|
|
102
|
+
if modelFields != null:
|
|
103
|
+
arrayExtend(fields, modelFields)
|
|
104
|
+
endif
|
|
105
|
+
elif arrayLength(data) > 0:
|
|
106
|
+
arrayExtend(fields, objectKeys(arrayGet(data, 0)))
|
|
107
|
+
endif
|
|
108
|
+
if !arrayLength(fields):
|
|
109
|
+
return null
|
|
110
|
+
endif
|
|
111
|
+
|
|
112
|
+
# Get precision and formatting
|
|
113
|
+
precisionDatetime = if(model != null, objectGet(model, 'datetime'))
|
|
114
|
+
precisionNumber = if(model != null, objectGet(model, 'precision', 2), 2)
|
|
115
|
+
precisionTrim = if(model != null, objectGet(model, 'trim', true), true)
|
|
116
|
+
formats = if(model != null, objectGet(model, 'formats'))
|
|
117
|
+
|
|
118
|
+
# Compute the field header widths
|
|
119
|
+
widths = objectNew()
|
|
120
|
+
for field in fields:
|
|
121
|
+
fieldWidth = stringLength(field)
|
|
122
|
+
if !objectHas(widths, field) || fieldWidth > objectGet(widths, field):
|
|
123
|
+
objectSet(widths, field, fieldWidth)
|
|
124
|
+
endif
|
|
125
|
+
endfor
|
|
126
|
+
|
|
127
|
+
# Compute the formatted field value strings and widths
|
|
128
|
+
dataFormat = arrayNew()
|
|
129
|
+
for row in data:
|
|
130
|
+
rowFormat = objectNew()
|
|
131
|
+
arrayPush(dataFormat, rowFormat)
|
|
132
|
+
for field in fields:
|
|
133
|
+
# Format the value
|
|
134
|
+
value = objectGet(row, field)
|
|
135
|
+
valueType = systemType(value)
|
|
136
|
+
if valueType == 'string':
|
|
137
|
+
valueFormat = value
|
|
138
|
+
elif valueType == 'number':
|
|
139
|
+
valueFormat = numberToFixed(value, precisionNumber, precisionTrim)
|
|
140
|
+
elif valueType == 'datetime':
|
|
141
|
+
valueFormat = datetimeISOFormat(value, precisionDatetime != null)
|
|
142
|
+
else:
|
|
143
|
+
valueFormat = stringNew(value)
|
|
144
|
+
endif
|
|
145
|
+
objectSet(rowFormat, field, valueFormat)
|
|
146
|
+
|
|
147
|
+
# Update the field width
|
|
148
|
+
valueWidth = stringLength(valueFormat)
|
|
149
|
+
if !objectHas(widths, field) || valueWidth > objectGet(widths, field):
|
|
150
|
+
objectSet(widths, field, valueWidth)
|
|
151
|
+
endif
|
|
152
|
+
endfor
|
|
153
|
+
endfor
|
|
154
|
+
|
|
155
|
+
# Compute the field header separator
|
|
156
|
+
headerSeparator = ''
|
|
157
|
+
for field in fields:
|
|
158
|
+
width = objectGet(widths, field)
|
|
159
|
+
format = if(formats != null, objectGet(formats, field))
|
|
160
|
+
align = if(format != null, objectGet(format, 'align'))
|
|
161
|
+
alignLeft = if(align == 'center', ':', '-')
|
|
162
|
+
alignRight = if(align == 'center' || align == 'right', ':', '-')
|
|
163
|
+
headerSeparator = headerSeparator + '|' + alignLeft + dataTableMarkdownField('', width, align, '-') + alignRight
|
|
164
|
+
endfor
|
|
165
|
+
headerSeparator = headerSeparator + '|'
|
|
166
|
+
|
|
167
|
+
# Compute the table header fields
|
|
168
|
+
headerFields = ''
|
|
169
|
+
for field in fields:
|
|
170
|
+
width = objectGet(widths, field)
|
|
171
|
+
format = if(formats != null, objectGet(formats, field))
|
|
172
|
+
align = if(format != null, objectGet(format, 'align'))
|
|
173
|
+
header = if(format != null, objectGet(format, 'header', field), field)
|
|
174
|
+
headerFields = headerFields + '| ' + dataTableMarkdownField(header, width, align, ' ') + ' '
|
|
175
|
+
endfor
|
|
176
|
+
headerFields = headerFields + '|'
|
|
177
|
+
|
|
178
|
+
# Output the table header
|
|
179
|
+
lines = arrayNew()
|
|
180
|
+
arrayPush(lines, headerFields)
|
|
181
|
+
arrayPush(lines, headerSeparator)
|
|
182
|
+
|
|
183
|
+
# Output each row
|
|
184
|
+
for row in dataFormat:
|
|
185
|
+
line = ''
|
|
186
|
+
for field in fields:
|
|
187
|
+
width = objectGet(widths, field)
|
|
188
|
+
format = if(formats != null, objectGet(formats, field))
|
|
189
|
+
align = if(format != null, objectGet(format, 'align'))
|
|
190
|
+
line = line + '| ' + dataTableMarkdownField(objectGet(row, field), width, align, ' ') + ' '
|
|
191
|
+
endfor
|
|
192
|
+
line = line + '|'
|
|
193
|
+
arrayPush(lines, line)
|
|
194
|
+
endfor
|
|
195
|
+
|
|
196
|
+
return lines
|
|
197
|
+
endfunction
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
# Helper to generate the Markdown field text
|
|
201
|
+
function dataTableMarkdownField(value, width, align, fill):
|
|
202
|
+
spaces = width - stringLength(value)
|
|
203
|
+
if align == 'right':
|
|
204
|
+
return stringRepeat(fill, spaces) + value
|
|
205
|
+
elif align == 'center':
|
|
206
|
+
spacesLeft = mathFloor(spaces / 2)
|
|
207
|
+
spacesRight = spaces - spacesLeft
|
|
208
|
+
return stringRepeat(fill, spacesLeft) + value + stringRepeat(fill, spacesRight)
|
|
209
|
+
endif
|
|
210
|
+
return value + stringRepeat(fill, spaces)
|
|
211
|
+
endfunction
|
|
@@ -99,7 +99,7 @@ function diffLines(left, right):
|
|
|
99
99
|
ixRight = ixRight + 1
|
|
100
100
|
endwhile
|
|
101
101
|
if identicalLines:
|
|
102
|
-
arrayPush(
|
|
102
|
+
arrayPush(diffs, objectNew('type', 'Identical', 'lines', identicalLines))
|
|
103
103
|
continue
|
|
104
104
|
endif
|
|
105
105
|
|