Module:Navbox: Difference between revisions
Jump to navigation
Jump to search
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) | ||
Revision as of 10:56, 23 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 getArgs = require("Module:Arguments").getArgs
local yesno = require("Module:Yesno")
local p = {}
-- Navbox row
function p.navbox_row(row_content)
local row_header = row_content["Header"]
local row_data = row_content["Data"]
local is_row_navbox = row_content["Is Row Navbox"]
local row = '<tr>\n'
if row_header == nil then
-- Headerless row
if is_row_navbox then
-- Row data is a child navbox
row = row
.. '<td style="width:5%; text-align:center; background-color:#eaecf0; white-space:nowrap; padding:0em; border:1px solid white" colspan="2">\n'
.. row_content[1]
.. '</td>\n'
else
-- Row data is normal data
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_content[1] .. '</div>\n'
.. '</td>\n'
end
else
-- Simple row with header and data
if is_row_navbox 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'
.. row_content[2]
.. '</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 title
-- A title is added if it's provided.
-- Child navboxes used for subcategories don't need a title or collapse options.
function p.navbox_title(title, is_collapsible, is_collapsed)
local is_collapsible = is_collapsible or true -- Not implemented
local is_collapsed = is_collapsed or true -- Not working?
local navbox_title = ''
if title == nil then
navbox_title = '<table style="width:100%; border-spacing:0px">\n'
else
navbox_title = navbox_title
.. '<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'
end
return navbox_title
end
-- Navbox to be called by other modules; also called by wrapper function
function p._navbox(args)
local title = args["Title"]
local is_child_navbox = args["Is Child Navbox"]
local rows = args["Rows"]
local is_collapsible = args["Is Collapsible"] -- Not implemented
local is_collapsed = args["Is Collapsible"] -- Not working?
-- Start of table
local navbox = p.navbox_title(title, is_collapsible, is_collapsed, is_subtable)
for i = 1, #rows do
navbox = navbox .. p.navbox_row(rows[i])
end
navbox = navbox
.. '</table>\n'
.. '</div>'
return navbox
end
-- Navbox to be #invoke'd
-- Wrapper function for template-based navboxes
function p.navbox(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
-- one single table.
-- Both the Wikipedia and RsWiki navboxes go up to 20 rows so follow that.
local rows = {}
for i = 1, 20 do
local header = args["Header " .. i]
local data = args["Data " .. i]
local is_navbox = yesno(args["Is Data " .. i .. " Navbox"])
local row = nil
if (header ~= nil or data ~= nil or is_navbox ~= nil) then
row = {
["Header"] = header,
["Data"] = data,
["Is Navbox"] = is_navbox
}
end
if row ~= nil then
table.insert(rows, row)
end
-- Remove original entries as cleanup
args["Header " .. i] = nil
args["Data " .. i] = nil
args["Is Data " .. i .. " Navbox"] = nil
end
args["Rows"] = rows
return p._navbox(args)
end
return p