Module:Navbox: Difference between revisions
Save progress; address unbounded recursion error |
Fixed recursion issue; everything works? |
||
Line 10: | Line 10: | ||
-- is another jagged array, then the data is a subtable | -- is another jagged array, then the data is a subtable | ||
function p.navbox_row(row_content) | function p.navbox_row(row_content) | ||
local row_content = { "Header", {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}} | local row_content = row_content or { "Header", {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}}} | ||
local row = '<tr>\n' | local row = '<tr>\n' | ||
if #row_content == 1 then | if #row_content == 1 then | ||
-- Headerless row | |||
row = row | row = row | ||
.. '<td style="width:5%; text-align:center; background-color:#eaecf0; white-space:nowrap; padding:0em; border:1px solid white" colspan="2">\n' | .. '<td style="width:5%; text-align:center; background-color:#eaecf0; white-space:nowrap; padding:0em; border:1px solid white" colspan="2">\n' | ||
Line 22: | Line 21: | ||
elseif #row_content == 2 then | elseif #row_content == 2 then | ||
if type(row_content[2]) == "table" then | if type(row_content[2]) == "table" then | ||
-- Row with subcategories | |||
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' | ||
.. '<td style="padding:0em">\n' | .. '<td style="padding:0em">\n' | ||
.. p.navbox_subtable(row_content[2]) | |||
.. '</td>\n' | .. '</td>\n' | ||
else | else | ||
-- Simple row with header and data | |||
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 36: | Line 36: | ||
end | end | ||
end | end | ||
local row = row .. '</tr>\n' | local row = row .. '</tr>\n' | ||
Line 44: | Line 43: | ||
-- Navbox subtable | -- Navbox subtable | ||
function p.navbox_subtable(subtable_content) | function p.navbox_subtable(subtable_content) | ||
local subtable_content = {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}} | local subtable_content = subtable_content or {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}} | ||
local subtable = '<table style="width:100%; border-spacing:0px"\n' | local subtable = '<table style="width:100%; border-spacing:0px"\n' | ||
for i = 1, #subtable_content do | for i = 1, #subtable_content do | ||
subtable = subtable | subtable = subtable | ||
.. p.navbox_row(subtable_content[i]) | .. p.navbox_row(subtable_content[i]) | ||
end | end | ||
subtable = subtable .. '</table>\n' | subtable = subtable .. '</table>\n' | ||
Line 62: | Line 59: | ||
function p._navbox(title, rows, is_collapsed) | function p._navbox(title, rows, is_collapsed) | ||
local title = title or "Navbox Title" | local title = title or "Navbox Title" | ||
local rows = rows or { "Header", {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}}} | local rows = rows or {{"Header", {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}}}} | ||
local is_collapsed = is_collapsed or true | local is_collapsed = is_collapsed or true | ||
Line 73: | Line 70: | ||
for i = 1, #rows do | for i = 1, #rows do | ||
navbox = p.navbox_row(rows[i]) | navbox = navbox .. p.navbox_row(rows[i]) | ||
end | end | ||