Jump to content

Template:Lua Functions/Updating: Difference between revisions

From The Battle for Wesnoth Wiki
Laela (talk | contribs)
Created page with "Reference how this page was made. For each relevant LuaAPI page run javascript <syntaxhighlight lang='js'> [...document.querySelectorAll('.toclevel-2 .toctext')].map(e => e.i..."
 
Laela (talk | contribs)
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 7: Line 7:
Put output to separate lines of data.txt and run python
Put output to separate lines of data.txt and run python
<syntaxhighlight lang='py'>
<syntaxhighlight lang='py'>
with open ("data.txt") as f:
with open("data.txt") as f:
    print("""{| class="reference-sidebar"
|
<span class="editlink">&#91;[{{SERVER}}{{localurl:Template:Lua Functions|action=edit}} edit]&#93;</span>'''Lua Functions'''""")
    sections = {}
     for line in f:
     for line in f:
         line = line.strip().strip("'")
         line = line.strip().strip("'")
        line = line.replace(",wesnoth.audio,wesnoth.achievements,wesnoth.game_events,wesnoth.map,wesnoth.interface,wesnoth.paths,wesnoth.schedule,wesnoth.sides,wesnoth.sync,wesnoth.units","")
         methods, url = line.split(" @ ")
         methods, url = line.split(" @ ")
         url = url.removeprefix("https://wiki.wesnoth.org/")
         url = url.removeprefix("https://wiki.wesnoth.org/")
         for method in methods.split(","):
        header = url.removeprefix("LuaAPI/").replace("/",".")
             print("[[{}#{}|{}]]<br>".format(url, method, method))
 
        sections[header] = []
         for method in sorted(methods.split(",")):
             methodWithoutLocation = method.split(".")[-1]
            row = "[[{}#{}|{}]]<br>".format(url, method, method)
            sections[header].append(row)
 
    for header in sorted(sections, key=lambda x: '_'+x if x.startswith('wesnoth') else x):
        print("|-\n|''{}''".format(header))
        for row in sections[header]:
            print(row)
    print("""|}<includeonly>[[Category:Lua Reference]]</includeonly><noinclude>A box with all the Lua functions, each one linking to the page and section they are described in. It was generated using [[/Updating|this method]]. This box should be included in [[LuaAPI|Lua reference]] page.</noinclude>""")
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 20:45, 26 April 2024

Reference how this page was made.

For each relevant LuaAPI page run javascript

[...document.querySelectorAll('.toclevel-2 .toctext')].map(e => e.innerText).filter(s => s.startsWith('wesnoth') || s.startsWith('wml') || s.startsWith('gui') || s.startsWith('location_set') || s.startsWith('functional') || s.startsWith('stringx') || s.startsWith('mathx') || s.startsWith('filesystem') || s.startsWith('ai') || s.startsWith('utils') || s.startsWith('unit_test')) + " @ " + document.location

Put output to separate lines of data.txt and run python

with open("data.txt") as f:
    print("""{| class="reference-sidebar"
|
<span class="editlink">&#91;[{{SERVER}}{{localurl:Template:Lua Functions|action=edit}} edit]&#93;</span>'''Lua Functions'''""")
    sections = {}
    for line in f:
        line = line.strip().strip("'")
        line = line.replace(",wesnoth.audio,wesnoth.achievements,wesnoth.game_events,wesnoth.map,wesnoth.interface,wesnoth.paths,wesnoth.schedule,wesnoth.sides,wesnoth.sync,wesnoth.units","")
        methods, url = line.split(" @ ")
        url = url.removeprefix("https://wiki.wesnoth.org/")
        header = url.removeprefix("LuaAPI/").replace("/",".")

        sections[header] = []
        for method in sorted(methods.split(",")):
            methodWithoutLocation = method.split(".")[-1]
            row = "[[{}#{}|{}]]<br>".format(url, method, method)
            sections[header].append(row)

    for header in sorted(sections, key=lambda x: '_'+x if x.startswith('wesnoth') else x):
        print("|-\n|''{}''".format(header))
        for row in sections[header]:
            print(row)
    print("""|}<includeonly>[[Category:Lua Reference]]</includeonly><noinclude>A box with all the Lua functions, each one linking to the page and section they are described in. It was generated using [[/Updating|this method]]. This box should be included in [[LuaAPI|Lua reference]] page.</noinclude>""")