yamlrender 1.0.0__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.
@@ -0,0 +1,3 @@
1
+ env
2
+ .DS_Store
3
+ dist
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mizuki Hikaru
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,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: yamlrender
3
+ Version: 1.0.0
4
+ Summary: yamlrender takes a YAML file and a Jinja2 template and renders a HTML or PDF file, populating the variables in the Jinja2 template with data from your YAML file.
5
+ Project-URL: Homepage, https://github.com/mizuki-hikaru/yamlrender
6
+ Project-URL: Issues, https://github.com/mizuki-hikaru/yamlrender/issues
7
+ Author-email: Mizuki Hikaru <mizuki@hikaru.org>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.9
13
+ Requires-Dist: jinja2
14
+ Requires-Dist: mistletoe
15
+ Requires-Dist: pyyaml
16
+ Requires-Dist: weasyprint
17
+ Description-Content-Type: text/markdown
18
+
19
+ # yamlrender
20
+
21
+ Please find the documentation at [hikaru.org](https://hikaru.org/projects/yamlrender).
@@ -0,0 +1,3 @@
1
+ # yamlrender
2
+
3
+ Please find the documentation at [hikaru.org](https://hikaru.org/projects/yamlrender).
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "yamlrender"
7
+ version = "1.0.0"
8
+ authors = [
9
+ { name="Mizuki Hikaru", email="mizuki@hikaru.org" },
10
+ ]
11
+ description = "yamlrender takes a YAML file and a Jinja2 template and renders a HTML or PDF file, populating the variables in the Jinja2 template with data from your YAML file."
12
+ readme = "README.md"
13
+ requires-python = ">=3.9"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ "pyyaml",
21
+ "jinja2",
22
+ "weasyprint",
23
+ "mistletoe",
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/mizuki-hikaru/yamlrender"
28
+ Issues = "https://github.com/mizuki-hikaru/yamlrender/issues"
29
+
30
+ [project.scripts]
31
+ yamlrender = "yamlrender:cli"
@@ -0,0 +1,46 @@
1
+ import sys
2
+ import yaml
3
+ import re
4
+ from markupsafe import Markup
5
+ from pathlib import Path
6
+ from jinja2 import Environment, FileSystemLoader, select_autoescape
7
+ from mistletoe import markdown
8
+
9
+ def yamlrender(input_path, template_path, output_path):
10
+ input_path = Path(input_path)
11
+ template_path = Path(template_path)
12
+ output_path = Path(output_path)
13
+
14
+ # Load YAML data
15
+ with input_path.open('r', encoding='utf-8') as f:
16
+ data = yaml.safe_load(f)
17
+
18
+ templates_dir = template_path.parent
19
+
20
+ # Set up Jinja2 environment
21
+ env = Environment(loader=FileSystemLoader(templates_dir), autoescape=select_autoescape(['html', 'xml']))
22
+ env.filters["markdown"] = lambda text: Markup(markdown(text or ""))
23
+ template = env.get_template(template_path.name)
24
+ rendered_html = template.render(**data, _context=data)
25
+
26
+ # Output
27
+ if output_path.suffix == ".pdf":
28
+ from weasyprint import HTML
29
+ HTML(string=rendered_html, base_url=".").write_pdf(str(output_path))
30
+ else:
31
+ output_path.write_text(rendered_html, encoding='utf-8')
32
+
33
+ def cli():
34
+ import argparse
35
+
36
+ parser = argparse.ArgumentParser(description="Render HTML or PDF from a YAML file and Jinja2 template.")
37
+ parser.add_argument("input", help="Path to input YAML file")
38
+ parser.add_argument("template", help="Path to Jinja2 template file")
39
+ parser.add_argument("output", help="Path to output HTML or PDF file")
40
+ args = parser.parse_args()
41
+
42
+ try:
43
+ yamlrender(args.input, args.template, args.output)
44
+ except Exception as e:
45
+ print(f"Error: {e}", file=sys.stderr)
46
+ sys.exit(1)