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 |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local h = {} | local h = {} | ||
local data = mw.loadData("Module:Color/Data") | |||
local utilsString = require("Module:UtilsString") | local utilsString = require("Module:UtilsString") | ||
local | local CAT_INVALID_ARGS = "[[Category:"..require("Module:Constants/category/invalidArgs").."]]" | ||
local CAT_INVALID_COLOR = "[[Category:Articles using invalid color names]]" | |||
function h.warn(msg) | |||
local utilsError = require("Module:UtilsError") | |||
utilsError.warn(msg) | |||
end | |||
local | function h.invalidColor(colorId) | ||
local TransclusionArguments = require("Module:Transclusion Arguments") | |||
h.warn(string.format("<code>%s</code> is not a valid color name. See [[Template:Color]] for a list of supported colors.", colorId)) | |||
-- We only store invalid colors for performance reasons | |||
-- Storing all template usages seems to break pages that use the template a lot | |||
TransclusionArguments.store({ | |||
module = "Module:Color", | |||
args = { | |||
[1] = colorId, | |||
[2] = text, | |||
}, | |||
isValid = false, | |||
}) | |||
end | |||
function p.Main(frame) | function p.Main(frame) | ||
Line 46: | Line 62: | ||
local colorValue = colorData.color | local colorValue = colorData.color | ||
local html = mw.html.create("span") | local html = mw.html.create("span") | ||
:addClass(" | :addClass("zw-color") | ||
:wikitext(text) | :wikitext(text) | ||
if utilsString.startsWith(colorValue, "linear-gradient") then | if utilsString.startsWith(colorValue, "linear-gradient") then | ||
Line 72: | Line 88: | ||
end | end | ||
return result | return result | ||
end | end | ||
Line 329: | Line 327: | ||
{ | { | ||
args = {"TMC Blue", "guy in green tights"}, | args = {"TMC Blue", "guy in green tights"}, | ||
expect = {'<span class=" | expect = {'<span class="zw-color" style="color:#37acbe">guy in green tights</span>', nil}, | ||
}, | }, | ||
{ | { | ||
args = {"notAColor", "foo"}, | args = {"notAColor", "foo"}, | ||
expect = {"foo", "[[Category:Articles | expect = {"foo", "[[Category:Articles using invalid color names]]"}, | ||
}, | }, | ||
}, | }, |