Module:MultiItems

-- -- LUA script for processing multiple items in a string -- separated by "!" -- -- Parameters: -- 1: Items List -- 2: File prefix -- 3: Size (optional: default 50) -- 4: File Suffix (optional) -- -- any characters in the list ' are stripped -- -- if the item name has "(non digit characters)" at the end, -- it is replaced with "-non digit characters" -- -- Plain version is returned if Event version is not in data. --

local p = {}

function p.getItems(frame)

local tArgs

if frame == mw.getCurrentFrame then fParent = frame:getParent tArgs = fParent.args

if (fParent.args[1]) then tArgs = fParent.args else tArgs = frame.args end else tArgs = frame end

local items = tArgs[1] or "" local prefix = tArgs[2] or "" local size = tArgs[3] local suffix = tArgs[4] or ""

if not size or size == "" then size = "50" end

items = mw.ustring.gsub(items, "^%s*(.-)%s*$", "%1") or '' -- check for !! (! at the end of item) -- replace with ^! -- ^ will be replaced back to ! before returning items = mw.ustring.gsub(items, "!!", "^!")

local itemsFile = "" local space = ""

for it in mw.text.gsplit(items, "%s*!%s*") do

local lcIt = mw.ustring.gsub(it, "^([^%(]+)%s%(([^%d]+)%)$", "%1-%2")       if not lcIt then lcIt = it end

lcIt = mw.ustring.gsub(mw.ustring.lower(lcIt), "'", "")

itemsFile = itemsFile .. space .. "[[File:"                   .. prefix                    .. "-"                    .. lcIt                    .. ".png|x"                    .. size                    .. "px|link="                    .. it        if suffix and suffix ~= "" then            itemsFile = itemsFile .. " " .. suffix        end

itemsFile = itemsFile .. "]]"

space = " " end

-- replace back any ! (delimiter) changed earlier itemsFile = mw.ustring.gsub(itemsFile, "%^", "!")

return itemsFile end

return p