Module:Flex: Difference between revisions

ReisuDesign (talk | contribs)
Created page with " local p = {} function p.main(frame) local args = frame:getParent().args local items = {} for i = 1, #args do local item = args[i] if item and mw.text.trim(item) ~= "" then table.insert(items, '<div>' .. item .. '</div>' ) end end return '<div style="display:flex; column-gap:15px; flex-direction:row; flex-wrap:wrap;">' .. table.concat(items) .. '</div>' end return p"
 
ReisuDesign (talk | contribs)
No edit summary
 
Line 6: Line 6:
     local items = {}
     local items = {}


     for i = 1, #args do
    -- Collect all numeric positional arguments
         local item = args[i]
    local keys = {}
 
     for key, _ in pairs(args) do
        local index = tonumber(key)
 
        if index and index > 0 and index % 1 == 0 then
            table.insert(keys, index)
        end
    end
 
    -- Keep items in their original positional order
    table.sort(keys)
 
    for _, index in ipairs(keys) do
         local item = args[index]


         if item and mw.text.trim(item) ~= "" then
         if item and mw.text.trim(item) ~= "" then
             table.insert(items,
             table.insert(items, '<div>' .. item .. '</div>')
                '<div>' .. item .. '</div>'
            )
         end
         end
     end
     end