Для документации этого модуля может быть создана страница Модуль: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 class="color-square" style="height:'..size..'px; width:'..size..'px; background:'..colorCodes[colorName]..';" title="'..color..' ('..colorId..')"></div>')
end
end
return '<div class="color-container">'..table.concat(colorBlocks)..'</div>'
end
return p