Для документации этого модуля может быть создана страница Модуль:Color/doc
local p = {}
function p.colors( f )
local args = f:getParent().args
local colorCodes = mw.loadData( 'Module:Color/codes' )
local colorIds = mw.loadData( 'Module:Color/ids' )
local colorBlocks = {}
local colorNames = {}
local size = 20
local colorName = ''
--This slices one parameter into a variable number of parameters with a comma as a delimiter.
--This allows the list to be called into another Template as its own parameter.
local M_SLICES = {}
for part in string.gmatch((args[1])..',', "([^,]*),") do
table.insert(M_SLICES,part:match "^%s*(.-)%s*$")
end
for i,color in ipairs(M_SLICES) do
colorName = color:gsub('%W',''):lower()
colorId = 'No ID'
if colorIds[colorName] ~= nil then
colorId = colorIds[colorName]
end
if colorCodes[colorName]~= nil then
table.insert(colorBlocks,'<div style="height:'..size..'px; width:'..size..'px; background:'..colorCodes[colorName]..'; margin:1px; border:1px solid black;" title="'..color..' ('..colorId..')"></div>')
end
end
return '<div style="display:flex; flex-wrap:wrap; justify-content:center; width:200px; padding-bottom:10px; padding-top:10px; margin:-1px;">'..table.concat(colorBlocks)..'</div>'
end
return p