Beispiel #1
0
def wrap_page(page, wrapper, variables, templates):
    with open(f"templates/{wrapper}.mediawiki", "r") as fp:
        body = fp.read()

    wiki_page = WikiPage(page)
    body = preprocess.begin(wiki_page, body)
    wtp = wikitextparser.parse(body)

    if wrapper != "Error":
        if wiki_page.has_history(page):
            filename = wiki_page.page_ondisk_name(page)
            if filename:
                variables["history_url"] = singleton.STORAGE.get_history_url(
                    filename)
        variables["has_source"] = "1" if wiki_page.has_source(page) else ""
        variables["does_exist"] = "1" if wiki_page.has_history(page) else ""
        variables["create_page_name"] = wiki_page.get_create_page_name(page)
        variables["repository_url"] = singleton.STORAGE.get_repository_url()

    arguments = [
        wikitextparser.Argument(f"|{name}={value}")
        for name, value in variables.items()
    ]
    parameter.replace(wiki_page, wtp, arguments)

    parser_function.replace(wiki_page, wtp)
    for template in reversed(wtp.templates):
        name = template.name.strip()
        if name in templates:
            template.string = templates[name]

    return wtp.string
Beispiel #2
0
 def test_setting_positionality(self):
     a = wtp.Argument("|1=v")
     a.positional = False
     self.assertEqual('|1=v', a.string)
     a.positional = True
     self.assertEqual('|v', a.string)
     a.positional = True
     self.assertEqual('|v', a.string)
     self.assertRaises(ValueError, setattr, a, 'positional', False)
Beispiel #3
0
def wrap_page(page, wrapper, variables, templates):
    with open(f"templates/{wrapper}.mediawiki", "r") as fp:
        body = fp.read()

    wiki_page = WikiPage(page)
    body = preprocess.begin(wiki_page, body)
    wtp = wikitextparser.parse(body)

    if wrapper != "Error":
        if wiki_page.has_history(page):
            filename = wiki_page.page_ondisk_name(page)
            if filename:
                variables["history_url"] = singleton.STORAGE.get_history_url(
                    filename)
        variables["has_source"] = "1" if wiki_page.has_source(page) else ""
        variables["does_exist"] = "1" if wiki_page.has_history(page) else ""
        variables["create_page_name"] = wiki_page.get_create_page_name(page)
        variables["repository_url"] = singleton.STORAGE.get_repository_url()

    variables["language"] = wiki_page.page_get_language(page) or ""
    variables["has_search"] = "1" if sitemap.FRONTEND_URL else ""

    variables["css"] = config.HTML_SNIPPETS["css"]
    variables["favicon"] = config.FAVICON
    variables["html_footer"] = config.HTML_SNIPPETS["footer"]
    variables["html_header"] = config.HTML_SNIPPETS["header"]
    variables["javascript"] = config.HTML_SNIPPETS["javascript"]
    variables["license"] = config.LICENSE
    variables["project_name"] = config.PROJECT_NAME

    arguments = [
        wikitextparser.Argument(f"|{name}={value}")
        for name, value in variables.items()
    ]
    parameter.replace(wiki_page, wtp, arguments)

    parser_function.replace(wiki_page, wtp)
    for template in reversed(wtp.templates):
        name = template.name.strip()
        if name in templates:
            template.string = templates[name]

    return wtp.string
Beispiel #4
0
 def test_basic(self):
     a = wtp.Argument('| a = b ')
     self.assertEqual(' a ', a.name)
     self.assertEqual(' b ', a.value)
     self.assertEqual(False, a.positional)
     self.assertEqual(repr(a), "Argument('| a = b ')")
Beispiel #5
0
 def test_parser_functions_at_the_end(self):
     a = wtp.Argument('| 1 ={{#ifeq:||yes}}')
     pfs = a.parser_functions
     self.assertEqual(1, len(pfs))
Beispiel #6
0
 def test_value_after_convertion_of_positional_to_keywordk(self):
     a = wtp.Argument("""|{{{a|{{{b}}}}}}""")
     a.name = ' 1 '
     self.assertEqual('{{{a|{{{b}}}}}}', a.value)
Beispiel #7
0
 def test_nowikied_arg(self):
     a = wtp.Argument('|<nowiki>1=3</nowiki>')
     self.assertEqual(True, a.positional)
     self.assertEqual('1', a.name)
     self.assertEqual('<nowiki>1=3</nowiki>', a.value)
Beispiel #8
0
 def test_set_value(self):
     a = wtp.Argument('| a = b ')
     a.value = ' c '
     self.assertEqual('| a = c ', a.string)
Beispiel #9
0
 def test_set_name_for_positional_args(self):
     a = wtp.Argument('| b ')
     a.name = a.name
     self.assertEqual('|1= b ', a.string)
Beispiel #10
0
 def test_set_name_at_subspan_boundary(self):
     a = wtp.Argument('|{{ a }}={{ b }}')
     a.name = ' c '
     self.assertEqual('| c ={{ b }}', a.string)
     self.assertEqual('{{ b }}', a.value)
Beispiel #11
0
 def test_set_name(self):
     a = wtp.Argument('| a = b ')
     a.name = ' c '
     self.assertEqual('| c = b ', a.string)
Beispiel #12
0
 def test_anonymous_parameter(self):
     a = wtp.Argument('| a ')
     self.assertEqual('1', a.name)
     self.assertEqual(' a ', a.value)