diff options
Diffstat (limited to 'htmtl')
| -rw-r--r-- | htmtl/htmtl.py | 4 | ||||
| -rw-r--r-- | htmtl/parsers/when.py | 14 | ||||
| -rw-r--r-- | htmtl/parsers/when_not.py | 14 |
3 files changed, 32 insertions, 0 deletions
diff --git a/htmtl/htmtl.py b/htmtl/htmtl.py index 885fe94..7732f06 100644 --- a/htmtl/htmtl.py +++ b/htmtl/htmtl.py @@ -11,6 +11,8 @@ from .parsers.outer_text import OuterText from .modifier import Modifier from .modifiers.truncate import Truncate from .expression_parser import ExpressionParser +from .parsers.when import When +from .parsers.when_not import WhenNot class Htmtl: @@ -32,6 +34,8 @@ class Htmtl: OuterHtml, OuterPartial, GenericValue, + When, + WhenNot, ] # set default expression modifiers diff --git a/htmtl/parsers/when.py b/htmtl/parsers/when.py new file mode 100644 index 0000000..57a965a --- /dev/null +++ b/htmtl/parsers/when.py @@ -0,0 +1,14 @@ +from typing import Optional +from dompa.nodes import Node +from ..parser import Parser + + +class When(Parser): + def traverse(self, node: Node) -> Optional[Node]: + if "when" in node.attributes: + if not self.expression(node.attributes["when"]): + return None + + node.attributes.pop("when") + + return node
\ No newline at end of file diff --git a/htmtl/parsers/when_not.py b/htmtl/parsers/when_not.py new file mode 100644 index 0000000..68e3d09 --- /dev/null +++ b/htmtl/parsers/when_not.py @@ -0,0 +1,14 @@ +from typing import Optional +from dompa.nodes import Node +from ..parser import Parser + + +class WhenNot(Parser): + def traverse(self, node: Node) -> Optional[Node]: + if "when-not" in node.attributes: + if self.expression(node.attributes["when-not"]): + return None + + node.attributes.pop("when-not") + + return node
\ No newline at end of file |
