Module:MInfobox

From Infinitypedia
Jump to navigation Jump to search

Documentation for this module may be created at Module:MInfobox/doc

p = {}

function p.DataTable(f)
  class = mw.text.trim(tostring(f.args['class']))

  bTag = '<table class="MInfoboxDataTable %s">'
  mTag = '<tr class="MInfoboxDataTable %s"><th class="MInfoboxDataTable %s">%s</th><td class="MInfoboxDataTable %s">%s</td></tr>'
  eTag = '</table>'

  str = string.format(bTag, class)
  tableHasData = false

  n = 1
  while f.args[n] ~= nil do
    header = mw.text.trim(tostring(f.args[n]))
    data = mw.text.trim(tostring(f.args[n + 1]))

    if data ~= '' then
      str = str .. string.format(mTag,class,class,header,class,data)
      tableHasData = true
    end

    n = n + 2
  end

  str = str .. eTag

  if tableHasData then
    return str
  else
    return ''
  end
end

return p