Improve cuddly #1

Merged
hannaeko merged 8 commits from improve-cuddly into main 2026-11-16 22:58:43 +01:00
Showing only changes of commit 0ecf731df8 - Show all commits

clean and re-order imports, and code style changes

ariasuni 2026-11-04 23:31:15 +01:00

View file

@ -1,14 +1,15 @@
import sys
import pathlib
from urllib.parse import urlparse
import kdl
import click
import kdl
from bs4 import BeautifulSoup
from bs4.element import Tag
from jinja2 import Environment
from weasyprint import HTML
class CuddlyMaybeList(object):
class CuddlyMaybeList:
"""
If the given list is only one item behave like a proxy to that item.
"""
@ -36,7 +37,7 @@ class CuddlyMaybeList(object):
def __getitem__(self, key):
return self.inner[key]
class CuddlyNode(object):
class CuddlyNode:
"""
Common interface to Document and Node.
Provide helper method to render to HTMl.
@ -89,7 +90,7 @@ class CuddlyNode(object):
return template.render(variables)
class RenderNode(object):
class RenderNode:
def __init__(self, components, env):
self.components = components
self.env = env
@ -125,12 +126,13 @@ def main(template, input, output):
with open(template_path) as template_file:
template_html = BeautifulSoup(template_file.read(), features="html.parser")
components = template_html.components.extract()
components = [element for element in components.children if isinstance(element, Tag)]
components = [
element for element in components.children if isinstance(element, Tag)
]
template_string = template_html.decode()
components = {
component.name: component.decode_contents().strip()
for component in components
component.name: component.decode_contents().strip() for component in components
}
with open(input) as input_file: