Module:Infobox sort
Appearance
local p = {}
function p.asc(frame)
local list = {}
for key,value in pairs(frame.args) do
-- Remove newlines
local stripped = mw.text.trim((string.gsub(value, "\n", "")))
if stripped:match("%S") ~= nil then
table.insert(list, stripped)
end
end
table.sort( list, function (a, b)
local indexA = a:find("%%")
local indexB = b:find("%%")
local numberA = tonumber(a:sub(1, indexA - 1))
local numberB = tonumber(b:sub(1, indexB - 1))
return numberA < numberB
end )
return mw.text.trim(table.concat( list, "<br>" ))
end
function p.desc(frame)
local list = {}
for key,value in pairs(frame.args) do
-- Remove newlines
local stripped = mw.text.trim((string.gsub(value, "\n", "")))
if stripped:match("%S") ~= nil then
table.insert(list, stripped)
end
end
table.sort( list, function (a, b)
local indexA = a:find("%%")
local indexB = b:find("%%")
local numberA = tonumber(a:sub(1, indexA - 1))
local numberB = tonumber(b:sub(1, indexB - 1))
return numberA > numberB
end )
return mw.text.trim(table.concat( list, "<br>" ))
end
return p