From 69968c9e34ae57cfee905d94fc98ec6a83fbe92b Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Mon, 30 Dec 2024 15:32:10 +0200 Subject: bump --- htmtl/attribute_parsers/__init__.py | 0 htmtl/expression_modifiers/__init__.py | 0 htmtl/htmtl.py | 190 ++------------------------------- 3 files changed, 8 insertions(+), 182 deletions(-) create mode 100644 htmtl/attribute_parsers/__init__.py create mode 100644 htmtl/expression_modifiers/__init__.py (limited to 'htmtl') diff --git a/htmtl/attribute_parsers/__init__.py b/htmtl/attribute_parsers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/htmtl/expression_modifiers/__init__.py b/htmtl/expression_modifiers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/htmtl/htmtl.py b/htmtl/htmtl.py index a84101b..10cd806 100644 --- a/htmtl/htmtl.py +++ b/htmtl/htmtl.py @@ -1,187 +1,13 @@ -from __future__ import annotations -from typing import Dict, Any, Tuple, Callable, Optional, Union - - -class Node: - name: str - attributes: Dict[str, str] - children: list[Node] - - def __init__(self, name: str, attributes: Dict[str, str], children: list[Node]): - self.name = name - self.attributes = attributes - self.children = [] - - -class IRBlockPosNode: - name: str - coords: Tuple[int, int] - children: list[Union[IRBlockPosNode, str]] - - def __init__(self, name: str, coords: Tuple[int, int]): - self.name = name - self.coords = coords - - -class IRBlockNode: - name: str - children: list[Union[IRBlockNode, str]] - - def __init__(self, name: str, children: list[IRBlockNode]): - self.name = name - self.children = children +from dompa import Dompa class Htmtl: - __template: str = "" - __ir_block_pos_nodes: list[IRBlockPosNode] = [] - __ir_block_nodes: list[IRBlockNode] = [] - __block_elements = ["html", "head", "body", "div", "span", "a"] - __inline_elements = ["!doctype", "img"] - - def __init__(self, template: str): - self.__template = template - self.__ir_block_pos_nodes = [] - self.__ir_block_nodes = [] - self.__create_ir_block_pos_nodes() - self.__join_ir_block_pos_nodes() - self.__create_nodes() - self.__run_attribute_parsers() - - def __create_ir_block_pos_nodes(self): - tag_start = None - tag_end = None - text_start = None - text_end = None - - for idx, part in enumerate(self.__template): - if part == "<": - if text_start is not None: - text_end = idx - - tag_start = idx - - if part == ">": - tag_end = idx + 1 - - if tag_start is not None and tag_end is not None: - tag = self.__template[tag_start:tag_end] - - if tag.startswith(" list[Tuple[int, IRBlockPosNode]]: - found_block_position_nodes = [] - [start, end] = coords - - for idx, ir_block_position_node in enumerate(self.__ir_block_pos_nodes): - [iter_start, iter_end] = ir_block_position_node.coords - - if iter_start > start and iter_end < end: - found_block_position_nodes.append((idx, ir_block_position_node)) - - return found_block_position_nodes - - def __create_nodes(self): - pass - - def __run_attribute_parsers(self): - pass - - def __find_last_ir_block_pos_match( - self, condition: Callable[[Any], bool] - ) -> Optional[Tuple[int, Any]]: - idx = len(self.__ir_block_pos_nodes) - - for item in reversed(self.__ir_block_pos_nodes): - idx -= 1 - - if condition(item): - return idx, item + __dom: Dompa + __attribute_parsers: list + __expression_modifiers: list - return None + def __init__(self, template: str, attribute_parsers = None, expression_modifiers = None): + self.__dom = Dompa(template) + self.__attribute_parsers = attribute_parsers or [] + self.__expression_modifiers = expression_modifiers or [] - def toHtml(self): - pass -- cgit v1.2.3