Source code for korona.html.tags.col

# -*- coding: utf-8 -*-
"""Module for constructing <col> tag."""

from __future__ import absolute_import

from ...lib.utils import validate_attribute_values
from ...templates.html.tags import col

ATTRIBUTES = {
    'align': {
        'description': 'Specifies the alignment of the content related'
                       ' to a <col> element',
        'values': ['left', 'right', 'center', 'justify', 'char']
    },
    'char': {
        'description': 'Specifies the alignment of the content related'
                       ' to a <col> element to a character',
        'values': None
    },
    'charoff': {
        'description': 'Specifies the number of characters the content'
                       ' will be aligned from the character specified '
                       'by the char attribute',
        'values': None
    },
    'span': {
        'description': 'Specifies the number of columns a <col> '
                       'element should span',
        'values': None
    },
    'valign': {
        'description': 'Specifies the vertical alignment of the '
                       'content related to a <col> element',
        'values': ['top', 'middle', 'bottom', 'baseline']
    },
    'width': {
        'description': 'Specifies the width of a <col> element',
        'values': None
    }
}


[docs]class Col(object): """Class for constructing col tag. Args: align (str): Specifies the alignment of the content related to a <col> element. char (str): Specifies the alignment of the content related to a <col> element to a character. charoff (int): Specifies the number of characters the content will be aligned from the character specified by the char attribute. span (int): Specifies the number of columns a <col> element should span. valign (str): Specifies the vertical alignment of the content related to a <col> element. width (str): Specifies the width of a <col> element. .. versionadded:: 0.2.0 """ def __init__(self, align=None, char=None, charoff=None, span=None, valign=None, width=None): self.tag = 'col' validate_attribute_values( tag=self.tag, attribute_name='align', attribute_value=align, default_values=ATTRIBUTES['align']['values']) self.validate_char_attribute(align=align, value=char) self.validate_charoff_attribute(align=align, char=char, value=charoff) validate_attribute_values( tag=self.tag, attribute_name='valign', attribute_value=valign, default_values=ATTRIBUTES['valign']['values']) self.values = {'align': align, 'char': char, 'charoff': charoff, 'span': span, 'valign': valign, 'width': width}
[docs] def construct(self): """Returns the constructed col tag <col>.""" return col.render(self.values)
[docs] def validate_char_attribute(self, align, value): """Validates char attribute. The char attribute can only be used if the align attribute is set to "char". """ if not value: return if value and align != 'char': raise AttributeError('<col>: The char attribute can only be used ' 'if the align attribute is set to "char".')
[docs] def validate_charoff_attribute(self, align, char, value): """Validates charoff attribute. The charoff attribute can only be used if the char attribute is specified and the align attribute is set to "char". """ if not value: return if value and (not char or align != 'char'): raise AttributeError('<col>: The charoff attribute can only be ' 'used if the char attribute is specified and ' 'the align attribute is set to "char".')