Module:ContractLinkHandler
Jump to navigation
Jump to search
Module:ContractLinkHandler
Builds link targets for one or more Contracts within a Contract Chain, for use by Template:ContractLinkHandler.
This module should not be invoked directly. To link Contracts, use Template:ContractLinkHandler.
This module provides the following function(s):
main- returns a tilde-separated list ofChain/Contract|Contractlink targets.
Usage
Single contract
{{#invoke:ContractLinkHandler|main|Wrecking Crew|Scrap Mettle}}
Multiple contracts
{{#invoke:ContractLinkHandler|main|Copper Required~Wrecking Crew|Scrap Mettle}}
Parameters
main
- 1
- string
- One or more Contract names, separated by tildes
~. Each item is trimmed, and empty items are skipped. - Returns an empty string if no valid names are supplied.
- 2
- string
- The Contract Chain name, used as the prefix for every link target.
- Returns an error message if not specified.
Notes
- Output is a tilde-separated string of link targets, not finished wikitext. Pass it to Module:Common's
bulletListwithlink=yes(as Template:InfoboxNavRow does) to render each item as a link. - Contract names must not contain
~or|, as these are reserved for list separation and link display text respectively.
local p = {}
local common = require("Module:Common")
-- ---------- Interface ----------
-- builds a tilde-separated list of "Chain/Contract|Contract" link targets
-- arg 1: tilde-separated contract names
-- arg 2: chain name (defaults to the current page's base name)
function p.main(frame)
local args = frame.args
local chain = common.trim(args[2] or "")
if chain == "" then return common.renderError("No contract chain specified") end
local out = {}
for name in mw.text.gsplit(args[1] or "", "~") do
name = common.trim(name)
if name ~= "" then
out[#out + 1] = chain .. "/" .. name .. "|" .. name
end
end
return table.concat(out, "~")
end
return p