Module:Weakness clickpic
Documentation for this module may be created at Module:Weakness clickpic/doc
-- <pre>
local p = {}
local onmain = require('Module:Mainonly').on_main
local yesno = require('Module:Yesno')
local weaknesses = mw.loadData('Module:Weakness clickpic/data')
function p.main(frame)
local args = frame:getParent().args
local split_list = mw.text.split(args[1],',')
local addcats = yesno(args.cg)
local noText = yesno(args.notext)
-- iterate through and create a parameters
-- look at only the first word for weaknesses
local params = {}
for i, v in ipairs(split_list) do
v = mw.text.trim(v)
:lower()
:gsub('(%w+)%s.*','%1')
:gsub('[][]','')
table.insert(params, v)
end
return p._main(params,addcats,noText)
end
function p.bestiary(frame)
local args = frame:getParent().args
local split_list = mw.text.split(args[1],',')
local addcats = yesno(args.cg)
local noText = yesno(args.notext)
-- iterate through and create a parameters
-- look at only the first word for weaknesses
local params = {}
for i, v in ipairs(split_list) do
v = mw.text.trim(v)
:lower()
:gsub('(%w+)%s.*','%1')
:gsub('[][]','')
table.insert(params, v)
end
return p._main(params,addcats,true)
end
function p._main(wargs,addcats,noText)
-- Create a list of good and bad args
local good_args = {}
local bad_args = {}
-- Return string
local ret = ''
-- Category list
local cats = ''
for i, v in ipairs(wargs) do
local weakns = weaknesses[v]
if weakns then
table.insert(good_args, weakns)
else
table.insert(bad_args, v)
end
end
for i, v in ipairs(good_args) do
if noText then
image = '[[File:'..v.image..'|link=' .. (v.link or '') .. '|x28px]]'
ret = ret..image
else
image = '[[File:'..v.image..'|link=' .. (v.link or '') .. '|x28px]]'
local link
if v.link then
if v.text then
link = '[['..v.link..'|'..v.text..']]'
else
link = '[['..v.link..']]'
end
else
link = v.text
end
ret = ret..image..' '..link
end
if (i < #good_args + #bad_args) then
ret = ret..'<br>'
end
if onmain() and addcats then
if v.category then
cats = cats..'[[Category:'..v.category..']]'
end
end
end
if #bad_args > 0 then
local bad_list = ''
for i, v in ipairs(bad_args) do
bad_list = bad_list .. '"' .. v .. '"'
if i < #bad_args then
bad_list = bad_list..', '
end
end
ret = ret..'<strong class="error" title="One or more weaknesses not recognised: '..bad_list..'">Bad argument</strong>'
if onmain() then
ret = ret..'[[Category:Erroneous parameter]]'
end
end
return ret..cats
end
return p