17,101
edits
mNo edit summary |
(_Currency: Conditional formatting for negative amounts, and refactor to avoid repeated string concatenation) Tag: Reverted |
||
Line 843: | Line 843: | ||
end | end | ||
function p._Currency(fileName, link, altText, | function p._Currency(fileName, link, altText, amount, maxAmount) | ||
local | local ret = {} | ||
table.insert(ret, '<span style="display:inline-block">') | |||
-- Currency icon | |||
if | if fileName ~= nil then | ||
table.insert(ret, '[[File:' .. fileName .. '|25px') | |||
if link ~= nil then | |||
table.insert(ret, '|link=' .. link) | |||
end | end | ||
table.insert(ret, '|alt=' .. ((altText == nil and '') or altText) .. ']]') | |||
end | end | ||
-- Currency amounts | |||
if tonumber(amount) ~= nil then | |||
if | local function numColour(amount) | ||
if amount < 0 then | |||
if | return '<span style="color:red;">' .. formatnum(amount) .. '</span>' | ||
else | |||
return formatnum(amount) | |||
end | |||
end | |||
table.insert(ret, ' ' .. numColour(amount)) | |||
if (tonumber(maxAmount) ~= nil and maxAmount > amount) then | |||
table.insert(ret, ' - ' .. numColour(maxAmount)) | |||
end | end | ||
end | end | ||
table.insert(ret, '</span>') | |||
return table.concat(ret) | |||
end | end | ||