Module:ItemList

local p = {} function p.itemlist( f ) local args = f:getParent.args

local listtype, extrastyle = 'ul', '' local iconsize = args.iconsize or '30px' local showOne = args.showQuantityOne or false local asPerCent = args.showQuantityAsPerCent or false

if args.columns ~= nil then extrastyle = extrastyle..'column-count:'..args.columns..';' end

if args.columnWidth ~= nil then extrastyle = extrastyle..'column-width:'..args.columnWidth..';' end

if args.marginLeft ~= nil then extrastyle = extrastyle..'margin-left:'..args.marginLeft..';' end

if args.listtype ~= nil then if args.listtype == 'ol' then listtype = 'ol' else -- none extrastyle = extrastyle..'list-style:none;' end end

-- for data from module:dv local Dv, M_ITEM = {}, {} for part in string.gmatch((args[1])..',', "([^,]*),") do   table.insert(Dv,part) end

-- if there is only one item anyway, proceed normally, else take the csv-list, converted to a table if Dv[2] == nil then M_ITEM = args else M_ITEM = Dv end

-- read arguments list into itemList (consists of tables, at index 1 is the text, at index 2 the quantity (optional)) local itemList, i, lastItem = {}, 0, nil for _, item in ipairs(M_ITEM) do   item = item:match "^%s*(.-)%s*$" -- trim

if string.len(item) > 0 then if lastItem and (item:match "^[%d.]*$" or item:match "^[%d.]*%-[%d.]*$") then if asPerCent then itemList[i][2] = item * 100 -- item is per cent value elseif item ~= '1' or showOne then itemList[i][2] = item -- item is quantity end lastItem = nil else table.insert(itemList, {item, nil} ) -- item is text i = i + 1 lastItem = item end end end

-- output itemList local output = {} local quantitySign = asPerCent and '% ' or ' × ' for _, item in ipairs(itemList) do   table.insert(output, ''..(item[2] ~= nil and item[2]..quantitySign or '')..' '..item[1]..'') end

-- if the list is long and has no explicit style, break it into columns automatically if #output > 5 and extrastyle == '' then extrastyle = 'column-width:15em;' end

return '<'..listtype..(extrastyle ~=  and ' style="'..extrastyle..'"' or )..'>'..table.concat(output, '')..'' end

return p