Module:Color: Difference between revisions
From Zelda Wiki, the Zelda encyclopedia
no edit summary
PhantomCaleb (talk | contribs) No edit summary |
PhantomCaleb (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local h = {} | |||
local | local utilsPackage = require("Module:UtilsPackage") | ||
local utilsString = require("Module:UtilsString") | local utilsString = require("Module:UtilsString") | ||
local _utilsArg = utilsPackage.lazyLoad("Module:UtilsArg") | |||
local _utilsError = utilsPackage.lazyLoad("Module:UtilsError") | |||
local Constants = mw.loadData("Module:Constants/Data") | local Constants = mw.loadData("Module:Constants/Data") | ||
Line 25: | Line 27: | ||
-- @return any error categories as a string, or nil | -- @return any error categories as a string, or nil | ||
function p.color(colorId, text) | function p.color(colorId, text) | ||
if text == nil or text == "" then | if text == nil or text == "" then | ||
h.warn("<code>text</code> parameter is required.") | |||
return text or "", CAT_INVALID_ARGS | return text or "", CAT_INVALID_ARGS | ||
end | end | ||
if colorId == nil or colorId == "" then | if colorId == nil or colorId == "" then | ||
h.warn("<code>color</code> parameter is required.") | |||
return text, CAT_INVALID_ARGS | return text, CAT_INVALID_ARGS | ||
end | end | ||
if string.find(colorId, "\n", 1, true) or string.find(colorId, "\r", 1, true) or utilsString.startsWith(colorId, " ") or utilsString.endsWith(colorId, " ") then | if string.find(colorId, "\n", 1, true) or string.find(colorId, "\r", 1, true) or utilsString.startsWith(colorId, " ") or utilsString.endsWith(colorId, " ") then | ||
h.warn("<code>color</code> argument contains invalid whitespace such as newlines or leading/trailing spaces.") | |||
return text, CAT_INVALID_ARGS | return text, CAT_INVALID_ARGS | ||
end | end | ||
Line 47: | Line 42: | ||
local colorData = data.colors[colorId] | local colorData = data.colors[colorId] | ||
if colorData == nil then | if colorData == nil then | ||
h.invalidColor(colorId) | |||
return text, CAT_INVALID_COLOR | return text, CAT_INVALID_COLOR | ||
end | end | ||
Line 74: | Line 69: | ||
action = "See [[Template:Color]] for a list of supported colors." | action = "See [[Template:Color]] for a list of supported colors." | ||
end | end | ||
h.warn(string.format("Color <code>%s</code> is being discontinued. %s", colorId, action)) | |||
return result, CAT_INVALID_COLOR | return result, CAT_INVALID_COLOR | ||
end | end | ||
return result | return result | ||
end | |||
function h.invalidColor(colorId) | |||
h.warn(string.format("<code>%s</code> is not a valid color name. See [[Template:Color]] for a list of supported colors.", colorId)) | |||
_utilsArg().store({ | |||
module = "Module:Color", | |||
args = { | |||
[1] = colorId, | |||
[2] = text, | |||
} | |||
}) | |||
end | |||
function h.warn(msg) | |||
_utilsError().warn(msg) | |||
end | end | ||