FANDOM


local p = {}
function p.itemlist( f )
  local dlclink = require('Module:DLCLink').link
  local args = f:getParent().args
  local itemList, iconsize, columns, indent, listindent, itemicon = {}, '30px', 1, 0, 0, '*'
 
  if args.iconsize ~= nil then
    iconsize = args.iconsize
  end
  if args.columns ~= nil then
    columns = args.columns
  end
  if args.listindent ~= nil then
    listindent = args.listindent
  end
  if args.itemicon ~= nil then
    if args.itemicon == 'none' then
      itemicon = ':'
    else
      itemicon = '#'
    end
  end
 
  local Dv = {}
    for part in string.gmatch((args[1])..',', "([^,]*),") do
      table.insert(Dv,part:match "^%s*(.-)%s*$")
    end
 
  if Dv[2] == nil then
      M_ITEM = args
    else
      M_ITEM = Dv
  end
 
  for _,item in ipairs(M_ITEM) do
    -- get indentation
    indent = 0
    item = item:match "^%s*(.-)%s*$" -- trim
    while string.sub(item,1,1) == '*' do
      item = string.sub(item,2)
      indent = indent + 1
    end
    if string.len(item)>0 then
      table.insert(itemList, string.rep(itemicon,indent)..itemicon..' [[File:'..item..'.png|'..iconsize..']] '..dlclink(item))
    end
  end
  return '<div style="column-count:'..columns..';-moz-column-count:'..columns..';-webkit-column-count:'..columns..';margin-left:'..1.6*listindent..'em">\n'..table.concat(itemList, '\n')..'\n</div>'
end
 
return p