class _TableCellBase(Element): def __init__(self, element_name, *content): super(_TableCellBase, self).__init__(element_name) self.extend(content) rows = int_html_attribute("rowspan", 1) columns = int_html_attribute("colspan", 1)
class Input(VoidElement): """An HTML <input> element. >>> input_ = Input("text", "description") >>> input_.size = 20 >>> input_.placeholder = "Enter description..." For most input types, a specific sub-class is provided. """ def __init__(self, type_="text", name=""): """Create an HTML input element. The type_ argument sets the HTML type attribute. Possible values are 'text', 'email', 'password', 'submit', etc. For most of these types, a more specific sub-class is provided. The optional name argument sets this input element's name, used when submitting a form. """ super().__init__("input") self.type = type_ self.name = name name = html_attribute("name", default="") value = html_attribute("value", default="") readonly = boolean_html_attribute("readonly") disabled = boolean_html_attribute("disabled") type = html_attribute("type") autocomplete = html_attribute("autocomplete") placeholder = html_attribute("placeholder") size = int_html_attribute("size") focus = boolean_html_attribute("autofocus")
class FileInput(Input): """An HTML file input (<input type="file">) element.""" def __init__(self, name=""): super(FileInput, self).__init__("file", name) max_length = int_html_attribute("maxlength") accept = list_html_attribute("accept")
class TextArea(Element): """An HTML <textarea> element. >>> area = TextArea("element-name") >>> area.placeholder = "Placeholder text ..." >>> area.append("Initial text area content.") """ def __init__(self, name=""): super(TextArea, self).__init__("textarea") self.name = name name = html_attribute("name", default="") readonly = boolean_html_attribute("readonly") disabled = boolean_html_attribute("disabled") columns = int_html_attribute("cols") rows = int_html_attribute("rows") placeholder = html_attribute("placeholder")
class OrderedList(_ListBase): """An HTML ordered list (<ol>) element. It contains ListItem children. >>> list_ = OrderedList() >>> item = list_.create_item("First Item") >>> item.add_css_classes("first-item") >>> list_.append(ListItem("Second Item")) """ def __init__(self): super(OrderedList, self).__init__("ol") start = int_html_attribute("start", 1)
class MyElement(Element): attr = int_html_attribute("data-attr", default=42)
class MyElement(Element): attr = int_html_attribute("data-attr")