Module:Navbox: Difference between revisions

Ganaram inukshuk (talk | contribs)
implement navbox nesting; some cleanup
Ganaram inukshuk (talk | contribs)
No edit summary
Line 1: Line 1:
-- Page is following provisonal style guide: User:Ganaram_inukshuk/Provisional_style_guide_for_Lua
-- Page is following provisonal style guide: User:Ganaram_inukshuk/Provisional_style_guide_for_Lua
-- Loosely modeled off of Runescape Wiki's navbox, not Wikipedia's
-- Loosely modeled off of Runescape Wiki's navbox, not Wikipedia's
local getArgs = require('Module:Arguments').getArgs
local getArgs = require("Module:Arguments").getArgs
local yesno = require("Module:Yesno")
local p = {}
local p = {}


-- Navbox row
-- Navbox row
-- The <td> cell has a div that sets padding for row content; this is omitted if
function p.navbox_row(row_content)
-- the row content is a child navbox.
local row_header    = row_content["Header"]
function p.navbox_row(row_content, is_row_child_navbox)
local row_data      = row_content["Data"]
local row_content = row_content or { "Header", "Content" }
local is_row_navbox = row_content["Is Row Navbox"]
local is_row_child_navbox = is_row_child_navbox or false -- Not implemented


local row = '<tr>\n'
local row = '<tr>\n'
if #row_content == 1 then
if row_header == nil then
-- Headerless row
-- Headerless row
if is_row_child_navbox then
if is_row_navbox then
-- Row data is a child navbox
-- Row data is a child navbox
row = row
row = row
Line 27: Line 27:
    .. '</td>\n'
    .. '</td>\n'
     end
     end
elseif #row_content == 2 then
else
-- Simple row with header and data
-- Simple row with header and data
if is_row_child_navbox then
if is_row_navbox then
row = row
row = row
.. '<th style="width:5%; text-align:right; background-color:#eaecf0; white-space:nowrap; padding:0.25em 0.5em; border:1px solid white">' .. row_content[1] .. '</th>\n'
.. '<th style="width:5%; text-align:right; background-color:#eaecf0; white-space:nowrap; padding:0.25em 0.5em; border:1px solid white">' .. row_content[1] .. '</th>\n'
Line 75: Line 75:
local is_child_navbox = args["Is Child Navbox"]
local is_child_navbox = args["Is Child Navbox"]
local rows            = args["Rows"]
local rows            = args["Rows"]
local row_is_subtable = args["Is Row Child Navbox"] -- Not implemented
local is_collapsible  = args["Is Collapsible"] -- Not implemented
local is_collapsible  = args["Is Collapsible"] -- Not implemented
local is_collapsed    = args["Is Collapsible"] -- Not working?
local is_collapsed    = args["Is Collapsible"] -- Not working?
Line 97: Line 96:
function p.navbox(frame)
function p.navbox(frame)
local args = getArgs(frame)
local args = getArgs(frame)
-- Prepropress boolean args
args["Is Collapsible" ] = yesno(args["Is Collapsible" ])
args["Is Collapsible" ] = yesno(args["Is Collapsible" ])
args["Is Child Navbox"] = yesno(args["Is Child Navbox"])
-- Preprocess individual entries for, headers, data, and is-row-child into
-- Preprocess individual entries for, headers, data, and is-row-child into
-- two separate tables.
-- one single table.
-- Both the Wikipedia and RsWiki navboxes go up to 20 rows so follow that
-- Both the Wikipedia and RsWiki navboxes go up to 20 rows so follow that.
local rows = {}
local rows = {}
local is_row_child_navbox = {}
for i = 1, 20 do
for i = 1, 20 do
local row = {}
local header = args["Header " .. i]
local header = args["Header " .. i]
local data  = args["Data "  .. i]
local data  = args["Data "  .. i]
local is_child_navbox = args["Is Row Child Navbox" .. i]
local is_navbox = yesno(args["Is Data " .. i .. " Navbox"])
if header ~= nil and data ~= nil then
local row = nil
-- If there's both a header data, add both
if (header ~= nil or data ~= nil or is_navbox ~= nil) then
table.insert(row, header)
row = {
table.insert(row, data)
["Header"] = header,
elseif header == nil and data ~= nil then
["Data"] = data,
-- Headerless row
["Is Navbox"] = is_navbox
table.insert(row, data)
}
elseif header ~= nil and data == nil then
-- Dataless row with header; this is allowed
table.insert(row, header)
table.insert(row, "")
end
end
if row ~= nil then
if #row >= 1 then
table.insert(rows, row)
table.insert(rows, row)
end
end
if is_child_navbox ~= nil then
-- Remove original entries as cleanup
table.insert(is_row_child_navbox, is_child_navbox)
end
args["Header " .. i] = nil
args["Header " .. i] = nil
args["Data "  .. i] = nil
args["Data "  .. i] = nil
args["Is Row Child Navbox" .. i] = nil
args["Is Data " .. i .. " Navbox"] = nil
end
end
args["Rows"] = rows
args["Rows"] = rows
args["Is Row Child Navbox"] = is_row_child_navbox
return p._navbox(args)
return p._navbox(args)