m (Maybe it's expanding before we see it...) |
m (\o/ Spam) |
||
Line 48: | Line 48: | ||
out = out .. thing .. "{{,}}" |
out = out .. thing .. "{{,}}" |
||
end |
end |
||
− | return string.sub(out, 1, -6) |
+ | return string.sub(out, 1, -6) .. args[1] |
end |
end |
||
Revision as of 00:09, 5 March 2016
Documentation for this module may be created at Module:NIA/doc
local p = {}
p.items = function( f )
local args = f.args or f
if f == mw.getCurrentFrame() and args[1] == nil then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local text = ""
for item in mw.text.gsplit(args[1], '%s*,%s*') do
text = text .. f:callParserFunction('#icon', {item = item, size = 16, mod = args.mod})
end
return text
end
function shuffle(list)
local indices = {}
for i = 1, #list do
indices[#indices+1] = i
end
local shuffled = {}
for i = 1, #list do
local index = math.random(#indices)
local value = list[indices[index]]
table.remove(indices, index)
shuffled[#shuffled+1] = value
end
return shuffled
end
p.rand = function(f)
local args = f.args or f
if f == mw.getCurrentFrame() and args[1] == nil then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
section = {}
for item in mw.text.gsplit(args[1], "{{NI|") do
item = item:gsub("{{,}}", ""):gsub("<!--.*-->", "")
if item ~= "" then
table.insert(section, "{{NI|" .. item)
end
end
out = ""
for i, thing in pairs(shuffle(section)) do
out = out .. thing .. "{{,}}"
end
return string.sub(out, 1, -6) .. args[1]
end
return p