Module:Navbox: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
Save progress; address unbounded recursion error |
||
| Line 4: | Line 4: | ||
local p = {} | local p = {} | ||
-- Navbox row | |||
-- A single table representing the row is entered, where: | |||
-- - If it has one entry, then it's for a headerless row | |||
-- - If it has two entry, then it's a header-data pair; if the second entry | |||
-- is another jagged array, then the data is a subtable | |||
function p.navbox_row(row_content) | |||
local row_content = { "Header", {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}}} | |||
--local row_content = { "Header", "Content" } | |||
local row = '<tr>\n' | |||
if #row_content == 1 then | |||
row = row | |||
.. '<td style="width:5%; text-align:center; background-color:#eaecf0; white-space:nowrap; padding:0em; border:1px solid white" colspan="2">\n' | |||
.. '<div style="padding:0.25em 0.5em">' .. row[1] .. '</div>\n' | |||
.. '</td>\n' | |||
elseif #row_content == 2 then | |||
if type(row_content[2]) == "table" then | |||
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' | |||
.. '<td style="padding:0em">\n' | |||
--.. p.navbox_subtable(row_content[2]) | |||
.. "Subtable content goes here" | |||
.. '</td>\n' | |||
else | |||
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' | |||
.. '<td style="padding:0em">\n' | |||
.. '<div style="padding:0.25em 0.5em">' .. row_content[2] .. '</div>\n' | |||
.. '</td>\n' | |||
end | |||
end | |||
local row = row .. '</tr>\n' | |||
return row | |||
end | |||
-- Navbox subtable | |||
function p.navbox_subtable(subtable_content) | |||
local subtable_content = {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}} | |||
local subtable = '<table style="width:100%; border-spacing:0px"\n' | |||
for i = 1, #subtable_content do | |||
subtable = subtable | |||
.. p.navbox_row(subtable_content[i]) | |||
end | |||
subtable = subtable .. '</table>\n' | |||
return subtable | |||
end | |||
-- Navbox to be called by other modules | -- Navbox to be called by other modules | ||
-- Rows | -- Rows are entered as a jagged array; one subtable per row | ||
-- | function p._navbox(title, rows, is_collapsed) | ||
-- - | local title = title or "Navbox Title" | ||
-- | local rows = rows or { "Header", {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}}} | ||
local is_collapsed = is_collapsed or true | |||
-- Start of table | |||
local navbox = '<div class="wikitable">' | |||
.. '<table class="mw-collapsible' .. (is_collapsed and ' mw-collapsed ' or ' ') .. 'nowraplinks" style="width: 100%; border-spacing:0px">\n' | |||
.. '<tr>\n' | |||
.. '<th style="width:5%; text-align:center; background-color:#eaecf0; white-space:nowrap; padding:0.25em 0.5em; border:1px solid white" colspan="2"><b>' .. title .. '</b></th>\n' | |||
.. '</tr>\n' | |||
for i = 1, #rows do | |||
navbox = p.navbox_row(rows[i]) | |||
end | |||
navbox = navbox | |||
.. '</table>\n' | |||
.. '</div>' | |||
return navbox | |||
end | end | ||
Revision as of 20:35, 22 November 2024
- This module implements a metatemplate, and may be invoked by templates using its corresponding template Template:Navbox, or used directly from other modules.
Module:Navbox is a module that implements the {{Navbox}} template. Navbox templates can be made by using the template or by calling the _navbox function from another module.
On templates, you can create a navbox by using {{Navbox}}, which calls this module's wrapper function.
local navbox = require("Module:Navbox")._navbox to create a navbox.
| Introspection summary for Module:Navbox | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
-- 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
local p = {}
-- Navbox row
-- A single table representing the row is entered, where:
-- - If it has one entry, then it's for a headerless row
-- - If it has two entry, then it's a header-data pair; if the second entry
-- is another jagged array, then the data is a subtable
function p.navbox_row(row_content)
local row_content = { "Header", {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}}}
--local row_content = { "Header", "Content" }
local row = '<tr>\n'
if #row_content == 1 then
row = row
.. '<td style="width:5%; text-align:center; background-color:#eaecf0; white-space:nowrap; padding:0em; border:1px solid white" colspan="2">\n'
.. '<div style="padding:0.25em 0.5em">' .. row[1] .. '</div>\n'
.. '</td>\n'
elseif #row_content == 2 then
if type(row_content[2]) == "table" then
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'
.. '<td style="padding:0em">\n'
--.. p.navbox_subtable(row_content[2])
.. "Subtable content goes here"
.. '</td>\n'
else
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'
.. '<td style="padding:0em">\n'
.. '<div style="padding:0.25em 0.5em">' .. row_content[2] .. '</div>\n'
.. '</td>\n'
end
end
local row = row .. '</tr>\n'
return row
end
-- Navbox subtable
function p.navbox_subtable(subtable_content)
local subtable_content = {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}}
local subtable = '<table style="width:100%; border-spacing:0px"\n'
for i = 1, #subtable_content do
subtable = subtable
.. p.navbox_row(subtable_content[i])
end
subtable = subtable .. '</table>\n'
return subtable
end
-- Navbox to be called by other modules
-- Rows are entered as a jagged array; one subtable per row
function p._navbox(title, rows, is_collapsed)
local title = title or "Navbox Title"
local rows = rows or { "Header", {{"Subheadher 1", "Content 1"}, {"Subheader 2", "Content 2"}}}
local is_collapsed = is_collapsed or true
-- Start of table
local navbox = '<div class="wikitable">'
.. '<table class="mw-collapsible' .. (is_collapsed and ' mw-collapsed ' or ' ') .. 'nowraplinks" style="width: 100%; border-spacing:0px">\n'
.. '<tr>\n'
.. '<th style="width:5%; text-align:center; background-color:#eaecf0; white-space:nowrap; padding:0.25em 0.5em; border:1px solid white" colspan="2"><b>' .. title .. '</b></th>\n'
.. '</tr>\n'
for i = 1, #rows do
navbox = p.navbox_row(rows[i])
end
navbox = navbox
.. '</table>\n'
.. '</div>'
return navbox
end
-- Navbox to be #invoke'd
-- Only supports one level of headers
function p.navbox(args)
end
return p