Module:Flex: Difference between revisions
Appearance
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 | -- Collect all numeric positional arguments | ||
local item = args[ | 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>') | ||
end | end | ||
end | end | ||
Latest revision as of 14:01, 12 October 2026
| Main | Usage |
The documentation for this module is missing. Click here to create it.
local p = {}
function p.main(frame)
local args = frame:getParent().args
local items = {}
-- Collect all numeric positional arguments
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
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