Joom's picture
Duplicate from taneemishere/html-code-generation-from-images-with-deep-neural-networks
cea929e
raw
history blame contribute delete
900 Bytes
from __future__ import print_function
__author__ = 'Taneem Jan, taneemishere.github.io'
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