Improve cuddly #1
1 changed files with 10 additions and 8 deletions
clean and re-order imports, and code style changes
commit
0ecf731df8
|
|
@ -1,14 +1,15 @@
|
||||||
import sys
|
|
||||||
import pathlib
|
import pathlib
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import kdl
|
|
||||||
import click
|
import click
|
||||||
|
import kdl
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from bs4.element import Tag
|
from bs4.element import Tag
|
||||||
from jinja2 import Environment
|
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.
|
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):
|
def __getitem__(self, key):
|
||||||
return self.inner[key]
|
return self.inner[key]
|
||||||
|
|
||||||
class CuddlyNode(object):
|
class CuddlyNode:
|
||||||
"""
|
"""
|
||||||
Common interface to Document and Node.
|
Common interface to Document and Node.
|
||||||
Provide helper method to render to HTMl.
|
Provide helper method to render to HTMl.
|
||||||
|
|
@ -89,7 +90,7 @@ class CuddlyNode(object):
|
||||||
return template.render(variables)
|
return template.render(variables)
|
||||||
|
|
||||||
|
|
||||||
class RenderNode(object):
|
class RenderNode:
|
||||||
def __init__(self, components, env):
|
def __init__(self, components, env):
|
||||||
self.components = components
|
self.components = components
|
||||||
self.env = env
|
self.env = env
|
||||||
|
|
@ -125,12 +126,13 @@ def main(template, input, output):
|
||||||
with open(template_path) as template_file:
|
with open(template_path) as template_file:
|
||||||
template_html = BeautifulSoup(template_file.read(), features="html.parser")
|
template_html = BeautifulSoup(template_file.read(), features="html.parser")
|
||||||
components = template_html.components.extract()
|
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()
|
template_string = template_html.decode()
|
||||||
|
|
||||||
components = {
|
components = {
|
||||||
component.name: component.decode_contents().strip()
|
component.name: component.decode_contents().strip() for component in components
|
||||||
for component in components
|
|
||||||
}
|
}
|
||||||
|
|
||||||
with open(input) as input_file:
|
with open(input) as input_file:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue