Module:Year list

From Soyjak Wiki, the free ensoyclopedia
Jump to navigationJump to search

local p = {}

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

    -- Image (optional)
    if args.image and args.image ~= "" then
        table.insert(out, string.format('[[File:%s|125px|right]]', args.image))
    end

    -- Collect year entries
    local years = {}

    for k, v in pairs(args) do
        local year = tonumber(k)
        if year and v and v ~= "" then
            table.insert(years, year)
        end
    end

    table.sort(years)

    for _, year in ipairs(years) do
        table.insert(out, string.format('* %d - %s', year, args[tostring(year)]))
    end

    return table.concat(out, "\n")
end

return p