Advertisement
adolphuZ

Untitled

Jun 5th, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. from abc import ABC, abstractmethod
  2.  
  3. class HtmlBuilder:
  4.     def __init__(self):
  5.         self.html = ""
  6.  
  7.     def add_element(self, element):
  8.         self.html += element.render()
  9.  
  10.     def get_html(self):
  11.         return self.html
  12.  
  13. class HtmlElement(ABC):
  14.     @abstractmethod
  15.     def render(self):
  16.         pass
  17.  
  18. class Div(HtmlElement):
  19.     def render(self):
  20.         return "<div></div>\n"
  21.  
  22. class Label(HtmlElement):
  23.     def render(self):
  24.         return "<label>Label</label>\n"
  25.  
  26. class Input(HtmlElement):
  27.     def render(self):
  28.         return "<input type='text'/>\n"
  29.  
  30. class Select(HtmlElement):
  31.     def render(self):
  32.         return "<select><option>Option</option></select>\n"
  33.  
  34. class Submit(HtmlElement):
  35.     def render(self):
  36.         return "<input type='submit'/>\n"
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement