Module:Icons: Difference between revisions

Undo revision 66451 by Auron956 (talk)
(_Currency: Conditional formatting for negative amounts, and refactor to avoid repeated string concatenation)
Tag: Reverted
(Undo revision 66451 by Auron956 (talk))
Tag: Undo
Line 843: Line 843:
end
end


function p._Currency(fileName, link, altText, amount, maxAmount)
function p._Currency(fileName, link, altText, amt, maxAmt)
local ret = {}
local amtText = nil
table.insert(ret, '<span style="display:inline-block">')
if tonumber(amt) ~= nil then
-- Currency icon
amtText = formatnum(amt)
if maxAmt ~= nil and maxAmt >= amt then
amtText = amtText .. ' - ' .. formatnum(maxAmt)
end
end
 
local fileText = ''
if fileName ~= nil then
if fileName ~= nil then
table.insert(ret, '[[File:' .. fileName .. '|25px')
fileText = '[[File:' .. fileName .. '|25px'
if link ~= nil then
if link ~= nil then
table.insert(ret, '|link=' .. link)
fileText = fileText .. '|link=' .. link
end
table.insert(ret, '|alt=' .. ((altText == nil and '') or altText) .. ']]')
end
-- Currency amounts
if tonumber(amount) ~= nil then
local function numColour(amount)
if amount < 0 then
return '<span style="color:red;">' .. formatnum(amount) .. '</span>'
else
return formatnum(amount)
end
end
table.insert(ret, '&nbsp;' .. numColour(amount))
if (tonumber(maxAmount) ~= nil and maxAmount > amount) then
table.insert(ret, ' - ' .. numColour(maxAmount))
end
end
fileText = fileText .. '|alt=' .. ((altText == nil and '') or altText) .. ']]'
end
end
table.insert(ret, '</span>')
 
return '<span style="display:inline-block">' .. fileText .. (amtText ~= nil and '&nbsp;' .. amtText or '') .. '</span>'
return table.concat(ret)
end
end