Module:Updates

From Dune: Awakening Community Wiki
Jump to navigation Jump to search

Module:Updates

Determines previous and next update versions, relative to a specified version string, using the manually-ordered dataset defined in Module:Updates/data.

Usage

Inside Template:UpdateInfobox

The module is invoked by the template to render navigation buttons.

{{#invoke:Updates|get|{{{version|{{PAGENAME}}}}}}}

The version parameter defaults to the current page name if not specified. The module returns a Template:InfoboxNavRow invocation with the previous and next update versions as parameters.

Parameters

get

1
string
The version string corresponding to an entry in Module:Updates/data.

Notes

  • Version ordering is determined entirely by the sequence defined in Module:Updates/data, thus the dataset must remain sorted in ascending version order for navigation to function correctly.
  • If the provided version does not exist in the dataset, a warning message is returned that will display in the infobox.
  • The module uses frame:preprocess() to expand the Template:InfoboxNavRow invocation.
    • This carries a performance overhead, which was the reason why Module:Swatches had to be overhauled to render the infobox directly, because it can require displaying tens of infoboxes at one go.
    • On the other hand, it is acceptable in this use case because of the low usage requirements.

local p = {}

local data = require("Module:Updates/data")

local function buildNavRow(prevVer, nextVer)
    local parts = {"{{InfoboxNavRow"}

    if prevVer then table.insert(parts, "|prev=" .. prevVer) end
    if nextVer then table.insert(parts, "|next=" .. nextVer) end
    table.insert(parts, "}}")

    return table.concat(parts)
end

function p.get(frame)
    local currentVer = mw.text.trim(frame.args[1] or "")

    if currentVer == "" then return "'''NO VERSION SPECIFIED'''" end

    for i, version in ipairs(data) do
        if version == currentVer then return frame:preprocess(buildNavRow(data[i-1], data[i+1])) end
    end

    return "'''SPECIFIED VERSION NOT PRESENT IN [[Module:Updates/data]]'''"
end

return p