Module:Module sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Restored revision 1218887761 by Thisasia (talk)
Tags: Twinkle Undo Reverted Mobile edit Mobile web edit Advanced mobile edit
Restored revision 1218888011 by Thisasia (talk)
Tags: Twinkle Undo Reverted Mobile edit Mobile web edit Advanced mobile edit
Line 4: Line 4:
local args = frame:getParent().args
local args = frame:getParent().args
local output = '{| class="infobox biography vcard" style="width: 22em;"\n'
local output = '{| class="infobox biography vcard" style="width: 22em;"\n'
local descriptions = {}
local newParameters = {}
local firstDescriptionFound = false
local firstDescriptionFound = false
for key, value in pairs(args) do
for key, value in pairs(args) do
if not firstDescriptionFound and key:sub(1, 11) == 'description' then
if key:sub(1, 11) == 'description' then
if value ~= "" then
if value ~= "" then
if not firstDescriptionFound then
output = output .. '| style="text-align: center; background-color: ' .. (args.descriptionbgcolor or "#f2f2f2") .. '; color: ' .. (args.descriptioncolor or "inherit") .. '; font-weight: bold;" | ' .. value .. '\n|-\n'
firstDescriptionFound = true
table.insert(descriptions, value)
firstDescriptionFound = true
else
table.insert(newParameters, '| style="text-align: center; background-color: ' .. (args.descriptionbgcolor or "#f2f2f2") .. '; color: ' .. (args.descriptioncolor or "inherit") .. '; font-weight: bold;" | ' .. value .. '\n|-\n')
end
end
end
elseif key == 'image' then
if value ~= "" then
local imgc = args.imgc or ""
local imagesize = args.imagesize or ""
output = output .. '|' ..'<div style="text-align:center;">'.. value .. '</div>'..'<small style="display: block; text-align: center;">' .. imgc .. '</small>\n|-\n'
end
else
table.insert(newParameters, '| <b>' .. key .. '</b>\n| ' .. value .. '\n|-\n')
end
end
end
end
for _, description in ipairs(descriptions) do
if args.image then
output = output .. '| style="text-align: center; background-color: ' .. (args.descriptionbgcolor or "#f2f2f2") .. '; color: ' .. (args.descriptioncolor or "inherit") .. '; font-weight: bold;" | ' .. description .. '\n|-\n'
local imgc = args.imgc or ""
local imagesize = args.imagesize or ""
output = output .. '|' ..'<div style="text-align:center;">'.. args.image.. '</div>'..'<small style="display: block; text-align: center;">' .. imgc .. '</small>\n|-\n'
end
end
for _, parameter in ipairs(newParameters) do
if firstDescriptionFound then
for key, value in pairs(args) do
output = output .. parameter
if key:sub(1, 11) == 'description' and key ~= 'description' and key ~= 'descriptionbgcolor' and key ~= 'descriptioncolor' then
if value ~= "" then
output = output .. '| style="text-align: center; background-color: ' .. (args.descriptionbgcolor or "#f2f2f2") .. '; color: ' .. (args.descriptioncolor or "inherit") .. '; font-weight: bold;" | ' .. value .. '\n|-\n'
end
end
end
for key, value in pairs(args) do
if key ~= 'image' and key ~= 'imagecaption' and key ~= 'imgc' and key ~= 'imagesize' then
if key:sub(1, 11) ~= 'description' then
output = output .. '| <b>' .. key .. '</b>\n| ' .. value .. '\n|-\n'
end
end
end
end
end

Revision as of 13:21, 14 April 2024

local p = {}

function p.infobox(frame)
    local args = frame:getParent().args
    local output = '{| class="infobox biography vcard" style="width: 22em;"\n'
    local descriptions = {}
    local newParameters = {}
    local firstDescriptionFound = false
    
    for key, value in pairs(args) do
        if key:sub(1, 11) == 'description' then
            if value ~= "" then
                if not firstDescriptionFound then
                    table.insert(descriptions, value)
                    firstDescriptionFound = true
                else
                    table.insert(newParameters, '| style="text-align: center; background-color: ' .. (args.descriptionbgcolor or "#f2f2f2") .. '; color: ' .. (args.descriptioncolor or "inherit") .. '; font-weight: bold;" | ' .. value .. '\n|-\n')
                end
            end
        elseif key == 'image' then
            if value ~= "" then
                local imgc = args.imgc or ""
                local imagesize = args.imagesize or ""  
                output = output .. '|' ..'<div style="text-align:center;">'.. value .. '</div>'..'<small style="display: block; text-align: center;">' .. imgc .. '</small>\n|-\n'
            end
        else
            table.insert(newParameters, '| <b>' .. key .. '</b>\n| ' .. value .. '\n|-\n')
        end
    end
    
    for _, description in ipairs(descriptions) do
        output = output .. '| style="text-align: center; background-color: ' .. (args.descriptionbgcolor or "#f2f2f2") .. '; color: ' .. (args.descriptioncolor or "inherit") .. '; font-weight: bold;" | ' .. description .. '\n|-\n'
    end
    
    for _, parameter in ipairs(newParameters) do
        output = output .. parameter
    end
    
    output = output .. '|}\n'
    
    return output
end

return p