Module:Navplate2
From Datacron Continuity Database, the Star Wars Legends Wiki
More actions
| Template documentation follows |
|---|
| Note: the template above may sometimes be partially or fully invisible. |
| Visit Module:Navplate2/doc to edit this documentation. (How does this work?) |
Template loop detected: Template:Documentation
{{navplate2}} allows a navigational template to be set up relatively quickly by supplying it with one or more lists of links, similar to Template:Navbox on Wikipedia.
Usage
Please remove the parameters that are left blank.
{{Navplate2
|subtitle =
|title =
|label1 =
|list1 =
|label2 =
|list2 =
|label3 =
|list3 =
}}
Parameter list
subtitle- Subtitle text above the title, it should be connected to the title
title- Title of the subject (wikilink is optional)
labeln- Label text for the list
listn- Text listing wikilinks
headern- Group header text
id- ID used for HTML, mostly used in template
Example
{{Navplate2
|id=test
|subtitle=List of
|title=Title
|header1 = Header
|label2 = Label 1
|listA2= [[Item 1]][[Item 2]]
|listB2= [[Item 1]][[Item 2]]
|header3 = Header
|label4 = Label 2
|listA4= [[Item 1]][[Item 2]]
|listB4= [[Item 1]][[Item 2]]
}}
gives
TemplateData
Creates a navigational box for links to other pages.
| Parameter | Description | Type | Status | |
|---|---|---|---|---|
| Subtitle | subtitle | Subtitle text above the title, it should be connected to the title
| String | suggested |
| Title | title | Title of the subject (wikilink is optional)
| Unknown | required |
| ID | id | ID used for HTML | Unknown | optional |
Module:Navplate2 implements the {{navplate2}} template.
--------------------------------------------------------------------------------
-- Module:Navplate --
-- This module implements {{Navplate}} --
-- Based on Module:Infobox --
-- This is a work in progress --
--------------------------------------------------------------------------------
local p = {}
local args = {}
local origArgs = {}
local function union( t1, t2 )
local vals = {}
for k, v in pairs( t1 ) do
vals[ v ] = true
end
for k, v in pairs( t2 ) do
vals[ v ] = true
end
local ret = {}
for k, v in pairs( vals ) do
table.insert( ret, k )
end
return ret
end
local function getArgNums( prefix )
local nums = {}
for k, v in pairs( args ) do
local num = tostring( k ):match( '^' .. prefix .. '([1-9]%d*)$' )
if num then table.insert( nums, tonumber( num ) ) end
end
table.sort( nums )
return nums
end
local function getDetailsHTML( data, frame )
local summary = frame:extensionTag {
name = 'summary',
content = data.summary.content,
args = {
class = data.summary.class
}
}
local details = frame:extensionTag {
name = 'details',
content = summary .. data.details.content,
args = {
class = data.details.class,
role = data.details.role,
open = data.details.open or 'no'
}
}
return details
end
local function getRowHTML( rowArgs )
local html = mw.html.create()
if rowArgs.header then
html
:tag( 'div' )
:addClass( 'template-navplate__groupheader' )
:wikitext( rowArgs.header )
elseif rowArgs.listA then
html
:tag( 'div' )
:addClass( 'template-navplate-item' )
:css( 'display', 'flex' ) -- Arrange items in a single row
:css( 'gap', '10px' ) -- Add spacing between columns
:tag( 'div' )
:addClass( 'template-navplate-item__listA' )
:css( 'flex', '1' ) -- Column 1: ListA
:wikitext( rowArgs.listA )
:done()
:tag( 'div' )
:addClass( 'template-navplate-item__label' )
:css( 'flex', '1' ) -- Column 2: Label
:wikitext( rowArgs.label )
:done()
:tag( 'div' )
:addClass( 'template-navplate-item__listB' )
:css( 'flex', '1' ) -- Column 3: ListB
:wikitext( rowArgs.listB )
end
return html
end
local function getTitleHTML()
local html = mw.html.create( 'div' )
html:addClass( 'template-navplate__headerContent' )
if not args.title then return end
if args.subtitle then
html
:tag( 'div' )
:addClass( 'template-navplate__subtitle' )
:wikitext( args.subtitle )
:done()
end
html
:tag( 'div' )
:addClass( 'template-navplate__title' )
:wikitext( args.title )
return html
end
local function getRowsHTML()
local html = mw.html.create()
local rownums = union( getArgNums( 'header' ), getArgNums( 'listA' ) )
table.sort( rownums )
for _, num in ipairs( rownums ) do
html:node( getRowHTML( {
header = args[ 'header' .. tostring( num ) ],
label = args[ 'label' .. tostring( num ) ],
listA = args[ 'listA' .. tostring( num ) ],
listB = args[ 'listB' .. tostring( num ) ]
} ) )
end
return html
end
local function preprocessSingleArg( argName )
if origArgs[ argName ] and origArgs[ argName ] ~= '' then
args[ argName ] = origArgs[ argName ]
end
end
local function preprocessArgs( prefixTable, step )
if type( prefixTable ) ~= 'table' then
error( 'Non-table value detected for the prefix table', 2 )
end
if type( step ) ~= 'number' then
error( 'Invalid step value detected', 2 )
end
for i, v in ipairs( prefixTable ) do
preprocessSingleArg( v.prefix )
if args[ v.prefix ] and v.depend then
for _, dependValue in ipairs( v.depend ) do
preprocessSingleArg( dependValue )
end
end
end
local a = 1
local moreArgumentsExist = true
while moreArgumentsExist == true do
moreArgumentsExist = false
for i = a, a + step - 1 do
for _, v in ipairs( prefixTable ) do
local prefixArgName = v.prefix .. tostring( i )
if origArgs[ prefixArgName ] then
moreArgumentsExist = true
preprocessSingleArg( prefixArgName )
end
if v.depend and (args[ prefixArgName ] or (i == 1 and args[ v.prefix ])) then
for _, dependValue in ipairs( v.depend ) do
local dependArgName = dependValue .. tostring( i )
preprocessSingleArg( dependArgName )
end
end
end
end
a = a + step
end
end
local function parseDataParameters()
preprocessSingleArg( 'id' )
preprocessSingleArg( 'subtitle' )
preprocessSingleArg( 'title' )
preprocessArgs( {
{ prefix = 'header' },
{ prefix = 'listA', depend = { 'label' } },
{ prefix = 'listB', depend = { 'label' } }
}, 50 )
end
local function _navplate()
local frame = mw.getCurrentFrame()
local summaryHTML = mw.html.create()
:tag( 'div' )
:addClass( 'citizen-ui-icon mw-ui-icon-wikimedia-collapse' )
:done()
:node( getTitleHTML() )
local contentHTML = mw.html.create( 'div' )
:addClass( 'template-navplate__content' )
:css( 'content-visibility', 'auto' )
:node( getRowsHTML() )
local output = getDetailsHTML( {
details = { class = 'template-navplate', content = tostring( contentHTML ) },
summary = { class = 'template-navplate__header', content = tostring( summaryHTML ) }
}, frame )
return frame:extensionTag { name = 'templatestyles', args = { src = 'Module:Navplate2/styles.css' } } .. output
end
function p.navplate( frame )
origArgs = frame:getParent().args
parseDataParameters()
return _navplate()
end
function p.navplateTemplate( frame )
origArgs = {}
for k, v in pairs( frame.args ) do origArgs[ k ] = mw.text.trim( v ) end
parseDataParameters()
return _navplate()
end
return p