示例#1
0
def Case():
    """
    Creates a ``pipe`` Element with each line of vrange becoming
    a case with an empty cond

    .. code-block::xml

        Spam
        Ham
        Eggs

        <pipe label="" capture="">
            <case label="c1" cond="">Spam</case>
            <case label="c2" cond="">Ham</case>
            <case label="c3" cond="">Eggs</case>
            <case label="c99" cond="1">BAD PIPE</case>
        </pipe>
    """
    print('test')

    cases = deciphervimclips.cell_factory(get_current_range(),
                                          "case",
                                          "c",
                                          attrs={'cond': ''})

    cases.append("""  <case label="c99" cond="1">BAD PIPE</case>""")

    cases = ['<pipe label="" capture="">'] + cases + ['</pipe>']

    # set_current_range( cases )

    print(dir(vim.current.range.start))
    def test_cell_factory(self):
        template = '  <{0} label="{1}"{2}>{3}</{0}>'

        def create_mock(*args):
            if args[3]:
                attrs_str = ' ' + ' '.join('{0}="{1}"'.format(k, v) for k, v in args[3].items())
            else:
                attrs_str = ''

            rows = []
            for i, line in enumerate(args[0]):
                rows.append(template.format(args[1], args[2] + str(i + 1), attrs_str, line))
            return ' '.join(rows)

        test_cells = (
            (['SPAM BACON EGGS'], 'row', 'r', {}),
            (['SPAM', 'BACON', 'EGGS'], 'row', 'r', {}),
        )

        for args in test_cells:
            mock_xml = etree.fromstring('<root>{0}</root>'.format(create_mock(*args)))
            generated_xml = etree.fromstring('<root>{0}</root>'.format(''.join(deciphervimclips.cell_factory(*args))))
            mock_xml, generated_xml = map(etree.tostring, (mock_xml, generated_xml))
            mock_xml, generated_xml = map(clean_xml, (mock_xml, generated_xml))
            self.assertEqual(mock_xml, generated_xml)
示例#3
0
def Rates():
    """
    Makes ``col`` Cells with vrange lines as text nodes
    also, if the line leads with an integer it is placed at the
    end of a <br/>

    .. code-block::xml

        1. Very Spammy
        2.
        3. Not at all Spammy

        <col label="c1">Very Spammy<br/>1</col>
        <col label="c2">2</col>
        <col label="c3">Not at all Spammy<br/>3</col>
    """

    lines = [line.strip() for line in get_current_range() if line.strip()]

    row_rgx = re.compile(r"^(?P<num>[a-zA-Z0-9-_]+)\.?\s+(?P<text>\w.*)")

    poleTemplate = "{num}. {text}<br/>{num}"
    innerTemplate = "{num}. {num}"

    for i, line in enumerate(lines):
        if row_rgx.match(line):
            lines[i] = poleTemplate.format(**row_rgx.match(line).groupdict())
        else:
            num = re.match(r"(?P<num>\d+)\.?", line)
            lines[i] = innerTemplate.format(**num.groupdict())

    set_current_range(deciphervimclips.cell_factory(lines, "col", "c"))
    def test_cell_factory(self):
        template = '  <{0} label="{1}"{2}>{3}</{0}>'

        def create_mock(*args):
            if args[3]:
                attrs_str = ' ' + ' '.join('{0}="{1}"'.format(k, v) for k, v in args[3].items())
            else:
                attrs_str = ''

            rows = []
            for i, line in enumerate(args[0]):
                rows.append(template.format(args[1], args[2] + str(i + 1), attrs_str, line))
            return ' '.join(rows)

        test_cells = (
            (['SPAM BACON EGGS'], 'row', 'r', {}),
            (['SPAM', 'BACON', 'EGGS'], 'row', 'r', {}),
        )

        for args in test_cells:
            mock_xml = etree.fromstring('<root>{0}</root>'.format(create_mock(*args)))
            generated_xml = etree.fromstring('<root>{0}</root>'.format(''.join(deciphervimclips.cell_factory(*args))))
            mock_xml, generated_xml = map(etree.tostring, (mock_xml, generated_xml))
            mock_xml, generated_xml = map(clean_xml, (mock_xml, generated_xml))
            self.assertEqual(mock_xml, generated_xml)
示例#5
0
def NoAnswer():
    """
    Makes ``noanswer`` Cells with vrange lines as text nodes

    .. code-block::xml

        99. Ni!

        <noanswer label="r99">Ni!</noanswer>
    """
    set_current_range(
        deciphervimclips.cell_factory(get_current_range(), "noanswer", "r"))
示例#6
0
def Rows():
    """
    Makes ``row`` Cells with vrange lines as text nodes

    .. code-block::xml

        1. Spam

        <row label="r1">Spam</row>
    """
    set_current_range(
        deciphervimclips.cell_factory(get_current_range(), "row", "r") +
        ['\n'])
示例#7
0
def Choice():
    """
    Makes ``choice`` Cells with vrange lines as text nodes

    .. code-block::xml

        3. Eggs

        <choice label="ch3">Eggs</choice>
    """
    set_current_range(
        deciphervimclips.cell_factory(get_current_range(), "choice", "ch") +
        ['\n'])
示例#8
0
def Cols():
    """
    Makes ``col`` Cells with vrange lines as text nodes

    .. code-block::xml

        2. Ham

        <col label="c2">Ham</col>
    """
    set_current_range(
        deciphervimclips.cell_factory(get_current_range(), "col", "c") +
        ['\n'])
示例#9
0
def MakeGroups():
    """
    """
    output = deciphervimclips.cell_factory(get_current_range(), "group", "g")

    set_current_range(output)