pyreportkit 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.
- pyreportkit-0.1.0.dist-info/METADATA +187 -0
- pyreportkit-0.1.0.dist-info/RECORD +222 -0
- pyreportkit-0.1.0.dist-info/WHEEL +5 -0
- pyreportkit-0.1.0.dist-info/licenses/LICENSE +21 -0
- pyreportkit-0.1.0.dist-info/top_level.txt +1 -0
- reportkit/__init__.py +0 -0
- reportkit/components/__init__.py +45 -0
- reportkit/components/document/__init__.py +6 -0
- reportkit/components/document/footer.py +12 -0
- reportkit/components/document/header.py +12 -0
- reportkit/components/document/page.py +18 -0
- reportkit/components/document/report.py +12 -0
- reportkit/components/information/__init__.py +4 -0
- reportkit/components/information/info_grid.py +23 -0
- reportkit/components/information/key_value.py +28 -0
- reportkit/components/layout/__init__.py +9 -0
- reportkit/components/layout/box.py +10 -0
- reportkit/components/layout/column.py +15 -0
- reportkit/components/layout/divider.py +10 -0
- reportkit/components/layout/grid.py +12 -0
- reportkit/components/layout/row.py +15 -0
- reportkit/components/layout/section.py +10 -0
- reportkit/components/layout/spacer.py +12 -0
- reportkit/components/media/__init__.py +4 -0
- reportkit/components/media/chart.py +14 -0
- reportkit/components/media/image.py +25 -0
- reportkit/components/pagination/__init__.py +5 -0
- reportkit/components/pagination/page_break.py +10 -0
- reportkit/components/pagination/page_count.py +10 -0
- reportkit/components/pagination/page_number.py +21 -0
- reportkit/components/table/__init__.py +7 -0
- reportkit/components/table/cell.py +27 -0
- reportkit/components/table/column.py +29 -0
- reportkit/components/table/row.py +25 -0
- reportkit/components/table/style.py +18 -0
- reportkit/components/table/table.py +27 -0
- reportkit/components/typography/__init__.py +6 -0
- reportkit/components/typography/heading.py +13 -0
- reportkit/components/typography/rich_text.py +23 -0
- reportkit/components/typography/text.py +12 -0
- reportkit/components/typography/text_span.py +24 -0
- reportkit/core/__init__.py +4 -0
- reportkit/core/component.py +12 -0
- reportkit/core/container.py +66 -0
- reportkit/core/exceptions.py +0 -0
- reportkit/core/factory.py +53 -0
- reportkit/core/registry.py +50 -0
- reportkit/core/serializer.py +90 -0
- reportkit/exporters/__init__.py +0 -0
- reportkit/exporters/base.py +17 -0
- reportkit/exporters/excel/__init__.py +8 -0
- reportkit/exporters/excel/exceptions.py +4 -0
- reportkit/exporters/excel/exporter.py +68 -0
- reportkit/exporters/excel/renderers/__init__.py +34 -0
- reportkit/exporters/excel/renderers/base.py +27 -0
- reportkit/exporters/excel/renderers/information.py +55 -0
- reportkit/exporters/excel/renderers/layout/__init__.py +7 -0
- reportkit/exporters/excel/renderers/layout/columns.py +48 -0
- reportkit/exporters/excel/renderers/layout/data.py +46 -0
- reportkit/exporters/excel/renderers/layout/page.py +24 -0
- reportkit/exporters/excel/renderers/layout/spacing.py +30 -0
- reportkit/exporters/excel/renderers/layout/stack.py +13 -0
- reportkit/exporters/excel/renderers/media.py +46 -0
- reportkit/exporters/excel/renderers/registry.py +22 -0
- reportkit/exporters/excel/renderers/table/__init__.py +4 -0
- reportkit/exporters/excel/renderers/table/cells.py +17 -0
- reportkit/exporters/excel/renderers/table/data.py +38 -0
- reportkit/exporters/excel/renderers/table/renderer.py +64 -0
- reportkit/exporters/excel/renderers/table/widths.py +29 -0
- reportkit/exporters/excel/renderers/text.py +40 -0
- reportkit/exporters/excel/styles.py +130 -0
- reportkit/exporters/excel/values/__init__.py +5 -0
- reportkit/exporters/excel/values/cells.py +60 -0
- reportkit/exporters/excel/values/components.py +16 -0
- reportkit/exporters/excel/values/formats.py +31 -0
- reportkit/exporters/excel/values/numbers.py +19 -0
- reportkit/exporters/excel/workbook/__init__.py +5 -0
- reportkit/exporters/excel/workbook/data.py +48 -0
- reportkit/exporters/excel/workbook/formatted.py +63 -0
- reportkit/exporters/excel/workbook/styles.py +27 -0
- reportkit/exporters/excel/workbook/workbook.py +65 -0
- reportkit/exporters/excel/worksheet/__init__.py +5 -0
- reportkit/exporters/excel/worksheet/borders.py +30 -0
- reportkit/exporters/excel/worksheet/cells.py +38 -0
- reportkit/exporters/excel/worksheet/constants.py +12 -0
- reportkit/exporters/excel/worksheet/data.py +51 -0
- reportkit/exporters/excel/worksheet/formatted.py +158 -0
- reportkit/exporters/excel/worksheet/page.py +23 -0
- reportkit/exporters/html/__init__.py +6 -0
- reportkit/exporters/html/assets.py +87 -0
- reportkit/exporters/html/direction.py +15 -0
- reportkit/exporters/html/engine.py +37 -0
- reportkit/exporters/html/exporter.py +38 -0
- reportkit/exporters/html/page/__init__.py +3 -0
- reportkit/exporters/html/page/components.py +47 -0
- reportkit/exporters/html/page/margins.py +24 -0
- reportkit/exporters/html/page/numbering.py +31 -0
- reportkit/exporters/html/page/resolver.py +37 -0
- reportkit/exporters/html/page/running.py +30 -0
- reportkit/exporters/html/page/styles.py +22 -0
- reportkit/exporters/html/page/validator.py +76 -0
- reportkit/exporters/html/registry.py +45 -0
- reportkit/exporters/html/renderers/__init__.py +37 -0
- reportkit/exporters/html/renderers/base.py +20 -0
- reportkit/exporters/html/renderers/document/__init__.py +6 -0
- reportkit/exporters/html/renderers/document/footer.py +18 -0
- reportkit/exporters/html/renderers/document/header.py +18 -0
- reportkit/exporters/html/renderers/document/page.py +17 -0
- reportkit/exporters/html/renderers/document/report.py +16 -0
- reportkit/exporters/html/renderers/information/__init__.py +4 -0
- reportkit/exporters/html/renderers/information/info_grid.py +26 -0
- reportkit/exporters/html/renderers/information/key_value.py +18 -0
- reportkit/exporters/html/renderers/layout/__init__.py +9 -0
- reportkit/exporters/html/renderers/layout/box.py +17 -0
- reportkit/exporters/html/renderers/layout/column.py +41 -0
- reportkit/exporters/html/renderers/layout/divider.py +16 -0
- reportkit/exporters/html/renderers/layout/grid.py +48 -0
- reportkit/exporters/html/renderers/layout/row.py +35 -0
- reportkit/exporters/html/renderers/layout/section.py +17 -0
- reportkit/exporters/html/renderers/layout/spacer.py +18 -0
- reportkit/exporters/html/renderers/media/__init__.py +3 -0
- reportkit/exporters/html/renderers/media/image.py +18 -0
- reportkit/exporters/html/renderers/pagination/__init__.py +4 -0
- reportkit/exporters/html/renderers/pagination/page_break.py +15 -0
- reportkit/exporters/html/renderers/pagination/page_number.py +15 -0
- reportkit/exporters/html/renderers/table/__init__.py +4 -0
- reportkit/exporters/html/renderers/table/cell.py +77 -0
- reportkit/exporters/html/renderers/table/table.py +69 -0
- reportkit/exporters/html/renderers/typography/__init__.py +5 -0
- reportkit/exporters/html/renderers/typography/heading.py +18 -0
- reportkit/exporters/html/renderers/typography/rich_text.py +28 -0
- reportkit/exporters/html/renderers/typography/text.py +16 -0
- reportkit/exporters/html/static/base.css +45 -0
- reportkit/exporters/html/static/information.css +83 -0
- reportkit/exporters/html/static/layout.css +81 -0
- reportkit/exporters/html/static/media.css +10 -0
- reportkit/exporters/html/static/pdf.css +96 -0
- reportkit/exporters/html/static/print.css +91 -0
- reportkit/exporters/html/static/table.css +222 -0
- reportkit/exporters/html/static/tokens.css +68 -0
- reportkit/exporters/html/static/typography.css +54 -0
- reportkit/exporters/html/styles.py +167 -0
- reportkit/exporters/html/templates/components/document/footer.html +3 -0
- reportkit/exporters/html/templates/components/document/header.html +3 -0
- reportkit/exporters/html/templates/components/document/page.html +8 -0
- reportkit/exporters/html/templates/components/document/report.html +3 -0
- reportkit/exporters/html/templates/components/information/info_grid.html +6 -0
- reportkit/exporters/html/templates/components/information/key_value.html +9 -0
- reportkit/exporters/html/templates/components/layout/box.html +3 -0
- reportkit/exporters/html/templates/components/layout/column.html +3 -0
- reportkit/exporters/html/templates/components/layout/divider.html +1 -0
- reportkit/exporters/html/templates/components/layout/grid.html +3 -0
- reportkit/exporters/html/templates/components/layout/row.html +3 -0
- reportkit/exporters/html/templates/components/layout/section.html +3 -0
- reportkit/exporters/html/templates/components/layout/spacer.html +1 -0
- reportkit/exporters/html/templates/components/media/image.html +8 -0
- reportkit/exporters/html/templates/components/pagination/page_break.html +1 -0
- reportkit/exporters/html/templates/components/pagination/page_number.html +4 -0
- reportkit/exporters/html/templates/components/table/cell.html +7 -0
- reportkit/exporters/html/templates/components/table/table.html +34 -0
- reportkit/exporters/html/templates/components/typography/heading.html +1 -0
- reportkit/exporters/html/templates/components/typography/rich_text.html +5 -0
- reportkit/exporters/html/templates/components/typography/text.html +1 -0
- reportkit/exporters/html/templates/document.html +17 -0
- reportkit/exporters/html/templates.py +30 -0
- reportkit/exporters/json.py +0 -0
- reportkit/exporters/pdf/__init__.py +8 -0
- reportkit/exporters/pdf/conversion.py +104 -0
- reportkit/exporters/pdf/dependencies.py +12 -0
- reportkit/exporters/pdf/exceptions.py +4 -0
- reportkit/exporters/pdf/exporter.py +16 -0
- reportkit/exporters/pdf/resources/__init__.py +4 -0
- reportkit/exporters/pdf/resources/fetcher.py +37 -0
- reportkit/exporters/pdf/resources/policy.py +60 -0
- reportkit/exporters/registry.py +50 -0
- reportkit/exporters/word/__init__.py +8 -0
- reportkit/exporters/word/document/__init__.py +4 -0
- reportkit/exporters/word/document/document.py +74 -0
- reportkit/exporters/word/document/engine.py +71 -0
- reportkit/exporters/word/exceptions.py +4 -0
- reportkit/exporters/word/exporter.py +32 -0
- reportkit/exporters/word/renderers/__init__.py +24 -0
- reportkit/exporters/word/renderers/base.py +56 -0
- reportkit/exporters/word/renderers/information.py +30 -0
- reportkit/exporters/word/renderers/layout/__init__.py +6 -0
- reportkit/exporters/word/renderers/layout/columns.py +82 -0
- reportkit/exporters/word/renderers/layout/page.py +38 -0
- reportkit/exporters/word/renderers/layout/spacing.py +33 -0
- reportkit/exporters/word/renderers/layout/stack.py +50 -0
- reportkit/exporters/word/renderers/media.py +49 -0
- reportkit/exporters/word/renderers/registry.py +22 -0
- reportkit/exporters/word/renderers/table/__init__.py +3 -0
- reportkit/exporters/word/renderers/table/cells.py +39 -0
- reportkit/exporters/word/renderers/table/renderer.py +95 -0
- reportkit/exporters/word/renderers/table/widths.py +12 -0
- reportkit/exporters/word/renderers/text.py +40 -0
- reportkit/exporters/word/styles/__init__.py +3 -0
- reportkit/exporters/word/styles/text.py +90 -0
- reportkit/exporters/word/styles/xml.py +147 -0
- reportkit/exporters/word/values.py +36 -0
- reportkit/formatting/__init__.py +0 -0
- reportkit/formatting/cell.py +12 -0
- reportkit/formatting/cells.py +41 -0
- reportkit/formatting/values.py +106 -0
- reportkit/rendering/__init__.py +0 -0
- reportkit/rendering/context.py +31 -0
- reportkit/rendering/table.py +56 -0
- reportkit/rendering/tracks.py +51 -0
- reportkit/rendering/visitor.py +55 -0
- reportkit/report.py +0 -0
- reportkit/styles/__init__.py +0 -0
- reportkit/styles/borders.py +6 -0
- reportkit/styles/style.py +117 -0
- reportkit/styles/table.py +37 -0
- reportkit/styles/theme.py +45 -0
- reportkit/styles/tokens.py +29 -0
- reportkit/validators/__init__.py +3 -0
- reportkit/validators/table/__init__.py +3 -0
- reportkit/validators/table/cell.py +38 -0
- reportkit/validators/table/column.py +62 -0
- reportkit/validators/table/row.py +37 -0
- reportkit/validators/table/table.py +63 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class PageStyleResolver:
|
|
2
|
+
"""
|
|
3
|
+
Build the @page rule; settings are validated by HtmlPageValidator.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
@staticmethod
|
|
7
|
+
def resolve(page):
|
|
8
|
+
"""
|
|
9
|
+
Build the base @page rule.
|
|
10
|
+
"""
|
|
11
|
+
return f"@page {{\n size: {page.size} {page.orientation};\n margin: {page.margin_top} {page.margin_right} {page.margin_bottom} {page.margin_left};\n}}"
|
|
12
|
+
|
|
13
|
+
@classmethod
|
|
14
|
+
def render(cls, page, margin_rules=None):
|
|
15
|
+
"""
|
|
16
|
+
Build the @page rule with its margin boxes.
|
|
17
|
+
"""
|
|
18
|
+
base_css = cls.resolve(page)
|
|
19
|
+
if not margin_rules:
|
|
20
|
+
return base_css
|
|
21
|
+
index = base_css.rfind("}")
|
|
22
|
+
return base_css[:index] + "\n".join(margin_rules) + "\n" + base_css[index:]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from .margins import PageMarginRegistry
|
|
4
|
+
from .running import RunningElementResolver
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class HtmlPageValidator:
|
|
8
|
+
"""
|
|
9
|
+
Validate every page setting that ends up in print CSS.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
PAGE_SIZES = {"A4", "A3", "A5", "Letter", "Legal"}
|
|
13
|
+
ORIENTATIONS = {"portrait", "landscape"}
|
|
14
|
+
LENGTH = re.compile(r"^\d+(?:\.\d+)?(?:mm|cm|in|pt)$")
|
|
15
|
+
|
|
16
|
+
@classmethod
|
|
17
|
+
def validate(cls, found):
|
|
18
|
+
"""
|
|
19
|
+
Validate the collected page components.
|
|
20
|
+
"""
|
|
21
|
+
cls.validate_pages(found.pages)
|
|
22
|
+
cls.validate_numbering(found)
|
|
23
|
+
cls.validate_running(found)
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def validate_pages(cls, pages):
|
|
27
|
+
"""
|
|
28
|
+
Pages must share one valid configuration.
|
|
29
|
+
"""
|
|
30
|
+
if len({cls.signature(page) for page in pages}) > 1:
|
|
31
|
+
raise ValueError("HTML printing currently requires identical page settings.")
|
|
32
|
+
page = pages[0]
|
|
33
|
+
if page.size not in cls.PAGE_SIZES:
|
|
34
|
+
raise ValueError("Unsupported page size.")
|
|
35
|
+
if page.orientation not in cls.ORIENTATIONS:
|
|
36
|
+
raise ValueError("Unsupported page orientation.")
|
|
37
|
+
if not all(isinstance(value, str) and cls.LENGTH.fullmatch(value) for value in cls.margins(page)):
|
|
38
|
+
raise ValueError("Invalid page margin.")
|
|
39
|
+
if page.page_number_position not in PageMarginRegistry.POSITIONS:
|
|
40
|
+
raise ValueError("Unsupported page number position.")
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def validate_numbering(found):
|
|
44
|
+
"""
|
|
45
|
+
Only one page numbering definition is supported.
|
|
46
|
+
"""
|
|
47
|
+
if len(found.numbers) > 1:
|
|
48
|
+
raise ValueError("Only one page numbering definition is supported.")
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def validate_running(found):
|
|
52
|
+
"""
|
|
53
|
+
Repeating elements must be unique and must not share the page number margin.
|
|
54
|
+
"""
|
|
55
|
+
types = [type(component) for component in found.running]
|
|
56
|
+
if len(types) != len(set(types)):
|
|
57
|
+
raise ValueError("Only one repeating Header and Footer are supported.")
|
|
58
|
+
positions = [RunningElementResolver.position(component) for component in found.running]
|
|
59
|
+
if found.numbers:
|
|
60
|
+
positions.append(found.pages[0].page_number_position)
|
|
61
|
+
if len(positions) != len(set(positions)):
|
|
62
|
+
raise ValueError("Page number position collides with a repeating Header or Footer.")
|
|
63
|
+
|
|
64
|
+
@staticmethod
|
|
65
|
+
def margins(page):
|
|
66
|
+
"""
|
|
67
|
+
Return the page margins in CSS order.
|
|
68
|
+
"""
|
|
69
|
+
return (page.margin_top, page.margin_right, page.margin_bottom, page.margin_left)
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def signature(cls, page):
|
|
73
|
+
"""
|
|
74
|
+
Return the settings that must match across pages.
|
|
75
|
+
"""
|
|
76
|
+
return (page.size, page.orientation, page.page_number_position, *cls.margins(page))
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from ...core.component import Component
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class HtmlRendererRegistry:
|
|
5
|
+
"""
|
|
6
|
+
Register and resolve HTML component renderers.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
_renderers: dict[type[Component], type] = {}
|
|
10
|
+
|
|
11
|
+
@classmethod
|
|
12
|
+
def register(cls, component: type[Component], renderer: type):
|
|
13
|
+
"""
|
|
14
|
+
Register an HTML renderer for a component.
|
|
15
|
+
"""
|
|
16
|
+
if not isinstance(component, type) or not issubclass(component, Component):
|
|
17
|
+
raise TypeError("Component must inherit from Component.")
|
|
18
|
+
|
|
19
|
+
if not isinstance(renderer, type):
|
|
20
|
+
raise TypeError("Renderer must be a class.")
|
|
21
|
+
|
|
22
|
+
if component in cls._renderers:
|
|
23
|
+
raise ValueError(f"Renderer for '{component.__name__}' is already registered.")
|
|
24
|
+
|
|
25
|
+
cls._renderers[component] = renderer
|
|
26
|
+
return renderer
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def get(cls, component: type[Component]) -> type:
|
|
30
|
+
"""
|
|
31
|
+
Resolve the registered HTML renderer.
|
|
32
|
+
"""
|
|
33
|
+
try:
|
|
34
|
+
return cls._renderers[component]
|
|
35
|
+
except KeyError:
|
|
36
|
+
raise ValueError(
|
|
37
|
+
f"No HTML renderer registered for '{component.__name__}'."
|
|
38
|
+
) from None
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def all(cls) -> dict[type[Component], type]:
|
|
42
|
+
"""
|
|
43
|
+
Return all registered HTML renderers.
|
|
44
|
+
"""
|
|
45
|
+
return cls._renderers.copy()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from ....components.document import Footer, Header, Page, Report
|
|
2
|
+
from ....components.information import InfoGrid, KeyValue
|
|
3
|
+
from ....components.layout import Box, Column, Divider, Grid, Row, Section, Spacer
|
|
4
|
+
from ....components.media import Image
|
|
5
|
+
from ....components.table import Table
|
|
6
|
+
from ....components.typography import Heading, RichText, Text
|
|
7
|
+
from ....components.pagination import PageBreak, PageNumber
|
|
8
|
+
from ..registry import HtmlRendererRegistry
|
|
9
|
+
from .document import FooterRenderer, HeaderRenderer, PageRenderer, ReportRenderer
|
|
10
|
+
from .information import InfoGridRenderer, KeyValueRenderer
|
|
11
|
+
from .layout import BoxRenderer, ColumnRenderer, DividerRenderer, GridRenderer, RowRenderer, SectionRenderer, SpacerRenderer
|
|
12
|
+
from .media import ImageRenderer
|
|
13
|
+
from .pagination import PageBreakRenderer, PageNumberRenderer
|
|
14
|
+
from .table import TableRenderer
|
|
15
|
+
from .typography import HeadingRenderer, RichTextRenderer, TextRenderer
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
HtmlRendererRegistry.register(Report, ReportRenderer)
|
|
19
|
+
HtmlRendererRegistry.register(Page, PageRenderer)
|
|
20
|
+
HtmlRendererRegistry.register(Header, HeaderRenderer)
|
|
21
|
+
HtmlRendererRegistry.register(Footer, FooterRenderer)
|
|
22
|
+
HtmlRendererRegistry.register(Section, SectionRenderer)
|
|
23
|
+
HtmlRendererRegistry.register(Box, BoxRenderer)
|
|
24
|
+
HtmlRendererRegistry.register(Row, RowRenderer)
|
|
25
|
+
HtmlRendererRegistry.register(Column, ColumnRenderer)
|
|
26
|
+
HtmlRendererRegistry.register(Grid, GridRenderer)
|
|
27
|
+
HtmlRendererRegistry.register(Spacer, SpacerRenderer)
|
|
28
|
+
HtmlRendererRegistry.register(Divider, DividerRenderer)
|
|
29
|
+
HtmlRendererRegistry.register(Table, TableRenderer)
|
|
30
|
+
HtmlRendererRegistry.register(Image, ImageRenderer)
|
|
31
|
+
HtmlRendererRegistry.register(KeyValue, KeyValueRenderer)
|
|
32
|
+
HtmlRendererRegistry.register(InfoGrid, InfoGridRenderer)
|
|
33
|
+
HtmlRendererRegistry.register(Text, TextRenderer)
|
|
34
|
+
HtmlRendererRegistry.register(Heading, HeadingRenderer)
|
|
35
|
+
HtmlRendererRegistry.register(RichText, RichTextRenderer)
|
|
36
|
+
HtmlRendererRegistry.register(PageBreak, PageBreakRenderer)
|
|
37
|
+
HtmlRendererRegistry.register(PageNumber, PageNumberRenderer)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class BaseHtmlRenderer(ABC):
|
|
5
|
+
"""
|
|
6
|
+
Define the base contract for HTML component renderers.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
@abstractmethod
|
|
10
|
+
def render(self, component, context, engine) -> str:
|
|
11
|
+
"""
|
|
12
|
+
Render a component into HTML.
|
|
13
|
+
"""
|
|
14
|
+
raise NotImplementedError
|
|
15
|
+
|
|
16
|
+
def render_children(self, component, context, engine) -> str:
|
|
17
|
+
"""
|
|
18
|
+
Render nested components using the HTML rendering engine.
|
|
19
|
+
"""
|
|
20
|
+
return "".join(engine.render(child, context) for child in component.children)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class FooterRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render report footer components.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/document/footer.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render the footer and its children.
|
|
14
|
+
"""
|
|
15
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
16
|
+
children = self.render_children(component, context, engine)
|
|
17
|
+
css_class = "rk-footer rk-running-footer" if component.repeat else "rk-footer"
|
|
18
|
+
return engine.templates.render(self.template_name, style=style, children=children, css_class=css_class)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class HeaderRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render report header components.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/document/header.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render the header and its children.
|
|
14
|
+
"""
|
|
15
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
16
|
+
children = self.render_children(component, context, engine)
|
|
17
|
+
css_class = "rk-header rk-running-header" if component.repeat else "rk-header"
|
|
18
|
+
return engine.templates.render(self.template_name, style=style, children=children, css_class=css_class)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PageRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render a report page.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/document/page.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render page content and print settings.
|
|
14
|
+
"""
|
|
15
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
16
|
+
children = self.render_children(component, context, engine)
|
|
17
|
+
return engine.templates.render(self.template_name, component=component, children=children, style=style)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ReportRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render the root report container.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/document/report.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render the report and all nested components.
|
|
14
|
+
"""
|
|
15
|
+
children = self.render_children(component, context, engine)
|
|
16
|
+
return engine.templates.render(self.template_name, children=children)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class InfoGridRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render information fields in a responsive grid.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/information/info_grid.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render the information grid.
|
|
14
|
+
"""
|
|
15
|
+
style = context.resolve_style(component)
|
|
16
|
+
css_class = self.get_class(component, style, context)
|
|
17
|
+
children = self.render_children(component, context, engine)
|
|
18
|
+
return engine.templates.render(self.template_name, component=component, style=engine.styles.resolve(style), flow=css_class, children=children)
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def get_class(component, style, context):
|
|
22
|
+
"""
|
|
23
|
+
Get the information grid CSS classes.
|
|
24
|
+
"""
|
|
25
|
+
direction = style.direction or context.direction
|
|
26
|
+
return f"rk-grid--{direction} rk-grid--cols-{component.columns}"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class KeyValueRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render a labeled information field.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/information/key_value.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render the label and its supplied value.
|
|
14
|
+
"""
|
|
15
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
16
|
+
label_style = engine.styles.resolve(component.label_style)
|
|
17
|
+
value_style = engine.styles.resolve(component.value_style)
|
|
18
|
+
return engine.templates.render(self.template_name, component=component, style=style, label_style=label_style, value_style=value_style)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from .box import BoxRenderer
|
|
2
|
+
from .column import ColumnRenderer
|
|
3
|
+
from .divider import DividerRenderer
|
|
4
|
+
from .grid import GridRenderer
|
|
5
|
+
from .row import RowRenderer
|
|
6
|
+
from .section import SectionRenderer
|
|
7
|
+
from .spacer import SpacerRenderer
|
|
8
|
+
|
|
9
|
+
__all__ = ["BoxRenderer", "ColumnRenderer", "DividerRenderer", "GridRenderer", "RowRenderer", "SectionRenderer", "SpacerRenderer"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class BoxRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render a styled box and its child components.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/layout/box.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render a box using its resolved style.
|
|
14
|
+
"""
|
|
15
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
16
|
+
children = self.render_children(component, context, engine)
|
|
17
|
+
return engine.templates.render(self.template_name, style=style, children=children)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ColumnRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render styled vertical layouts.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/layout/column.html"
|
|
10
|
+
|
|
11
|
+
@staticmethod
|
|
12
|
+
def resolve_layout(component):
|
|
13
|
+
"""
|
|
14
|
+
Resolve column layout properties.
|
|
15
|
+
"""
|
|
16
|
+
styles = []
|
|
17
|
+
if component.align not in (None, "start", "center", "end", "stretch"):
|
|
18
|
+
raise ValueError("Invalid column alignment.")
|
|
19
|
+
if component.justify not in (None, "start", "center", "end", "space-between", "space-around", "space-evenly"):
|
|
20
|
+
raise ValueError("Invalid column justification.")
|
|
21
|
+
if component.direction not in (None, "ltr", "rtl"):
|
|
22
|
+
raise ValueError("Invalid column direction.")
|
|
23
|
+
if component.align:
|
|
24
|
+
styles.append(f"align-items: {component.align}")
|
|
25
|
+
if component.justify:
|
|
26
|
+
styles.append(f"justify-content: {component.justify}")
|
|
27
|
+
if component.gap:
|
|
28
|
+
styles.append(f"gap: {component.gap}")
|
|
29
|
+
if component.direction:
|
|
30
|
+
styles.append(f"direction: {component.direction}")
|
|
31
|
+
return "; ".join(styles)
|
|
32
|
+
|
|
33
|
+
def render(self, component, context, engine):
|
|
34
|
+
"""
|
|
35
|
+
Render a column with its children and styles.
|
|
36
|
+
"""
|
|
37
|
+
children = self.render_children(component, context, engine)
|
|
38
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
39
|
+
layout = self.resolve_layout(component)
|
|
40
|
+
style = "; ".join(part for part in (style, layout) if part)
|
|
41
|
+
return engine.templates.render(self.template_name, children=children, style=style)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DividerRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render visual separators between report sections.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/layout/divider.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render a divider with its resolved styles.
|
|
14
|
+
"""
|
|
15
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
16
|
+
return engine.templates.render(self.template_name, style=style)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from ..base import BaseHtmlRenderer
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
GRID_TRACK_PATTERN = re.compile(r"^(?:\d+(?:\.\d+)?(?:fr|px|%|rem|em)|auto|min-content|max-content)$")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class GridRenderer(BaseHtmlRenderer):
|
|
9
|
+
"""
|
|
10
|
+
Render report components in a grid layout.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
template_name = "components/layout/grid.html"
|
|
14
|
+
|
|
15
|
+
def render(self, component, context, engine):
|
|
16
|
+
"""
|
|
17
|
+
Render grid columns and nested components.
|
|
18
|
+
"""
|
|
19
|
+
style = context.resolve_style(component)
|
|
20
|
+
columns = self.resolve_columns(component.columns)
|
|
21
|
+
css_class = self.get_class(component.columns, style.direction or context.direction)
|
|
22
|
+
children = self.render_children(component, context, engine)
|
|
23
|
+
return engine.templates.render(self.template_name, children=children, columns=columns, flow=css_class, style=engine.styles.resolve(style))
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def resolve_columns(columns):
|
|
27
|
+
"""
|
|
28
|
+
Resolve grid column definitions.
|
|
29
|
+
"""
|
|
30
|
+
if isinstance(columns, bool):
|
|
31
|
+
raise ValueError("Grid columns must be a positive integer or valid track definition.")
|
|
32
|
+
if isinstance(columns, int):
|
|
33
|
+
if columns < 1:
|
|
34
|
+
raise ValueError("Grid columns must be a positive integer.")
|
|
35
|
+
return f"repeat({columns}, minmax(0, 1fr))"
|
|
36
|
+
if isinstance(columns, str):
|
|
37
|
+
tracks = columns.split()
|
|
38
|
+
if tracks and all(GRID_TRACK_PATTERN.fullmatch(track) for track in tracks):
|
|
39
|
+
return " ".join(tracks)
|
|
40
|
+
raise ValueError("Invalid grid column definition.")
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def get_class(columns, direction):
|
|
44
|
+
"""
|
|
45
|
+
Get grid direction and column CSS classes.
|
|
46
|
+
"""
|
|
47
|
+
count = columns if isinstance(columns, int) else len(columns.split())
|
|
48
|
+
return f"rk-grid--{direction} rk-grid--cols-{count}"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class RowRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render styled horizontal layouts.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/layout/row.html"
|
|
10
|
+
|
|
11
|
+
@staticmethod
|
|
12
|
+
def resolve_layout(component):
|
|
13
|
+
"""
|
|
14
|
+
Resolve row layout properties.
|
|
15
|
+
"""
|
|
16
|
+
styles = []
|
|
17
|
+
if component.justify:
|
|
18
|
+
styles.append(f"justify-content: {component.justify}")
|
|
19
|
+
if component.align:
|
|
20
|
+
styles.append(f"align-items: {component.align}")
|
|
21
|
+
if component.gap:
|
|
22
|
+
styles.append(f"gap: {component.gap}")
|
|
23
|
+
if component.wrap:
|
|
24
|
+
styles.append("flex-wrap: wrap")
|
|
25
|
+
return "; ".join(styles)
|
|
26
|
+
|
|
27
|
+
def render(self, component, context, engine):
|
|
28
|
+
"""
|
|
29
|
+
Render a row with its children and styles.
|
|
30
|
+
"""
|
|
31
|
+
children = self.render_children(component, context, engine)
|
|
32
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
33
|
+
layout = self.resolve_layout(component)
|
|
34
|
+
style = "; ".join(part for part in (style, layout) if part)
|
|
35
|
+
return engine.templates.render(self.template_name, children=children, style=style)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SectionRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render styled report sections.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/layout/section.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render a section with its children and styles.
|
|
14
|
+
"""
|
|
15
|
+
children = self.render_children(component, context, engine)
|
|
16
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
17
|
+
return engine.templates.render(self.template_name, children=children, style=style)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SpacerRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render empty spacing between report components.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/layout/spacer.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render a spacer with the requested height.
|
|
14
|
+
"""
|
|
15
|
+
if isinstance(component.height, bool) or not isinstance(component.height, (int, float)) or not 0 <= component.height < float("inf"):
|
|
16
|
+
raise ValueError("Spacer height must be a finite non-negative number.")
|
|
17
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
18
|
+
return engine.templates.render(self.template_name, height=component.height, style=style)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
from ...assets import AssetResolver
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ImageRenderer(BaseHtmlRenderer):
|
|
6
|
+
"""
|
|
7
|
+
Render images into HTML.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
template_name = "components/media/image.html"
|
|
11
|
+
|
|
12
|
+
def render(self, component, context, engine):
|
|
13
|
+
"""
|
|
14
|
+
Render an image with its presentation properties.
|
|
15
|
+
"""
|
|
16
|
+
style = engine.styles.resolve(context.resolve_style(component))
|
|
17
|
+
source = AssetResolver.resolve(component.src)
|
|
18
|
+
return engine.templates.render(self.template_name, component=component, source=source, style=style)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PageBreakRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render a forced page break.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/pagination/page_break.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render a page break marker.
|
|
14
|
+
"""
|
|
15
|
+
return engine.templates.render(self.template_name)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from ..base import BaseHtmlRenderer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PageNumberRenderer(BaseHtmlRenderer):
|
|
5
|
+
"""
|
|
6
|
+
Render a page numbering placeholder.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
template_name = "components/pagination/page_number.html"
|
|
10
|
+
|
|
11
|
+
def render(self, component, context, engine):
|
|
12
|
+
"""
|
|
13
|
+
Render the page numbering format.
|
|
14
|
+
"""
|
|
15
|
+
return ""
|