Jump to content

Module:Alert list

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Harej (talk | contribs) at 20:18, 28 April 2023 (Smaller icon). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

local function renderNotification(args, index)
    local icon = args['icon' .. index]
    local label = args['label' .. index]
    local msg = args['msg' .. index]
    local action = args['action' .. index]
    local time = args['time' .. index]

    if not icon or not label then
        return ''
    end

    local notification = {
        '* [[File:' .. icon .. "|18px|link=]] '''" .. label .. "'''",
    }

    if msg and msg ~= '' then
        table.insert(notification, '*: ' .. msg)
    end

    if action and action ~= '' then
        table.insert(notification, '*: ' .. action)
    end
    
    if time and time ~= '' then
        table.insert(notification, '*: <small>' .. time .. '</small>')
    end

    return table.concat(notification, '\n')
end

function p.main(frame)
    local args = frame:getParent().args
    local output = {}

    for i = 1, math.huge do
        local notification = renderNotification(args, i)

        if notification == '' then
            break
        end

        table.insert(output, notification)
    end

    return table.concat(output, '\n')
end

return p