html-table-builder 0.1.1__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.
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: html-table-builder
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Library for creating HTML tables based on templates
|
|
5
|
+
Author-email: Evgeny Borisov <maybe_i_will_read_it@internet.ru>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://gitflic.ru/project/evgeniiborisov1983/html-table-builder
|
|
8
|
+
Project-URL: Repository, https://gitflic.ru/project/evgeniiborisov1983/html-table-builder.git
|
|
9
|
+
Keywords: html,table,builder,template,grid
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
13
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.13.2
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: formats-to-structural-nodes>=0.1.0
|
|
19
|
+
Requires-Dist: more-structural-nodes>=0.1.0
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# The library for generating html (vertical) tables
|
|
23
|
+
This library is necessary for creating html tables from prepared data contained in json formats, directories, arrays, and structural nodes (an additional library is more-structural-nodes). The library allows you to perform the following operations:
|
|
24
|
+
1. Group data by parameter value;
|
|
25
|
+
2. Sort data by parameter;
|
|
26
|
+
3. Output parameter names;
|
|
27
|
+
4. Output parameter values;
|
|
28
|
+
5. Output property values (for BaseStructuralNode);
|
|
29
|
+
6. Set auto-increment cells;
|
|
30
|
+
7. Set a dictionary of names (for parameter conversion);
|
|
31
|
+
8. Set headlines;
|
|
32
|
+
9. Set table properties;
|
|
33
|
+
## Template formation rules
|
|
34
|
+
At the very top of the hierarchy is a table. The table is not allocated in a separate block.
|
|
35
|
+
The next level is multiblock. Combines an array of blocks. For example, there may be a header block and a data block. In fact, the number of blocks is not limited.
|
|
36
|
+
|
|
37
|
+
`"multiblock": {}`
|
|
38
|
+
|
|
39
|
+
There is an array of blocks inside the multi block.
|
|
40
|
+
|
|
41
|
+
` "multiblock": {
|
|
42
|
+
"block_drivers": []
|
|
43
|
+
}`
|
|
44
|
+
|
|
45
|
+
The block can be one of the following types ("type"):
|
|
46
|
+
1. object - incoming data in the block is perceived as an object. This type is necessary for non-duplicate data.
|
|
47
|
+
2. array - incoming data is an array. Accordingly, corresponding cells will be created for each element of the array.
|
|
48
|
+
3. array_by_object - all parameters will be extracted from the incoming object and processed as an array. This can be useful if the data is decomposed as parameters rather than an array.
|
|
49
|
+
|
|
50
|
+
The block consists of lines.
|
|
51
|
+
|
|
52
|
+
`"rows": []`
|
|
53
|
+
|
|
54
|
+
The strings themselves consist of containers.
|
|
55
|
+
|
|
56
|
+
`"containers": []`
|
|
57
|
+
|
|
58
|
+
A container either describes the behavior for displaying data, or allows you to output a more complex data structure, starting with a multiblock. The nesting level is unlimited.
|
|
59
|
+
|
|
60
|
+
An example of a container that allows you to output a multiblock:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
[
|
|
64
|
+
{
|
|
65
|
+
"type": "multiblock",
|
|
66
|
+
"source": "multi_test",
|
|
67
|
+
"multiblock": {
|
|
68
|
+
"block_drivers": [
|
|
69
|
+
{
|
|
70
|
+
"type": "array",
|
|
71
|
+
"rows": [
|
|
72
|
+
{
|
|
73
|
+
"containers": [
|
|
74
|
+
{
|
|
75
|
+
"type": "value",
|
|
76
|
+
"source": "a"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"type": "value",
|
|
80
|
+
"source": "b"
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
To reduce the nesting, it is allowed to specify the name of the multiblock, in accordance with the example:
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
[
|
|
96
|
+
{
|
|
97
|
+
"type": "multiblock",
|
|
98
|
+
"multiblock": "arrays_cena"
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The "multiblocks" section in the root directory is used to describe the multiblock.:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
"multiblocks": {
|
|
107
|
+
"{multiblock name}": {
|
|
108
|
+
"block_drivers": [
|
|
109
|
+
{
|
|
110
|
+
...
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The following options are available to specify the filling of the cell data.
|
|
118
|
+
|
|
119
|
+
Filling in the attribute name:
|
|
120
|
+
```
|
|
121
|
+
{
|
|
122
|
+
"type": "name"
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Filling in with a constant:
|
|
127
|
+
```
|
|
128
|
+
{
|
|
129
|
+
"type": "constant",
|
|
130
|
+
"value": "{value}"
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Filling in an attribute value along an arbitrary path relative to the incoming object:
|
|
135
|
+
```
|
|
136
|
+
{
|
|
137
|
+
"type": "value",
|
|
138
|
+
"source": "{attribute path relative to the incoming object}"
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Filling in the attribute value:
|
|
143
|
+
```
|
|
144
|
+
{
|
|
145
|
+
"type": "value"
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Filling in the auto-increment value:
|
|
150
|
+
```
|
|
151
|
+
{
|
|
152
|
+
"type": "auto-increment"
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Filling in the node property value:
|
|
157
|
+
```
|
|
158
|
+
{
|
|
159
|
+
"type": "parameter",
|
|
160
|
+
"source": "parameter name"
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
# Example
|
|
165
|
+
## Template
|
|
166
|
+
```
|
|
167
|
+
{
|
|
168
|
+
"parameters": {
|
|
169
|
+
"table": {
|
|
170
|
+
"border": "2"
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
"dictionaries": {
|
|
174
|
+
"main": {
|
|
175
|
+
"True": "Firm and clear",
|
|
176
|
+
"description": "Amazing narrative",
|
|
177
|
+
"value": "Meaningful",
|
|
178
|
+
"visible": "Look",
|
|
179
|
+
"victory": "Live!!!"
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
"multiblock": {
|
|
183
|
+
"block_drivers": [
|
|
184
|
+
{
|
|
185
|
+
"type": "object",
|
|
186
|
+
"rows": [
|
|
187
|
+
{
|
|
188
|
+
"containers": [
|
|
189
|
+
{
|
|
190
|
+
"type": "constant",
|
|
191
|
+
"value": "Parameter"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"type": "constant",
|
|
195
|
+
"value": "Name"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"type": "constant",
|
|
199
|
+
"value": "Value"
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"type": "array",
|
|
207
|
+
"rows": [
|
|
208
|
+
{
|
|
209
|
+
"containers": [
|
|
210
|
+
{
|
|
211
|
+
"type": "value",
|
|
212
|
+
"source": "name"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"type": "multiblock",
|
|
216
|
+
"multiblock": "info"
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
]
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
},
|
|
224
|
+
"multiblocks": {
|
|
225
|
+
"info": {
|
|
226
|
+
"block_drivers": [
|
|
227
|
+
{
|
|
228
|
+
"source": "info",
|
|
229
|
+
"type": "object_as_array",
|
|
230
|
+
"rows": [
|
|
231
|
+
{
|
|
232
|
+
"containers": [
|
|
233
|
+
{
|
|
234
|
+
"type": "name",
|
|
235
|
+
"dictionary": "main"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"type": "value",
|
|
239
|
+
"dictionary": "main"
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
## Data
|
|
251
|
+
```
|
|
252
|
+
[
|
|
253
|
+
{
|
|
254
|
+
"name": "First",
|
|
255
|
+
"info": {
|
|
256
|
+
"description": "first one",
|
|
257
|
+
"value": 3,
|
|
258
|
+
"visible": true
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"name": "Second",
|
|
263
|
+
"info": {
|
|
264
|
+
"description": "Difficult second",
|
|
265
|
+
"value": "Something smart",
|
|
266
|
+
"visible": true,
|
|
267
|
+
"victory": "Yes"
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
```
|
|
272
|
+
## Result
|
|
273
|
+
<table border="2">
|
|
274
|
+
<tbody>
|
|
275
|
+
<tr>
|
|
276
|
+
<td colspan="1", rowspan="1"><div>Parameter</div></td>
|
|
277
|
+
<td colspan="1", rowspan="1"><div>Name</div></td>
|
|
278
|
+
<td colspan="1", rowspan="1"><div>Value</div></td>
|
|
279
|
+
</tr>
|
|
280
|
+
<tr>
|
|
281
|
+
<td colspan="1", rowspan="3"><div>The first</div></td>
|
|
282
|
+
<td colspan="1", rowspan="1"><div>Amazing narration</div></td>
|
|
283
|
+
<td colspan="1", rowspan="1"><div>Just the first</div></td>
|
|
284
|
+
</tr>
|
|
285
|
+
<tr>
|
|
286
|
+
<td colspan="1", rowspan="1"><div>Significant value</div></td>
|
|
287
|
+
<td colspan="1", rowspan="1"><div>3</div></td>
|
|
288
|
+
</tr>
|
|
289
|
+
<tr>
|
|
290
|
+
<td colspan="1", rowspan="1"><div>Visibility</div></td>
|
|
291
|
+
<td colspan="1", rowspan="1"><div>Firmly and clearly</div></td>
|
|
292
|
+
</tr>
|
|
293
|
+
<tr>
|
|
294
|
+
<td colspan="1", rowspan="4"><div>The second</div></td>
|
|
295
|
+
<td colspan="1", rowspan="1"><div>Amazing narration</div></td>
|
|
296
|
+
<td colspan="1", rowspan="1"><div>The second one is difficult</div></td>
|
|
297
|
+
</tr>
|
|
298
|
+
<tr>
|
|
299
|
+
<td colspan="1", rowspan="1"><div>Significant value</div></td>
|
|
300
|
+
<td colspan="1", rowspan="1"><div>Something smart</div></td>
|
|
301
|
+
</tr>
|
|
302
|
+
<tr>
|
|
303
|
+
<td colspan="1", rowspan="1"><div>Visibility</div></td>
|
|
304
|
+
<td colspan="1", rowspan="1"><div>Firmly and clearly</div></td>
|
|
305
|
+
</tr>
|
|
306
|
+
<tr>
|
|
307
|
+
<td colspan="1", rowspan="1"><div>Vivat!!!</div></td>
|
|
308
|
+
<td colspan="1", rowspan="1"><div>Yes</div></td>
|
|
309
|
+
</tr>
|
|
310
|
+
</tbody>
|
|
311
|
+
</table>
|
|
312
|
+
|
|
313
|
+
# Usage
|
|
314
|
+
If you need to create only one table using a specific template, you can use the create_table function.
|
|
315
|
+
|
|
316
|
+
Example
|
|
317
|
+
```
|
|
318
|
+
from html_table_builder import create_table
|
|
319
|
+
import json
|
|
320
|
+
|
|
321
|
+
template_file_name = "template.json"
|
|
322
|
+
table_file_name = "test_table.json"
|
|
323
|
+
result_file_name = "result.html"
|
|
324
|
+
|
|
325
|
+
if __name__ == "__main__":
|
|
326
|
+
with open(template_file_name, mode="r", encoding="utf-8") as f:
|
|
327
|
+
template = json.load(f)
|
|
328
|
+
with open(table_file_name, mode="r", encoding="utf-8") as f:
|
|
329
|
+
table_json = json.load(f)
|
|
330
|
+
result = create_table(table_json, template)
|
|
331
|
+
with open(result_file_name, mode="w", encoding="utf-8") as f:
|
|
332
|
+
f.write(result)
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
If you need to create several tables with different data sources for the same template, it is better to create a table generator object and create tables through it.
|
|
336
|
+
|
|
337
|
+
Example
|
|
338
|
+
```
|
|
339
|
+
from html_table_builder import TableGenerator
|
|
340
|
+
import json
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
if __name__ == "__main__":
|
|
344
|
+
with open(template_file_name, mode="r", encoding="utf-8") as f:
|
|
345
|
+
template = json.load(f)
|
|
346
|
+
table_generator = TableGenerator(template)
|
|
347
|
+
with open(table_file_name, mode="r", encoding="utf-8") as f:
|
|
348
|
+
table_json = json.load(f)
|
|
349
|
+
result = table_generator.create_table(table_json)
|
|
350
|
+
with open(result_file_name, mode="w", encoding="utf-8") as f:
|
|
351
|
+
f.write(result)
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
# About data conversion for table cells
|
|
355
|
+
An object of the converter class inherited from the ConverterInterface interface is used to convert data from the source into data from table cells. A method must be implemented inside the interface.:
|
|
356
|
+
|
|
357
|
+
- def convert(self, base_value: Any) -> str
|
|
358
|
+
|
|
359
|
+
The converter object is passed by the last (optional) parameter in the TableGenerator constructor: TableGenerator(template, new_converter). Or when using the function: create_table(table_json, template, new_converter).
|
|
360
|
+
If you don't pass your own object, then use your own one, which converts the received value to a string and wraps it in a div tag.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
html_table_builder/__init__.py,sha256=Gh11iAh8iSnHpiG1BYHDESBg-2qvXFCFz34LExX1Bmw,69
|
|
2
|
+
html_table_builder-0.1.1.dist-info/licenses/LICENSE,sha256=H6bxDNp8-rCLTMRFiiszgr8wsm3Xp3epcE27DGXXg7g,1107
|
|
3
|
+
html_table_builder-0.1.1.dist-info/METADATA,sha256=SPEpvR6PGY8Rlp2p6m86eNSEO5fKDeQEiON0zOmOSVg,11177
|
|
4
|
+
html_table_builder-0.1.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
html_table_builder-0.1.1.dist-info/top_level.txt,sha256=j5o_FILhdoHxus9canCN_iBMs4WlbDOwD-Ly6B2Q5x0,19
|
|
6
|
+
html_table_builder-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2026] [Borisov Evgeny Mikhailovich]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
html_table_builder
|