Module:Navbox: Difference between revisions

Ganaram inukshuk (talk | contribs)
refactor row contents from array to table of key-value pairs (again)
Ganaram inukshuk (talk | contribs)
m minor renaming
 
(14 intermediate revisions by the same user not shown)
Line 7: Line 7:
local p = {}
local p = {}


-- TODO (low priority): add an option for a dataless header row, to mirror the
-- TODO (medium priority): add/use navbox/styles.css
-- option of having a headerless data row. Requires changing row content from
-- a regular array to an associative array.


-- TODO (medium priority): nest and refactor helper functions
-- TODO (medium priority): nest and refactor helper functions
Line 28: Line 26:
local header_style = '! style="white-space: nowrap; font-size: 0.9em; width: 5%; text-align: right; background-color: #eaecf0; padding: 0.25em 0.5em; border: 1px solid white;" |'
local header_style = '! style="white-space: nowrap; font-size: 0.9em; width: 5%; text-align: right; background-color: #eaecf0; padding: 0.25em 0.5em; border: 1px solid white;" |'
local data_style = is_content_navbox
local data_style = is_content_navbox
and '| style="padding: 0;" |' -- For nested navboxes
and '| style="padding: 0;" |\n' -- For nested navboxes; endline required for nested navboxes to work properly
or  '| style="font-size: 0.9em; padding: 0.25em 0.5em;" | ' -- For normal content
or  '| style="font-size: 0.9em; padding: 0.25em 0.5em;" |' -- For normal content; endline not needed as adding it makes rows too thick


table.insert(row, "|-")
table.insert(row, "|-")
Line 35: Line 33:
table.insert(row, data_style .. data)
table.insert(row, data_style .. data)
elseif data and not header then
elseif data and not header then
-- Row is a headerless data row...
-- Row is a headerless data row
local data_style = is_content_navbox
local data_style = is_content_navbox
and '| style="padding: 0;" colspan="2" | ' -- For nested navboxes
and '| style="padding: 0; colspan="2" |\n' -- For nested navboxes
or  '| style="font-size: 0.9em; padding: 0.25em 0.5em;" colspan="2" | ' -- For normal content
or  '| style="font-size: 0.9em; padding: 0.25em 0.5em;" colspan="2" |' -- For normal content
table.insert(row, "|-")
table.insert(row, "|-")
table.insert(row, data_style .. data)
table.insert(row, data_style .. data)
elseif header and not data then
elseif header and not data then
-- Row is a dataless header row...
-- Row is a dataless header row
local data_style = is_content_navbox
local data_style = is_content_navbox
and '| style="padding: 0;" colspan="2" | ' -- For nested navboxes
and '! style="padding: 0;" colspan="2" |\n' -- For nested navboxes; in case nav elements are ever added here, such as numlinks
or  '| style="font-size: 0.9em; padding: 0.25em 0.5em;" colspan="2" | ' -- For normal content
or  '! style="white-space: nowrap; font-size: 0.9em; width: 5%; background-color: #eaecf0; padding: 0.25em 0.5em; border: 1px solid white;" colspan="2" |'
table.insert(row, "|-")
table.insert(row, "|-")
Line 104: Line 102:
-- Navbox to be called by other modules; also called by wrapper function
-- Navbox to be called by other modules; also called by wrapper function
function p._navbox(args)
function p._navbox(args)
local title          = args["Title"]
local title          = args["Title"] or "Navbox Title"
local name            = args["name"]
local name            = args["name"]
local rows            = args["Rows"]
local rows            = args["Rows"]
Line 200: Line 198:
local args = getArgs(frame)
local args = getArgs(frame)
-- Preprocess bools for rows that have either a header or data.
-- Preprocess bools for rows that indicate whether that row is a nested
-- Absence of data defaults to false.
-- navbox. A row is considered valid if it has either a header or data. If
-- a bool exists but not its header or data, it's skipped. If a valid row
-- exists but not its bool, it defaults to false.
local is_data_navbox = {}
local is_data_navbox = {}
for i = 1, 30 do
for i = 1, 30 do
Line 207: Line 207:
local data  = args["Data "  .. i]
local data  = args["Data "  .. i]
local key = string.format("Is Data %d Navbox", i)
local key = string.format("Is Data %d Navbox", i)
local row_contains_entry = header and data
if header or data then
if header or data then
Line 218: Line 217:
-- Preprocess individual entries for headers and data
-- Preprocess individual entries for headers and data
local rows = tiu.header_data_pairs_to_table(args, 30)
local rows = tiu.numbered_header_data_args_to_table(args, 30)
args["Rows"] = rows
args["Rows"] = rows
Line 229: Line 228:
end
end
return result
return frame:preprocess(result)
end
end