Module:IconList

From The Deadlock Wiki
Jump to navigation Jump to search

Parses a comma-separated list of names and converts them into icons using Module:Icon.

{{#invoke:IconList|parse|INPUT_LIST|SIZE}}

Functions

[edit source]
  • parse|INPUT_LIST|SIZE
    • Splits a comma-separated string of names and renders them as a row of icons.
    • INPUT_LIST: A list of names separated by commas (e.g., "Abrams, Bebop").
    • SIZE (Optional): The size of the icons (e.g., "35px"). Defaults to 35px.

Example

[edit source]

To generate a list of heroes:

{{#invoke:IconList|parse|Abrams, Bebop, Seven}}

and it would return:

To change the size to 50px:

{{#invoke:IconList|parse|Abrams, Bebop, Seven|50px}}

and it would return:


local p = {}
local Icon = require('Module:Icon') 

function p.parse(frame)
    local input = frame.args[1] or ""
    local size = frame.args[2] or "35px"
    
    if input == "" then return "" end
    
    local result = {}
    -- Split by comma
    for item in string.gmatch(input, '([^,]+)') do
        -- Trim whitespace
        item = item:match("^%s*(.-)%s*$")
        
        -- Create a fake frame to pass to the existing Icon module
        local fakeFrame = { getParent = function() return { args = { item, size, "icon-only" } } end }
        table.insert(result, Icon.render(fakeFrame))
    end
    
    return table.concat(result, " ")
end
return p