Module:Navbox: Difference between revisions
implement navbox nesting; some cleanup |
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( | local getArgs = require("Module:Arguments").getArgs | ||
local yesno = require("Module:Yesno") | |||
local p = {} | local p = {} | ||
-- Navbox row | -- Navbox row | ||
function p.navbox_row(row_content) | |||
local row_header = row_content["Header"] | |||
function p.navbox_row(row_content | local row_data = row_content["Data"] | ||
local | local is_row_navbox = row_content["Is Row Navbox"] | ||
local | |||
local row = '<tr>\n' | local row = '<tr>\n' | ||
if | if row_header == nil then | ||
-- Headerless row | -- Headerless row | ||
if | 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 | ||
else | |||
-- Simple row with header and data | -- Simple row with header and data | ||
if | 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 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 | ||
-- | -- 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 = {} | ||
for i = 1, 20 do | for i = 1, 20 do | ||
local header = args["Header " .. i] | local header = args["Header " .. i] | ||
local data = args["Data " .. i] | local data = args["Data " .. i] | ||
local | local is_navbox = yesno(args["Is Data " .. i .. " Navbox"]) | ||
if header ~= nil | local row = nil | ||
if (header ~= nil or data ~= nil or is_navbox ~= nil) then | |||
row = { | |||
["Header"] = header, | |||
["Data"] = data, | |||
["Is Navbox"] = is_navbox | |||
} | |||
end | end | ||
if row ~= nil then | |||
if | |||
table.insert(rows, row) | table.insert(rows, row) | ||
end | end | ||
-- Remove original entries as cleanup | |||
args["Header " .. i] = nil | args["Header " .. i] = nil | ||
args["Data " .. i] = nil | args["Data " .. i] = nil | ||
args["Is | args["Is Data " .. i .. " Navbox"] = nil | ||
end | end | ||
args["Rows"] = rows | args["Rows"] = rows | ||
return p._navbox(args) | return p._navbox(args) |