Module:Infobox: Difference between revisions

ArrowHead294 (talk | contribs)
mNo edit summary
Ganaram inukshuk (talk | contribs)
Added skeleton code for invokable infobox; should not affect existing build functions
Line 1: Line 1:
local getArgs = require("Module:Arguments").getArgs
local p = {}
local p = {}


--------------------------------------------------------------------------------
------------------------------- HELPER FUNCTIONS -------------------------------
--------------------------------------------------------------------------------
function p.infobox_header(title, adjacent_links)
end
function p.infobox_row(row_content)
end
--------------------------------------------------------------------------------
-------------------------------- MAIN FUNCTIONS --------------------------------
--------------------------------------------------------------------------------
-- Function to be called by other modules; also called by wrapper function
function p._infobox(args)
end
-- Function to be #invoke'd
-- Wrapper function for template-based infoboxes
-- Modeled off of navbox
function p.infobox(frame)
local args = getArgs(frame)
-- Preprocess adjacent links
local adjacent_links = {}
local link_count = args["Link Count"] -- This is 0, 2, or 8
-- Preprocess rows
-- Set row count to 30; if more rows are needed, this can be changed or a
-- module can be written for that.
local rows = {}
for i = 1, 30 do
local header = args["Header " .. i]
local data  = args["Data "  .. i]
local row = nil
if (header ~= nil or data ~= nil) then
row = {
["Header"] = header,
["Data"] = ((header ~= nil and data == nil) and "" or data),
}
end
if row ~= nil then
table.insert(rows, row)
end
-- Remove original entries as cleanup
args["Header " .. i] = nil
args["Data "  .. i] = nil
end
args["Rows"] = rows
return p._navbox(args)
end
--------------------------------------------------------------------------------
------------------------------ EXISTING FUNCTIONS ------------------------------
--------------------------------------------------------------------------------
-- Original function; kept for supporting old navboxes
function p.build(title, entries, prev_link, next_link)
function p.build(title, entries, prev_link, next_link)
local s = "<div style=\""
local s = "<div style=\""