918
edits
(Currency: Implement for currency templates; _Currency: Add category to output for non-numeric amount arguments) |
No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 850: | Line 850: | ||
function p._Currency(fileName, link, altText, amount, maxAmount) | function p._Currency(fileName, link, altText, amount, maxAmount) | ||
local | local function numColour(amount) | ||
if tonumber(amount) < 0 then | |||
local | return mw.html.create('span') | ||
:css('color', 'red') | |||
:wikitext(formatnum(amount)) | |||
:done() | |||
else | |||
return formatnum(amount) | |||
end | |||
end | |||
local html = mw.html.create('span') | |||
:addClass('img-text') | |||
-- Currency amounts | -- Currency amounts | ||
if tonumber(amount) ~= nil then | if tonumber(amount) ~= nil then | ||
local text = mw.html.create('span') | |||
:css('margin-right', '0.2em') | |||
:node(numColour(amount)) | |||
if (tonumber(maxAmount) ~= nil and maxAmount > amount) then | if (tonumber(maxAmount) ~= nil and maxAmount > amount) then | ||
text:wikitext(' - ' .. numColour(maxAmount)) | |||
end | end | ||
html:node(text:done()) | |||
end | end | ||
-- Currency icon | -- Currency icon | ||
if fileName ~= nil then | if fileName ~= nil then | ||
html:wikitext('[[File:'):wikitext(fileName):wikitext('|25px') | |||
if link ~= nil then | if link ~= nil then | ||
html:wikitext('|link='):wikitext(link) | |||
end | end | ||
html:wikitext('|alt=') | |||
:wikitext(((altText == nil and '') or altText)) | |||
:wikitext(']]') | |||
end | end | ||
html:done() | |||
if ((amount ~= nil and tonumber(amount) == nil) | if ((amount ~= nil and tonumber(amount) == nil) | ||
or (maxAmount ~= nil and tonumber(maxAmount) == nil)) then | or (maxAmount ~= nil and tonumber(maxAmount) == nil)) then | ||
html:wikitext('[[Category:Pages with non-numeric currency arguments]]') | |||
end | end | ||
return | return tostring(html) | ||
end | end | ||
Line 904: | Line 913: | ||
local currID, minVal, maxVal, _ | local currID, minVal, maxVal, _ | ||
currID = args[1] | currID = args[1] | ||
if args[2] ~= nil then | if args[2] ~= nil and args[2] ~= '' then | ||
minVal, _ = string.gsub(args[2], ',', '') | minVal, _ = string.gsub(args[2], ',', '') | ||
end | end | ||
if args[3] ~= nil then | if args[3] ~= nil and args[3] ~= '' then | ||
maxVal, _ = string.gsub(args[3], ',', '') | maxVal, _ = string.gsub(args[3], ',', '') | ||
end | end |
edits