Module:Versions
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):
get- renders an InfoboxNavRow with theprevandnextversions populated correspondingly.latest- returns the latest version string.
Usage
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.
Return latest version
Returns the latest version, i.e. the current last entry in Module:Versions/data, as a string.
{{#invoke:Versions|latest}}
Parameters
get
- 1
- string
- The version string corresponding to an entry in Module:Versions/data.
latest
- <No parameters>
Notes
get
- If the provided version does not exist in the dataset, a warning message is returned that will display in the infobox.
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.get(frame)
local currentVer = common.trim(frame.args[1])
if currentVer == "" then return common.error("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 common.error("Unknown version: %s. New versions must be added to [[Module:Versions/data]].", currentVer)
end
function p.latest(frame)
return data[#data]
end
return p