コード例 #1
0
ファイル: template.py プロジェクト: Xaroth/wikitexthtml
def _render_template(instance: WikiTextHtml, template: wikitextparser.Template):
    name = template.name.strip()

    try:
        if not instance.template_exists(name):
            instance.add_error(f'Template "{name}" does not exist.')
    except InvalidTemplate as e:
        # Errors always end with a dot, hence the [:-1].
        instance.add_error(f'{e.args[0][:-1]} (template "{{{{{name}}}}}").')
        return

    instance._templates.add(name)
    if instance._template_path.count(name) >= 10:
        instance.add_error(
            f'Template "{name}" was transcluded itself more than ten times (recursion depth limit reached).'
        )
        return
    instance._template_path.append(name)

    body = instance.template_load(name)
    body = preprocess.begin(instance, body, is_transcluding=True)
    body = preprocess.hr_line(instance, body)

    wtp = wikitextparser.parse(body)

    parameter.replace(instance, wtp, template.arguments)
    parser_function.replace(instance, wtp)
    replace(instance, wtp)

    template.string = wtp.string

    instance._template_path.remove(name)
コード例 #2
0
 def test_overwriting_template_args(self):
     t = Template('{{t|a|b|c}}')
     c = t.arguments[-1]
     self.assertEqual('|c', c.string)
     t.string = '{{t|0|a|b|c}}'
     self.assertEqual('', c.string)
     self.assertEqual('0', t.get_arg('1').value)
     self.assertEqual('c', t.get_arg('4').value)
コード例 #3
0
def test_overwriting_template_args():
    t = Template('{{t|a|b|c}}')
    c = t.arguments[-1]
    assert '|c' == c.string
    t.string = '{{t|0|a|b|c}}'
    assert '' == c.string
    assert '0' == t.get_arg('1').value
    assert 'c' == t.get_arg('4').value