Module:Versions

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

Module:Versions

Provides utility functions related to game versions by referencing the dataset defined in Module:Versions/data.

This module provides the following function(s):

  • latest - returns the latest version string.
  • check - returns whether a given version string exists in the dataset.
  • get - renders an InfoboxNavRow with the prev and next versions populated correspondingly.

Usage

Return latest version

Returns the latest version, i.e. the current last entry in Module:Versions/data, as a string.

{{#invoke:Versions|latest}}

Check whether a version exists

Returns true if the given version string exists in Module:Versions/data, or false otherwise.

{{#invoke:Versions|check|1.3.15.0}}

Inside Template:VersionInfobox

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

{{#invoke:Versions|get|{{{version|{{BASEPAGENAME}}}}}}}

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

latest

<No parameters>

check

1
string
The version string to look up in Module:Versions/data.

get

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

local p = {}

local common = require("Module:Common")
local data = require("Module:Versions/data")

-- ---------- Rendering ----------

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

    if prevVer then parts[#parts + 1] = "|prev=" .. prevVer end
    if nextVer then parts[#parts + 1] = "|next=" .. nextVer end
    parts[#parts + 1] = "}}"

    return table.concat(parts)
end

-- ---------- Interface ----------

function p.latest(frame)
    return data[#data]
end

function p.check(frame)
    local inputVer = common.trim(frame.args[1])

    for _, version in ipairs(data) do
        if version == inputVer then return "true" end
    end

    return "false"
end

function p.get(frame)
    local inputVer = common.trim(frame.args[1])
    if inputVer == "" then return common.renderError("No version specified") end

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

    return common.renderError("Unknown version: <code>%s</code>. New versions must be added to [[Module:Versions/data]].", inputVer)
end

return p