Module:Wjkinfobox

From Guild of Archivists

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

local p = {}
function p.mkinfobox(frame)

    local table2load = "Module:" .. frame.args[1]
    local dataxx = mw.loadData(table2load)
    local datax = {}
    if frame.args[2] ~= nil then
       for i,v in pairs( dataxx[frame.args[2]]) do
          datax[i] = v
       end
      else datax = dataxx
    end
    
 local count = 0
 for i,v in pairs( datax) do
   count = count + 1
  end
 local line = "<table class=infobox >"
 local replaceit = ""
 for i = 1, count do
    replaceit = datax[i]
    if replaceit == nil then break end
    if string.find(replaceit,"^@") == nil then
       replaceit = "@o" .. replaceit
    end
    replaceit = (string.gsub(replaceit,"^@t",'<tr><td colspan=\"2\" style=\"background:lightblue;width:230px;font-size:10pt;text-align:center;font-weight:bold;\">'))
    if string.find(replaceit,"^@i") ~= nil then
       if string.find(replaceit,"@l") ~= nil then
          replaceit = (string.gsub(replaceit,"@l",'|link='))
          if string.find(replaceit,"@c") ~= nil then
             replaceit = (string.gsub(replaceit,"@c",'|noframe|240px]]<br \/>'))
            else
             replaceit = (string.gsub(replaceit,"&","|noframe|240px]]"))              
            end -- END else if
         end -- END @l search
       if string.find(replaceit,"@c") ~= nil then
             replaceit = (string.gsub(replaceit,"@c",'|noframe|240px]]<br \/>'))
             replaceit = (string.gsub(replaceit,"^@i",'<tr><td colspan=\"2\" style=\"text-align:center;font-size:7pt\">[[Image:'))
        else
           replaceit = (string.gsub(replaceit,"^@i",'<tr><td colspan=\"2\" style=\"text-align:center;font-size:7pt\">[[Image:'))
           if string.find(replaceit,"]]&") ~= nil then
             replaceit = (string.gsub(replaceit,"$","]]"))
           end
         end -- END if else
       end -- END if
      if string.find(replaceit,"^@n") ~= nil then
        if string.find(replaceit,"@d") ~= nil then
           replaceit = (string.gsub(replaceit,"@d",'<\/td><td style=\"font-size:9pt;width:150px;\">'))
           replaceit = (string.gsub(replaceit,"^@n",'<tr><td style=\"font-size:9pt;font-weight:bold;;width:70px;\">'))
         else
           replaceit = (string.gsub(replaceit,"^@n",'<tr><td style=\"font-size:9pt;font-weight:bold;;width:70px;\">'))
         end -- END if else
       end -- END if
      if string.find(replaceit,"^@d") ~= nil then
          replaceit = (string.gsub(replaceit,"^@d",'<tr><td> <\/td><td style=\"font-size:9pt;width:150px;\">'))
       end -- END if
      if string.find(replaceit,"^@h") ~= nil then
          replaceit = (string.gsub(replaceit,"^@h",'<tr><td colspan=\"2\" style=\"background:lightblue;text-align:center;font-size:9pt;font-weight:bold; width:220px;\">'))
       end -- END if
      if string.find(replaceit,"^@s") ~= nil then
          replaceit = (string.gsub(replaceit,"^@s",'<tr><td colspan=\"2\" style=\"background:lightgreen;text-align:center;font-size:8pt;font-weight:bold; width:220px;\">'))
       end -- END if
      if string.find(replaceit,"^@o") ~= nil then
         replaceit = (string.gsub(replaceit,"^@o",'<tr><td colspan=\"2\" style=\"text-align:left; font-weight:bold; background:#FBEFF2; font-size:7pt;\"><hr>'))
         replaceit = (string.gsub(replaceit,"$","<hr>"))
        end -- END if
   replaceit = (string.gsub(replaceit,"&",'<\/td><\/tr>'))
   line = line .. replaceit
   end -- END for
  line = line .. "<\/table>"
  return line
end -- END FUNCTION MKINFOBOX
return p