Anonymous

Module:Color: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
no edit summary
No edit summary
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 utilsPackage = require("Module:UtilsPackage")
local utilsString = require("Module:UtilsString")
local utilsString = require("Module:UtilsString")
local _TransclusionArguments = utilsPackage.lazyLoad("Module:Transclusion Arguments")
local _utilsError = utilsPackage.lazyLoad("Module:UtilsError")


local data = mw.loadData("Module:Color/Data")
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 CAT_INVALID_ARGS = "[[Category:"..require("Module:Constants/category/invalidArgs").."]]"
function h.invalidColor(colorId)
local CAT_INVALID_COLOR = "[[Category:Articles Using Invalid Color Names]]"
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("colored-text")
: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
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))
-- 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 h.warn(msg)
_utilsError().warn(msg)
end
end


Line 329: Line 327:
{
{
args = {"TMC Blue", "guy in green tights"},
args = {"TMC Blue", "guy in green tights"},
expect = {'<span class="colored-text" style="color:#37acbe">guy in green tights</span>', nil},
expect = {'<span class="zw-color" style="color:#37acbe">guy in green tights</span>', nil},
},
},
{
{
args = {"notAColor", "foo"},
args = {"notAColor", "foo"},
expect = {"foo", "[[Category:Articles Using Invalid Color Names]]"},
expect = {"foo", "[[Category:Articles using invalid color names]]"},
},
},
},
},