Модуль:Sandbox/Антрактидов
Для документации этого модуля может быть создана страница Модуль:Sandbox/Антрактидов/Документация
local p = {}
local trim = mw.text.trim
local function getCommaSeparatedList(list)
local output = {}
local _tbl = mw.text.split((list or ''), ',')
for _, val in ipairs(_tbl) do
local temp = trim(val)
if temp ~= '' then
output[#output + 1] = trim(val)
end
end
return output or {}
end
function p.drawTable(frame)
local args = frame.args
local pArgs = frame:getParent().args
local classes = args.class or 'wikitable'
local styles = args.style or ''
local output = { '<table class="' .. classes .. '" style="' .. styles .. '">' }
-- create table header
local tableHeader = '<tr><th>' .. (args['+'] or '') .. '</th>'
for _, val in ipairs(getCommaSeparatedList(args.cols)) do
tableHeader = tableHeader .. '<th>' .. (args[val] or val) .. '</th>'
end
output[#output + 1] = tableHeader .. '</tr>'
for _, rowName in ipairs(getCommaSeparatedList(args.rows)) do
local newRow = '<tr><th>' .. (args[rowName] or rowName) .. '</th>'
for _, colName in ipairs(getCommaSeparatedList(args.cols)) do
local paramName = rowName .. '_' .. colName
newRow = newRow .. '<td>' .. (pArgs[paramName] or '{{{' .. paramName .. '}}}') .. '</td>'
end
output[#output + 1] = newRow .. '</tr>'
end
output[#output + 1] = '</table>'
return table.concat(output, '\n')
end
return p