pdfrender 0.1.0__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.
- pdf_render/__init__.py +25 -0
- pdf_render/data/__init__.py +5 -0
- pdf_render/data/accessor.py +161 -0
- pdf_render/data/importer.py +209 -0
- pdf_render/data/model_field_typing.py +159 -0
- pdf_render/import_functions.py +43 -0
- pdf_render/md/__init__.py +3 -0
- pdf_render/md/extensions/__init__.py +13 -0
- pdf_render/md/extensions/columns.py +47 -0
- pdf_render/md/extensions/flex_wrap.py +52 -0
- pdf_render/md/extensions/muted_text.py +42 -0
- pdf_render/md/extensions/nerdfont_glyph.py +37 -0
- pdf_render/md/extensions/page_break.py +39 -0
- pdf_render/md/rendering.py +29 -0
- pdf_render/pdf/__init__.py +5 -0
- pdf_render/pdf/document_template.py +45 -0
- pdf_render/pdf/metadata.py +38 -0
- pdf_render/pdf/options.py +64 -0
- pdf_render/pdf/rendering.py +40 -0
- pdf_render/templates/__init__.py +4 -0
- pdf_render/templates/environment.py +158 -0
- pdf_render/templates/filters/__init__.py +9 -0
- pdf_render/templates/filters/format_filters.py +34 -0
- pdf_render/templates/filters/getter_filters.py +45 -0
- pdf_render/templates/rendering.py +75 -0
- pdf_render/templates/tests/__init__.py +0 -0
- pdf_render/user_input/__init__.py +3 -0
- pdf_render/user_input/undefined_variable_form.py +321 -0
- pdfrender-0.1.0.dist-info/METADATA +96 -0
- pdfrender-0.1.0.dist-info/RECORD +34 -0
- pdfrender-0.1.0.dist-info/WHEEL +5 -0
- pdfrender-0.1.0.dist-info/entry_points.txt +2 -0
- pdfrender-0.1.0.dist-info/licenses/LICENSE +21 -0
- pdfrender-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Any, Mapping, Sequence
|
|
3
|
+
|
|
4
|
+
from jinja2 import FileSystemLoader
|
|
5
|
+
|
|
6
|
+
from pdf_render.data.accessor import DBAccessor
|
|
7
|
+
from pdf_render.import_functions import get_functions_by_prefix_from_modules
|
|
8
|
+
from pdf_render.templates.environment import TypedVariableEnvironment
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def new_template_environment(
|
|
12
|
+
templates_dir: Path,
|
|
13
|
+
filters_modules: str | Sequence[str] = None,
|
|
14
|
+
filters_func_prefix: str = "jinja_filter",
|
|
15
|
+
tests_modules: str | Sequence[str] = None,
|
|
16
|
+
tests_func_prefix: str = "jinja_test",
|
|
17
|
+
trim_func_prefix: bool = True,
|
|
18
|
+
db_accessor: DBAccessor = None,
|
|
19
|
+
globals_mapping: Mapping[str, Any] = None,
|
|
20
|
+
**jinja2_env_kwargs,
|
|
21
|
+
) -> TypedVariableEnvironment:
|
|
22
|
+
"""Build a `TypedVariableEnvironment` wired up with filters, tests, and globals.
|
|
23
|
+
|
|
24
|
+
Discovers Jinja2 filter/test functions by name prefix from
|
|
25
|
+
`pdf_render.templates.filters`/`pdf_render.templates.tests` plus any
|
|
26
|
+
additional modules given, and registers them on the returned
|
|
27
|
+
environment. A `DBAccessor` (or plain mapping) can be supplied as the
|
|
28
|
+
environment's globals so templates can query the database directly.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
templates_dir: The directory to load templates from.
|
|
32
|
+
filters_modules: Additional dotted module path(s) to search for
|
|
33
|
+
filter functions.
|
|
34
|
+
filters_func_prefix: The function name prefix that marks a function
|
|
35
|
+
as a Jinja2 filter.
|
|
36
|
+
tests_modules: Additional dotted module path(s) to search for test
|
|
37
|
+
functions.
|
|
38
|
+
tests_func_prefix: The function name prefix that marks a function as
|
|
39
|
+
a Jinja2 test.
|
|
40
|
+
trim_func_prefix: Whether to strip the prefix from the registered
|
|
41
|
+
filter/test name.
|
|
42
|
+
db_accessor: A `DBAccessor` (or mapping) to use as the environment's
|
|
43
|
+
globals, enabling database access from templates.
|
|
44
|
+
globals_mapping: Additional global variables to merge into the
|
|
45
|
+
environment's globals.
|
|
46
|
+
**jinja2_env_kwargs: Additional keyword arguments passed through to
|
|
47
|
+
`TypedVariableEnvironment`/`jinja2.Environment`.
|
|
48
|
+
See [Jinja2.Environment docs](https://jinja.palletsprojects.com/en/stable/api/#jinja2.Environment)
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
A configured `TypedVariableEnvironment`.
|
|
52
|
+
"""
|
|
53
|
+
filter_module_names = ["pdf_render.templates.filters"]
|
|
54
|
+
if isinstance(filters_modules, str):
|
|
55
|
+
filter_module_names.append(filters_modules)
|
|
56
|
+
elif isinstance(filters_modules, Sequence):
|
|
57
|
+
filter_module_names = [*filters_modules, *filter_module_names]
|
|
58
|
+
filters_dict = get_functions_by_prefix_from_modules(filter_module_names, filters_func_prefix, trim_func_prefix)
|
|
59
|
+
|
|
60
|
+
tests_module_names = ["pdf_render.templates.tests"]
|
|
61
|
+
if isinstance(tests_modules, str):
|
|
62
|
+
tests_module_names.append(tests_modules)
|
|
63
|
+
elif isinstance(filters_modules, Sequence):
|
|
64
|
+
tests_module_names = (*tests_modules, tests_module_names)
|
|
65
|
+
tests_dict = get_functions_by_prefix_from_modules(tests_module_names, tests_func_prefix, trim_func_prefix)
|
|
66
|
+
|
|
67
|
+
environment_loader = FileSystemLoader(searchpath=templates_dir)
|
|
68
|
+
environment = TypedVariableEnvironment(loader=environment_loader, **jinja2_env_kwargs)
|
|
69
|
+
environment.globals = db_accessor if db_accessor else {}
|
|
70
|
+
|
|
71
|
+
environment.globals.update(globals_mapping)
|
|
72
|
+
environment.filters.update(filters_dict)
|
|
73
|
+
environment.tests.update(tests_dict)
|
|
74
|
+
|
|
75
|
+
return environment
|
|
File without changes
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Iterable
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
from textual import on
|
|
7
|
+
from textual.app import App, ComposeResult
|
|
8
|
+
from textual.binding import Binding
|
|
9
|
+
from textual.containers import Horizontal, ScrollableContainer
|
|
10
|
+
from textual.validation import Function
|
|
11
|
+
from textual.widgets import (
|
|
12
|
+
Button,
|
|
13
|
+
Checkbox,
|
|
14
|
+
Footer,
|
|
15
|
+
Header,
|
|
16
|
+
Input,
|
|
17
|
+
Label,
|
|
18
|
+
Select,
|
|
19
|
+
Static,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _is_choice(t: Any) -> bool:
|
|
24
|
+
return isinstance(t, click.Choice)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _is_valid_float(v: str) -> bool:
|
|
28
|
+
try:
|
|
29
|
+
float(v)
|
|
30
|
+
return True
|
|
31
|
+
except ValueError:
|
|
32
|
+
return False
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _coerce_to_type(value: Any, _type: Any) -> Any:
|
|
36
|
+
"""Convert a raw widget value to the expected Python type."""
|
|
37
|
+
if _type is bool or _type is bool:
|
|
38
|
+
return bool(value)
|
|
39
|
+
if _type is int:
|
|
40
|
+
return int(value)
|
|
41
|
+
if _type is float:
|
|
42
|
+
return float(value)
|
|
43
|
+
if _is_choice(_type):
|
|
44
|
+
return str(value)
|
|
45
|
+
return str(value)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def new_template_form(css: str = None, bindings: Iterable[Binding] = None):
|
|
49
|
+
class TemplateForm(App[dict[str, Any]]):
|
|
50
|
+
CSS = (
|
|
51
|
+
"""
|
|
52
|
+
Screen {
|
|
53
|
+
background: $surface;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#form-container {
|
|
57
|
+
padding: 1 2;
|
|
58
|
+
height: 1fr;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.field-block {
|
|
62
|
+
height: 3;
|
|
63
|
+
align: left middle;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.field-label {
|
|
67
|
+
width: 24;
|
|
68
|
+
color: $text-muted;
|
|
69
|
+
text-style: bold;
|
|
70
|
+
content-align: left middle;
|
|
71
|
+
height: 3;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.type-hint {
|
|
75
|
+
width: 16;
|
|
76
|
+
color: $text-disabled;
|
|
77
|
+
text-style: italic;
|
|
78
|
+
content-align: left middle;
|
|
79
|
+
height: 3;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.field-block Input {
|
|
83
|
+
width: 1fr;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.field-block Select {
|
|
87
|
+
width: 1fr;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.field-block Checkbox {
|
|
91
|
+
width: auto;
|
|
92
|
+
color: white;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#button-bar {
|
|
96
|
+
align: right middle;
|
|
97
|
+
height: 3;
|
|
98
|
+
padding: 0 2;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#btn-submit {
|
|
102
|
+
margin-left: 1;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.error-msg {
|
|
106
|
+
color: $error;
|
|
107
|
+
text-style: bold;
|
|
108
|
+
height: auto;
|
|
109
|
+
padding: 0 0 1 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
ToggleButton {
|
|
113
|
+
& > .toggle--button {
|
|
114
|
+
color: #bfbfbf;
|
|
115
|
+
background: transparent;
|
|
116
|
+
text-style: dim;
|
|
117
|
+
}
|
|
118
|
+
&.-on > .toggle--button {
|
|
119
|
+
text-style: bold not dim;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
"""
|
|
123
|
+
if not isinstance(css, str)
|
|
124
|
+
else css
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
BINDINGS = (
|
|
128
|
+
[
|
|
129
|
+
Binding("ctrl+enter", "submit", "Submit", priority=True),
|
|
130
|
+
Binding("ctrl+s", "submit", "Submit"),
|
|
131
|
+
Binding("escape", "quit_app", "Quit"),
|
|
132
|
+
]
|
|
133
|
+
if not isinstance(bindings, Iterable) or not all(isinstance(binding, Binding) for binding in bindings)
|
|
134
|
+
else bindings
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
def __init__(
|
|
138
|
+
self,
|
|
139
|
+
variables: dict[str, Any],
|
|
140
|
+
defaults: dict[str, Any] | None = None,
|
|
141
|
+
title: str = "",
|
|
142
|
+
):
|
|
143
|
+
super().__init__()
|
|
144
|
+
self.variables = variables
|
|
145
|
+
self.defaults = defaults or {}
|
|
146
|
+
self.title = title
|
|
147
|
+
self._error_label: Static | None = None
|
|
148
|
+
|
|
149
|
+
def compose(self) -> ComposeResult:
|
|
150
|
+
yield Header(name=self.title, show_clock=False)
|
|
151
|
+
yield Footer()
|
|
152
|
+
|
|
153
|
+
with ScrollableContainer(id="form-container"):
|
|
154
|
+
for name, _type in self.variables.items():
|
|
155
|
+
if _is_choice(_type):
|
|
156
|
+
type_hint = "choice"
|
|
157
|
+
elif _type is bool:
|
|
158
|
+
type_hint = "bool"
|
|
159
|
+
elif _type is int:
|
|
160
|
+
type_hint = "int"
|
|
161
|
+
elif _type is float:
|
|
162
|
+
type_hint = "float"
|
|
163
|
+
else:
|
|
164
|
+
type_hint = "str"
|
|
165
|
+
|
|
166
|
+
with Horizontal(classes="field-block"):
|
|
167
|
+
yield Label(name, classes="field-label")
|
|
168
|
+
yield Label(type_hint, classes="type-hint")
|
|
169
|
+
|
|
170
|
+
default = self.defaults.get(name)
|
|
171
|
+
|
|
172
|
+
if _is_choice(_type):
|
|
173
|
+
options = [(c, c) for c in _type.choices]
|
|
174
|
+
valid_default = (
|
|
175
|
+
str(default) if default is not None and str(default) in _type.choices else None
|
|
176
|
+
)
|
|
177
|
+
select_kwargs = {"allow_blank": True, "prompt": "Select…"}
|
|
178
|
+
if valid_default is not None:
|
|
179
|
+
select_kwargs["value"] = valid_default
|
|
180
|
+
|
|
181
|
+
yield Select(options, id=f"field_{name}", **select_kwargs)
|
|
182
|
+
|
|
183
|
+
elif _type is bool:
|
|
184
|
+
yield Checkbox(
|
|
185
|
+
"",
|
|
186
|
+
id=f"field_{name}",
|
|
187
|
+
value=bool(default) if default is not None else False,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
elif _type is int:
|
|
191
|
+
yield Input(
|
|
192
|
+
value=str(default) if default is not None else "",
|
|
193
|
+
placeholder="integer…",
|
|
194
|
+
id=f"field_{name}",
|
|
195
|
+
validators=[
|
|
196
|
+
Function(
|
|
197
|
+
lambda v: v.lstrip("-").isdigit(),
|
|
198
|
+
"Must be a whole number",
|
|
199
|
+
)
|
|
200
|
+
],
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
elif _type is float:
|
|
204
|
+
yield Input(
|
|
205
|
+
value=str(default) if default is not None else "",
|
|
206
|
+
placeholder="number…",
|
|
207
|
+
id=f"field_{name}",
|
|
208
|
+
validators=[
|
|
209
|
+
Function(
|
|
210
|
+
lambda v: _is_valid_float(v),
|
|
211
|
+
"Must be a valid number",
|
|
212
|
+
)
|
|
213
|
+
],
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
else:
|
|
217
|
+
yield Input(
|
|
218
|
+
value=str(default) if default is not None else "",
|
|
219
|
+
placeholder="text…",
|
|
220
|
+
id=f"field_{name}",
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
yield Static("", id="error-msg", classes="error-msg")
|
|
224
|
+
|
|
225
|
+
with Horizontal(id="button-bar"):
|
|
226
|
+
yield Button("Cancel", variant="default", id="btn-cancel")
|
|
227
|
+
yield Button("Submit", variant="primary", id="btn-submit")
|
|
228
|
+
|
|
229
|
+
def action_submit(self) -> None:
|
|
230
|
+
self._do_submit()
|
|
231
|
+
|
|
232
|
+
def action_quit_app(self) -> None:
|
|
233
|
+
self.exit(None)
|
|
234
|
+
|
|
235
|
+
@on(Button.Pressed, "#btn-submit")
|
|
236
|
+
def handle_submit(self) -> None:
|
|
237
|
+
self._do_submit()
|
|
238
|
+
|
|
239
|
+
@on(Button.Pressed, "#btn-cancel")
|
|
240
|
+
def handle_cancel(self) -> None:
|
|
241
|
+
self.exit(None)
|
|
242
|
+
|
|
243
|
+
def _do_submit(self) -> None:
|
|
244
|
+
results: dict[str, Any] = {}
|
|
245
|
+
errors: list[str] = []
|
|
246
|
+
|
|
247
|
+
for name, t in self.variables.items():
|
|
248
|
+
widget_id = f"field_{name}"
|
|
249
|
+
|
|
250
|
+
if _is_choice(t):
|
|
251
|
+
widget: Select = self.query_one(f"#{widget_id}", Select)
|
|
252
|
+
if not isinstance(widget.value, str):
|
|
253
|
+
errors.append(f"'{name}' requires a selection.")
|
|
254
|
+
continue
|
|
255
|
+
results[name] = str(widget.value)
|
|
256
|
+
|
|
257
|
+
elif t is bool:
|
|
258
|
+
widget: Checkbox = self.query_one(f"#{widget_id}", Checkbox)
|
|
259
|
+
results[name] = widget.value
|
|
260
|
+
|
|
261
|
+
else:
|
|
262
|
+
widget: Input = self.query_one(f"#{widget_id}", Input)
|
|
263
|
+
raw = widget.value.strip()
|
|
264
|
+
|
|
265
|
+
if not raw:
|
|
266
|
+
errors.append(f"'{name}' cannot be empty.")
|
|
267
|
+
continue
|
|
268
|
+
|
|
269
|
+
validation_result = widget.validate(raw)
|
|
270
|
+
if validation_result is not None and validation_result.failures:
|
|
271
|
+
errors.append(f"'{name}' has an invalid value.")
|
|
272
|
+
continue
|
|
273
|
+
|
|
274
|
+
try:
|
|
275
|
+
results[name] = _coerce_to_type(raw, t)
|
|
276
|
+
except (ValueError, TypeError):
|
|
277
|
+
errors.append(f"'{name}' could not be converted to {t.__name__}.")
|
|
278
|
+
|
|
279
|
+
error_widget = self.query_one("#error-msg", Static)
|
|
280
|
+
if errors:
|
|
281
|
+
error_widget.update("\n".join(errors))
|
|
282
|
+
else:
|
|
283
|
+
error_widget.update("")
|
|
284
|
+
self.exit(results)
|
|
285
|
+
|
|
286
|
+
return TemplateForm
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def prompt_for_undefined_variables(
|
|
290
|
+
variables: dict[str, Any],
|
|
291
|
+
defaults: dict[str, Any] | None = None,
|
|
292
|
+
title: str = "",
|
|
293
|
+
css: str = None,
|
|
294
|
+
bindings: Iterable[Binding] = None,
|
|
295
|
+
) -> dict[str, Any] | None:
|
|
296
|
+
"""
|
|
297
|
+
Launch the Textual form and return the filled values dict.
|
|
298
|
+
|
|
299
|
+
Args:
|
|
300
|
+
variables: Mapping of variable_name -> type. Duplicate keys are collapsed automatically
|
|
301
|
+
(last definition wins, preserving insertion order of first occurrence).
|
|
302
|
+
defaults: Optional mapping of variable_name -> default value.
|
|
303
|
+
Pre-fills the corresponding widget; user can override.
|
|
304
|
+
title: Shown at the top of the TUI window to provide users with additional context
|
|
305
|
+
css: A str containing CSS you wish to override the defaults with.
|
|
306
|
+
None for default CSS
|
|
307
|
+
bindings: An iterable of textual.Binding objects you wish to override the defaults with.
|
|
308
|
+
None for default bindings.
|
|
309
|
+
|
|
310
|
+
Returns:
|
|
311
|
+
A dict of {variable_name: coerced_value}, or None if the user cancelled.
|
|
312
|
+
"""
|
|
313
|
+
|
|
314
|
+
seen_variables: dict[str, Any] = {}
|
|
315
|
+
for name, t in variables.items():
|
|
316
|
+
if name not in seen_variables:
|
|
317
|
+
seen_variables[name] = t
|
|
318
|
+
|
|
319
|
+
template_form = new_template_form(css, bindings)
|
|
320
|
+
app = template_form(seen_variables, defaults=defaults, title=title)
|
|
321
|
+
return app.run()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pdfrender
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Using DB models and Jinja2 to generate templated PDF documents
|
|
5
|
+
Author-email: Cam Ratchford <camratchford@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/camratchford/pdfrender
|
|
7
|
+
Project-URL: Source, https://github.com/camratchford/pdfrender
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Natural Language :: English
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: byoconfig
|
|
22
|
+
Requires-Dist: typer
|
|
23
|
+
Requires-Dist: jinja2
|
|
24
|
+
Requires-Dist: click
|
|
25
|
+
Requires-Dist: textual
|
|
26
|
+
Requires-Dist: pyyaml
|
|
27
|
+
Requires-Dist: sqlmodel
|
|
28
|
+
Requires-Dist: pydantic
|
|
29
|
+
Requires-Dist: markdown
|
|
30
|
+
Requires-Dist: pymdown-extensions
|
|
31
|
+
Requires-Dist: pygments
|
|
32
|
+
Requires-Dist: weasyprint
|
|
33
|
+
Provides-Extra: development
|
|
34
|
+
Requires-Dist: pytest; extra == "development"
|
|
35
|
+
Requires-Dist: pytest-cov; extra == "development"
|
|
36
|
+
Requires-Dist: isort; extra == "development"
|
|
37
|
+
Requires-Dist: ruff; extra == "development"
|
|
38
|
+
Requires-Dist: build; extra == "development"
|
|
39
|
+
Provides-Extra: docs
|
|
40
|
+
Requires-Dist: mkdocs~=1.6; extra == "docs"
|
|
41
|
+
Requires-Dist: mkdocs-autorefs~=1.4; extra == "docs"
|
|
42
|
+
Requires-Dist: mkdocs-get-deps~=0.2.2; extra == "docs"
|
|
43
|
+
Requires-Dist: mkdocs-material~=9.7; extra == "docs"
|
|
44
|
+
Requires-Dist: mkdocs-material-extensions~=1.3; extra == "docs"
|
|
45
|
+
Requires-Dist: mkdocstrings~=1.0; extra == "docs"
|
|
46
|
+
Requires-Dist: mkdocstrings-python~=2.0; extra == "docs"
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# pdfrender
|
|
50
|
+
|
|
51
|
+
A database relationship and template-driven Markdown to PDF toolkit.
|
|
52
|
+
|
|
53
|
+
Bring your own SQLAlchemy/SQLModel models, YAML data, and Jinja2 templates.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
- Type-aware model importing DB data from YAML. Supports nested instance data for dynamically assigning relationships.
|
|
57
|
+
- Facilities to perform DB queries inside the Jinja2 template context
|
|
58
|
+
- Custom Jinja2 Environment object:
|
|
59
|
+
- Pre-processes templates to support typed variables, allowing template authors to specify variable types
|
|
60
|
+
using PEP 484 annotation syntax.
|
|
61
|
+
- Stores undefined variables, allowing for run-time user variable prompts
|
|
62
|
+
- Dynamically composed Textual CLI form, to capture run-time user variable inputs
|
|
63
|
+
|
|
64
|
+
## Documentation
|
|
65
|
+
|
|
66
|
+
Published at https://camratchford.github.io/pdfrender/ (deployed on release,
|
|
67
|
+
see below). To view locally instead:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install -e ".[docs]"
|
|
71
|
+
mkdocs serve -f extras/docs/mkdocs.yml
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Then open http://127.0.0.1:8000.
|
|
75
|
+
|
|
76
|
+
## Releasing
|
|
77
|
+
|
|
78
|
+
The package version comes from git tags via `setuptools-scm` - there's
|
|
79
|
+
nothing to bump by hand in `pyproject.toml`. To cut a release:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
git tag v0.1.0
|
|
83
|
+
git push --tags
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Pushing a `v*` tag triggers `.github/workflows/release.yml`, which builds
|
|
87
|
+
the package and publishes it to PyPI (via
|
|
88
|
+
[trusted publishing](https://docs.pypi.org/trusted-publishers/), no stored
|
|
89
|
+
token needed), and deploys `extras/docs` to GitHub Pages.
|
|
90
|
+
|
|
91
|
+
One-time setup this repo needs before that works:
|
|
92
|
+
|
|
93
|
+
- **PyPI**: add a trusted publisher on the
|
|
94
|
+
[pdfrender PyPI project](https://pypi.org/manage/project/pdfrender/publishing/)
|
|
95
|
+
pointing at this repo and the `release.yml` workflow.
|
|
96
|
+
- **GitHub Pages**: under Settings -> Pages, set Source to "GitHub Actions".
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
pdf_render/__init__.py,sha256=qXaVJNBTdL8brrbRbKsynI0pAsaywZGsWD1kfdNZBvg,689
|
|
2
|
+
pdf_render/import_functions.py,sha256=9dRIRWSMRRfB0pYfGcgWVyQ-ZFkTRlYhndFBgBsemQM,1452
|
|
3
|
+
pdf_render/data/__init__.py,sha256=3-p3zPKYQMYSCj2DggunufeiGdjGrmVs6j2kKhV8_dQ,165
|
|
4
|
+
pdf_render/data/accessor.py,sha256=Aswq679wqeVoRT9FdUaj9hXWeQoZnRzm1BCHFyBHdp8,6108
|
|
5
|
+
pdf_render/data/importer.py,sha256=Txn-r1ShUWZa8ovpU9WMKE7kQtObCSdrjJFwjUsiIz4,8451
|
|
6
|
+
pdf_render/data/model_field_typing.py,sha256=lRl49Q5A45NjN8gd45qAqH80skGBrxfunNcr-N6FpG4,5787
|
|
7
|
+
pdf_render/md/__init__.py,sha256=sBfyzkX6jHIk7OmN97wnlcRjOt_AhkfYK9559qYhBwU,88
|
|
8
|
+
pdf_render/md/rendering.py,sha256=xpiidPQxYYXW9nFyHDNSDlOPbqIxmb4-E4BACb23VtI,1169
|
|
9
|
+
pdf_render/md/extensions/__init__.py,sha256=L561kJSQkx19-ycC51o8OA30cVIppxmyTgnubJeidUA,370
|
|
10
|
+
pdf_render/md/extensions/columns.py,sha256=gZr95YG57Yj-ZPxRjoMOsFX02V6nz0TR_D2nZ82I-XU,1460
|
|
11
|
+
pdf_render/md/extensions/flex_wrap.py,sha256=ooRDDS0adXOwLeIR6g9LyEglSt8FK7TI0l1Iir1wNGc,1664
|
|
12
|
+
pdf_render/md/extensions/muted_text.py,sha256=G-8wmrf_qmfzzEOgHtYtNsnWjtQjl31MXpi6a84IVmw,1226
|
|
13
|
+
pdf_render/md/extensions/nerdfont_glyph.py,sha256=5fCZohlfE5QzTZ_Yavj7Wr2_09OvJCe0OriYpw8UPXU,1005
|
|
14
|
+
pdf_render/md/extensions/page_break.py,sha256=XOCKw4Ua5N4LYWOb9m5hQocywRpyawXgXxIo7di-OdU,1060
|
|
15
|
+
pdf_render/pdf/__init__.py,sha256=2MOgdQSpp4Oq-FE1hXvb177P4lDPURiv_PpAPrTQ7vA,155
|
|
16
|
+
pdf_render/pdf/document_template.py,sha256=oO0E6vsG9PSj9lduOfZJggzsNEv524c1mDu1GkVsBGw,1238
|
|
17
|
+
pdf_render/pdf/metadata.py,sha256=3w9ZHbiufI9YHs2FigUhD7hIR8CjO4uBkblRR1XPg14,1392
|
|
18
|
+
pdf_render/pdf/options.py,sha256=FSHtHFwn1lJ8_XjYJbrjugRugsBikEUtlMjkSaJi3Jg,2863
|
|
19
|
+
pdf_render/pdf/rendering.py,sha256=bbVEB6wKS78iLBpNwUQT0JqHyaytYlKyUVHuQtQ4lpo,1568
|
|
20
|
+
pdf_render/templates/__init__.py,sha256=wYLxecUtH-SjlgJ-ITpfZRd_e_DcbtWI9Iqm51EfaMU,166
|
|
21
|
+
pdf_render/templates/environment.py,sha256=53k8PcHr1ISOCmdnbA7Jp7NUqabvm5C7A9dRfRmQM7Q,6301
|
|
22
|
+
pdf_render/templates/rendering.py,sha256=C_kpovQhn2lWHJXvU2JCU5TesWnZFLSHu05Egq-qmb0,3439
|
|
23
|
+
pdf_render/templates/filters/__init__.py,sha256=kxd5SpaEuAaTwSXErz17t9EesECXVNY2tpIj-aW2f3M,349
|
|
24
|
+
pdf_render/templates/filters/format_filters.py,sha256=zE-3REsj0wHYe_eqOmFbuIyYXv1QpAb-tFrd2suyh9A,929
|
|
25
|
+
pdf_render/templates/filters/getter_filters.py,sha256=S8Jf4bvNHzryW8xgReKlEFD6Ql5tVgRmKPXLHYM6dds,1653
|
|
26
|
+
pdf_render/templates/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
|
+
pdf_render/user_input/__init__.py,sha256=7vxxbVasiYXWD8H8nzRmB3Lv7KiFqTnK5e4TqhWs2rA,114
|
|
28
|
+
pdf_render/user_input/undefined_variable_form.py,sha256=wqHdQbJWJN0EZ3JZbjHyrN9WheUnaS7rolNdT_zEJ3I,10541
|
|
29
|
+
pdfrender-0.1.0.dist-info/licenses/LICENSE,sha256=Rmn7wkN_w7iiZgvv4Q8Hy2jmiUq9E9iWYRp-iX75BBE,1073
|
|
30
|
+
pdfrender-0.1.0.dist-info/METADATA,sha256=fM5BwPzlntXowQ3SRUsgpIp3mof2hqGgy89SWlBD4rA,3539
|
|
31
|
+
pdfrender-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
32
|
+
pdfrender-0.1.0.dist-info/entry_points.txt,sha256=nd_8klbU5TenNX6vtAWdB_wfLuuuyyCC6hP3vs-gGf4,54
|
|
33
|
+
pdfrender-0.1.0.dist-info/top_level.txt,sha256=isBDCoFGvkIAy7ZWrHYEFRTESFikfE0s24vK0vsVvEE,11
|
|
34
|
+
pdfrender-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cameron Ratchford
|
|
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
|
+
pdf_render
|