Module:icons: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 5: | Line 5: | ||
local title = mw.title.new(args[1]) | local title = mw.title.new(args[1]) | ||
local text = title:getContent() | local text = title:getContent() | ||
local games = text and p.extractGames(text) or | local games = text and p.extractGames(text) or "" | ||
local text = {} | local text = {} | ||
local games2 = { "iii", "vc", "sa", "iv" } | local games2 = { "iii", "vc", "sa", "iv" } | ||
local data | local data | ||
games = games:lower() | |||
for i,game in ipairs(games2) do | for i,game in ipairs(games2) do | ||
if | if games:find(game:lower(), 1, false) then | ||
data = frame:expandTemplate{title = "icon-"..game} | data = frame:expandTemplate{title = "icon-"..game} | ||
else | else | ||
| Line 33: | Line 34: | ||
local games = text:match("|%s*games%s*=%s*([^|]+)") | local games = text:match("|%s*games%s*=%s*([^|]+)") | ||
if not games then | if not games then | ||
return | return "iii vc sa iv" | ||
end | end | ||
return games:match("^%s*(.-)%s*$") -- trim | |||
end | end | ||
Latest revision as of 14:52, 9 June 2026
Documentation for this module may be created at Module:icons/doc
local p = {}
function p.main(frame)
local args = p.getArgs(frame)
local title = mw.title.new(args[1])
local text = title:getContent()
local games = text and p.extractGames(text) or ""
local text = {}
local games2 = { "iii", "vc", "sa", "iv" }
local data
games = games:lower()
for i,game in ipairs(games2) do
if games:find(game:lower(), 1, false) then
data = frame:expandTemplate{title = "icon-"..game}
else
data = frame:expandTemplate{title = "icon-placeholder"}
end
table.insert(text, data)
end
return table.concat(text, " ")
end
function p.getArgs(frame)
if p.argsCache then
return p.argsCache
else
local args = frame:getParent().args
p.argsCache = args
return args
end
end
function p.extractGames(text)
local games = text:match("|%s*games%s*=%s*([^|]+)")
if not games then
return "iii vc sa iv"
end
return games:match("^%s*(.-)%s*$") -- trim
end
function p.inArray(array, value)
for i,v in ipairs(array) do
if v == value then
return true
end
end
return false
end
return p