Module:Topic display box

local p = {}

-- function to output the appropriate icon for each article local function icon(code, px) local image, blank if code == "FA" then image = "" elseif code == "GA" then image = "" elseif code == "CA" then image = "" elseif code == "FFA" then image = "" elseif code == "FGA" then image = "" elseif code == "FCA" then image = "" else image = "" blank = true end return image:format(px), blank end

-- primary function called by template function p.main(frame) -- obtain parameters from template call local pframe = frame:getParent local args = pframe.args -- initialize main variables from parameters local topictype = (args.type or ""):upper                                -- topic type local title = args.title or ""                                             -- topic title local titlestatus = (args.titlestatus or ""):upper                       -- status of title article local fullcategory = (args.fullcategory ~= "") and args.fullcategory or nil -- category for full list of possible articles local statuslist = {}                                                      -- table that will contain list of statuses local articlelist = {}                                                     -- table that will contain list of articles -- process unnamed parameters, which alternate between status and article for n, value in ipairs(args) do		if n % 2 == 1 then statuslist[#statuslist + 1] = value:upper else articlelist[#articlelist + 1] = value end end -- declare variable that will contain background color local bgcolor -- determines background color based on topictype if topictype == "FT" then bgcolor = "FAFAD2" elseif topictype == "GT" then bgcolor = "ADDFAD" elseif topictype == "CT" then bgcolor = "FAB09E" else bgcolor = "FFFFFF" -- default to white if topictype is unrecognized end -- declare variable that will contain status icon for title of box local titleicon, nostatus = icon(titlestatus, 20, "") if nostatus then titleicon = "" end

-- declare variable that will contain list of lines to be used in creating the finished product local lines = {} -- combine statuslist entries with the corresponding articlelist entries, calling articleicon function to convert code into image for n, article in ipairs(articlelist) do		lines[#lines + 1] = string.format("%s %s", icon(statuslist[n], 15), article) end -- if a category is provided, add an extra line with the category link if fullcategory then lines[#lines + 1] = string.format("(Full list of possible articles)", fullcategory) end -- declare variables that will contain number and width of columns, respectively local columns, colwidth -- set number/width of columns, width is expressed as a percentage if #lines == 1 then columns, colwidth = 1, 100 elseif #lines < 7 then columns, colwidth = 2, 50 else columns, colwidth = 3, 33 end -- calculate number of lines per column (last column may be up to two short) local lpc = math.ceil(#lines / columns) -- now the real work begins -- build finished product local ret = {} ret[#ret + 1] = string.format('' ret[#ret + 1] = string.format("\n %s %s  ", titleicon, title) ret[#ret + 1] = '\n \n{| style="width: 100%; background: none;"' for c = 1, columns do		if c == 3 then colwidth = 34 end -- add cell styling for each column ret[#ret + 1] = string.format('\n| style="vertical-align: top; text-align: left; width: %d%%" | ', colwidth) -- calculates what line to start current column at, based on column number (c) local columnstart = lpc * (c - 1) + 1 -- calculates what line to end current column at		local columnend = math.min(lpc * c, #lines) -- build column; each "line" begins with a unless it is the first of the column for line = columnstart, columnend do			if line == columnstart then ret[#ret + 1] = lines[line] else ret[#ret + 1] = " " .. lines[line] end end end ret[#ret + 1] = "\n|}\n " return table.concat(ret) end

return p