예제 #1
0
def build_dom_calendar_table(rows, head=None, caption=None, cls=None):
    """
    Build a DOM table with data from <rows>.
    """
    table = moin_page.table()
    if cls is not None:
        table.attrib[moin_page('class')] = cls

    if caption is not None:
        table_caption = moin_page.caption()
        table_caption.append(caption)
        table.append(table_caption)

    if head is not None:
        table_head = moin_page.table_header()
        table_row = moin_page.table_row()
        for _idx, cell_tuple in enumerate(head):
            (cell, cell_class) = cell_tuple
            table_cell = moin_page.table_cell(children=[cell])
            table_cell.attrib[moin_page('class')] = cell_class
            table_row.append(table_cell)
        table_head.append(table_row)
        table.append(table_head)
    table_body = moin_page.table_body()

    for row in rows:
        table_row = moin_page.table_row()
        for cell_tuple in row:

            # - cell content
            # - href for <a> tag
            # - CSS class for <td> tag
            (cell, cell_addr, cell_class) = cell_tuple

            # empty cell
            if not cell_addr:
                table_cell = moin_page.table_cell(children=[cell])
                table_cell.attrib[moin_page('class')] = cell_class

            # cell with link to calendar
            else:
                table_a = moin_page.a(attrib={xlink.href: Iri(cell_addr)},
                                      children=[cell])
                table_cell = moin_page.table_cell(children=[table_a])
                table_cell.attrib[moin_page('class')] = cell_class
            table_row.append(table_cell)
        table_body.append(table_row)
    table.append(table_body)
    return table
예제 #2
0
파일: moinwiki_in.py 프로젝트: wobsta/moin
    def tablerow_cell_repl(self,
                           stack,
                           table,
                           row,
                           cell,
                           cell_marker,
                           cell_text,
                           cell_args=None):
        def add_attr_to_style(attrib, attr):
            attr = attr.strip().decode('unicode-escape')
            if not attr.endswith(';'):
                attr += ';'
            if attrib.get(moin_page('style'), ""):
                attrib[moin_page('style')] = attrib.get(
                    moin_page('style'), "") + " " + attr
            else:
                attrib[moin_page('style')] = attr

        element = moin_page.table_cell()
        stack.push(element)

        if len(cell_marker) // 2 > 1:
            element.set(moin_page.number_columns_spanned,
                        len(cell_marker) // 2)

        if cell_args:
            cell_args = _TableArguments()(cell_args)
            no_errors = True

            # any positional parameters will be errors;  retrieved as (key=None, value="some-positional-param");
            for key, value in cell_args.items():
                if key == 'bgcolor':
                    if no_errors:
                        # avoid overriding error highlighting
                        add_attr_to_style(
                            element.attrib,
                            'background-color: {0};'.format(value))
                elif key == 'rowbgcolor':
                    add_attr_to_style(row.attrib,
                                      'background-color: {0};'.format(value))
                elif key == 'tablebgcolor':
                    add_attr_to_style(table.attrib,
                                      'background-color: {0};'.format(value))
                elif key == 'width':
                    add_attr_to_style(element.attrib,
                                      'width: {0};'.format(value))
                elif key == 'tablewidth':
                    add_attr_to_style(table.attrib,
                                      'width: {0};'.format(value))
                elif key == 'caption':
                    table.insert(0, moin_page.caption(children=[
                        value,
                    ]))
                elif key == 'tableclass':
                    table.attrib[moin_page(
                        'class')] = value + u' moin-wiki-table'
                elif key == 'rowclass':
                    row.attrib[moin_page('class')] = value
                elif key == 'class':
                    element.attrib[moin_page('class')] = value
                elif key == 'tablestyle':
                    add_attr_to_style(table.attrib, value)
                elif key == 'rowstyle':
                    add_attr_to_style(row.attrib, value)
                elif key == 'style':
                    if no_errors:
                        add_attr_to_style(element.attrib, value)
                elif key == 'tableid':
                    table.attrib[moin_page('id')] = value
                elif key == 'rowid':
                    row.attrib[moin_page('id')] = value
                elif key == 'id':
                    element.attrib[moin_page('id')] = value
                elif key == 'number-columns-spanned':
                    element.attrib[moin_page(key)] = value
                elif key == 'number-rows-spanned':
                    element.attrib[moin_page(key)] = value
                else:
                    if key == 'error' or key is None:
                        error = value
                    else:
                        error = key
                    cell_markup = cell.split('>')[0]
                    cell_markup = cell_markup.split('<')[1]
                    msg1 = _('Error:')
                    msg2 = _('is invalid within')
                    cell_text = '[ {0} "{1}" {2} <{3}>&nbsp;]<<BR>>{4}'.format(
                        msg1, error, msg2, cell_markup, cell_text)
                    if no_errors:
                        add_attr_to_style(
                            element.attrib,
                            'background-color: pink; color: black;')
                    no_errors = False

        self.parse_inline(cell_text, stack, self.inline_re)

        stack.pop_name('table-cell')