Module:Contacts
From The Obey Me Wiki
Description: Used to add card links/images within tables - desktop version
local cardList = {} function cardList.add(frame) -- iterate input into array local contact = {} for i = 1, 100 do contact[i] = frame:getParent().args[i] end local cardName = "" -- formats card name for i = 1, table.getn(contact) do cardName = contact[i] if string.find(cardName, "\n\n") then cardName = string.gsub(cardName, "\n\n", "") else cardName = string.gsub(cardName, "\n", "") end if string.find(cardName, " %(Casual%)") then contact[i] = "[[" .. cardName .. "|" .. string.gsub(cardName, " %(Casual%)", "<nowiki>%[Casual%]</nowiki>") .. "]]" elseif string.find(cardName, " %(Uniform%)") then contact[i] = "[[" .. cardName .. "|" .. string.gsub(cardName, " %(Uniform%)", "<nowiki>%[Uniform%]</nowiki>") .. "]]" else contact[i] = "[[" .. cardName .. "]]" end if string.find(cardName, "%(Pride%)") then contact[i] = "[[" .. cardName .. "|" .. string.sub(cardName, 1, string.find(cardName, "%(Pride%)") - 2) .. "]] [[File:Pride.png|10px]]" elseif string.find(cardName, "%(Greed%)") then contact[i] = "[[" .. cardName .. "|" .. string.sub(cardName, 1, string.find(cardName, "%(Greed%)") - 2) .. "]] [[File:Greed.png|10px]]" elseif string.find(cardName, "%(Envy%)") then contact[i] = "[[" .. cardName .. "|" .. string.sub(cardName, 1, string.find(cardName, "%(Envy%)") - 2) .. "]] [[File:Envy.png|10px]]" elseif string.find(cardName, "%(Wrath%)") then contact[i] = "[[" .. cardName .. "|" .. string.sub(cardName, 1, string.find(cardName, "%(Wrath%)") - 2) .. "]] [[File:Wrath.png|10px]]" elseif string.find(cardName, "%(Lust%)") then contact[i] = "[[" .. cardName .. "|" .. string.sub(cardName, 1, string.find(cardName, "%(Lust%)") - 2) .. "]] [[File:Lust.png|10px]]" elseif string.find(cardName, "%(Gluttony%)") then contact[i] = "[[" .. cardName .. "|" .. string.sub(cardName, 1, string.find(cardName, "%(Gluttony%)") - 2) .. "]] [[File:Gluttony.png|10px]]" elseif string.find(cardName, "%(Sloth%)") then contact[i] = "[[" .. cardName .. "|" .. string.sub(cardName, 1, string.find(cardName, "%(Sloth%)") - 2) .. "]] [[File:Sloth.png|10px]]" elseif string.find(cardName, " %(OM%)") then contact[i] = "[[" .. cardName .. "|" .. string.gsub(cardName, " %(OM%)", "") .. "]]" elseif string.find(cardName, " %(NB%)") then contact[i] = "[[" .. cardName .. "|" .. string.gsub(cardName, " %(NB%)", "") .. "]]" else contact[i] = "[[" .. cardName .. "]]" end end -- starts the table local html = '<div class="flex-container">\n' local imageName = '' -- starting from first element of the array for card = 1, table.getn(contact), 10 do -- opens a new row html = html .. "\n" -- iterates between 1~10 for count = 0, 9 do imageName = string.gsub(string.gsub(frame:getParent().args[card + count], ":", " -"), "?", " -") html = html .. "<div class=\"cardflex\"><span class=\"desktop-ver\"><small>[[File:" .. string.gsub(imageName, "\n", "") .. ".png|center|130px|class=cardimage|link=" .. string.gsub(frame:getParent().args[card + count], "\n", "") .. "]]</small></span>\n<span class=\"mobile-ver\"><small>[[File:" .. string.gsub(imageName, "\n", "") .. ".png|center|100px|class=cardimage|link=" .. string.gsub(frame:getParent().args[card + count], "\n", "") .. "]]</small></span>\n" .. contact[card + count] .. "</div>\n" if card + count + 1 > table.getn(contact) then break end end -- completes one row of card html = html .. "\n" end return html .. "</div>" end return cardList --[[File:{{{1}}}.png|center|class="cardlistimage"|link={{{1}}}]]