Please join this new Discord server!
Difference between revisions of "Module:Main"
From Etrian Odyssey Wiki
(Created page with "local p = {} function p.main(frame) local args = {} local labels = {} local output = ":''Main article" for i = 1, 10 do if frame:getParent().args[i] ~= nil then args...") |
(This should allow for a variable number of articles) |
||
Line 2: | Line 2: | ||
function p.main(frame) | function p.main(frame) | ||
-- Name input for convenience | |||
local in_args = frame:getParent().args | |||
-- Start building output | |||
local args = {} | local args = {} | ||
local output = ":''Main article" | local output = ":''Main article" | ||
for | |||
if | -- Loop through input: check if labels are entered, and if so, | ||
args[ | -- append them to the link text | ||
for k, v in pairs(in_args) do | |||
if type(k) == "number" then | |||
args[k] = v | |||
elseif type(k) == "string" and k:sub(1,1) == "l" then | |||
local i = tonumber(k:sub(2)) | |||
args[i] = args[i] .. "|" .. v | |||
end | end | ||
end | end | ||
-- Turn the list from above into links, and append to output | |||
if #args > 1 then | if #args > 1 then | ||
output = output .. "s: [[" .. mw.text.listToText(args, "]], [[", "]] and [[") | output = output .. "s: [[" .. mw.text.listToText(args, "]], [[", "]] and [[") | ||
Line 20: | Line 26: | ||
end | end | ||
-- Return completed list of articles | |||
return output .. "]]''" | return output .. "]]''" | ||
end | end | ||
return p | return p |
Latest revision as of 02:03, 17 December 2018
- This documentation is transcluded from Module:Main/doc. To edit this documentation, click here.
Builds the list of articles output by Template:Main. This module allows for an indefinite number of articles to be listed by the template.
local p = {}
function p.main(frame)
-- Name input for convenience
local in_args = frame:getParent().args
-- Start building output
local args = {}
local output = ":''Main article"
-- Loop through input: check if labels are entered, and if so,
-- append them to the link text
for k, v in pairs(in_args) do
if type(k) == "number" then
args[k] = v
elseif type(k) == "string" and k:sub(1,1) == "l" then
local i = tonumber(k:sub(2))
args[i] = args[i] .. "|" .. v
end
end
-- Turn the list from above into links, and append to output
if #args > 1 then
output = output .. "s: [[" .. mw.text.listToText(args, "]], [[", "]] and [[")
else
output = output .. ": [[" .. args[1]
end
-- Return completed list of articles
return output .. "]]''"
end
return p