Download compiler/classes/Node.py from Bruno/pix2code: direct link, hf CLI and curl.
- Browser
- Download file 930 Bytes
-
https://huggingface.co/Bruno/pix2code/resolve/refs%2Fpr%2F1/compiler/classes/Node.py
- Command line
-
hf download hf://Bruno/pix2code@refs/pr/1/compiler/classes/Node.py
-
curl -L -o Node.py https://huggingface.co/Bruno/pix2code/resolve/refs%2Fpr%2F1/compiler/classes/Node.py
930 Bytes
| #!/usr/bin/env python | |
| from __future__ import print_function | |
| __author__ = 'Tony Beltramelli - www.tonybeltramelli.com' | |
| class Node: | |
| def __init__(self, key, parent_node, content_holder): | |
| self.key = key | |
| self.parent = parent_node | |
| self.children = [] | |
| self.content_holder = content_holder | |
| def add_child(self, child): | |
| self.children.append(child) | |
| def show(self): | |
| print(self.key) | |
| for child in self.children: | |
| child.show() | |
| def render(self, mapping, rendering_function=None): | |
| content = "" | |
| for child in self.children: | |
| content += child.render(mapping, rendering_function) | |
| value = mapping[self.key] | |
| if rendering_function is not None: | |
| value = rendering_function(self.key, value) | |
| if len(self.children) != 0: | |
| value = value.replace(self.content_holder, content) | |
| return value | |