Module:Listbox: Difference between revisions
Jump to navigation
Jump to search
Want an adless experience? Log in or Create an account.
(and the other one) |
(REWRITE - extending Listbox) |
||
Line 1: | Line 1: | ||
local Args = require( 'Module:Args' ) | local Args = require( 'Module:Args' ) | ||
local | local Listing = require( 'Module:Listing' ) | ||
function | function buildHList( parent, sections ) | ||
local | local list = parent:addClass( 'hlist' ) | ||
:tag( 'ul' ) | |||
for _, section in ipairs( sections ) do | |||
for | list:tag( 'li' ) | ||
:wikitext( '[[' .. section.name .. ']]' ) | |||
end | end | ||
end | end | ||
local Listbox = Listing.Listbox | |||
local Navbox = setmetatable( {}, Listbox ) | |||
Navbox.__index = Navbox | |||
function Navbox.new( args ) | |||
local obj = Listbox.new( args ) | |||
return setmetatable( obj, Navbox ) | |||
end | end | ||
-- override | |||
function Navbox:renderContent() | |||
local listing = Listing._parseListing( 'User:Locke/Sandbox/Listing' ) -- TODO self.subject ) | |||
function | |||
local content = mw.html.create( 'table' ) | local content = mw.html.create( 'table' ) | ||
if | if #listing.topLevelLeaves > 0 then | ||
local defaultCell = content:tag( 'tr' ) | local defaultCell = content:tag( 'tr' ) | ||
:tag( 'td' ) | :tag( 'td' ) | ||
Line 122: | Line 32: | ||
:attr( 'colspan', '2' ) | :attr( 'colspan', '2' ) | ||
:css( 'text-align', 'center' ) | :css( 'text-align', 'center' ) | ||
buildHList( defaultCell, listing.topLevelLeaves ) | |||
end | end | ||
if | if #listing.groups > 0 then | ||
for index, group in ipairs( listing.groups ) do | |||
local row = content:tag( 'tr' ) | |||
for index, group in ipairs( groups ) do | row:tag( 'th' ) | ||
:addClass( 'label' ) | |||
:wikitext( group.name ) | |||
local cell = row:tag( 'td' ) | |||
:addClass( (index + (#listing.topLevelLeaves > 0 and 1 or 0)) % 2 == 0 and 'even' or 'odd' ) | |||
buildHList( cell, group.sections ) | |||
end | end | ||
end | end | ||
Line 143: | Line 49: | ||
end | end | ||
local | local p = {} | ||
function p.main( frame ) | |||
local navbox = Navbox.new( Args.fromFrame( frame ) ) | |||
function p. | |||
local navbox = Navbox.new( | |||
return navbox:render() | return navbox:render() | ||
end | end | ||
-- for use in the debug console: | -- for use in the debug console: | ||
-- =p. | -- =p.main(p.debugframe) | ||
p.debugframe = { | p.debugframe = { | ||
args = { | args = {}, | ||
[1] = "The Legend of Zelda", | getParent = function() return { | ||
args = { | |||
} | [1] = "The Legend of Zelda", | ||
[2] = "Enemies" | |||
} | |||
} end | |||
} | } | ||
return | return p |
Revision as of 22:45, July 25, 2020
Documentation for this module may be created at Module:Listbox/doc
local Args = require( 'Module:Args' ) local Listing = require( 'Module:Listing' ) function buildHList( parent, sections ) local list = parent:addClass( 'hlist' ) :tag( 'ul' ) for _, section in ipairs( sections ) do list:tag( 'li' ) :wikitext( '[[' .. section.name .. ']]' ) end end local Listbox = Listing.Listbox local Navbox = setmetatable( {}, Listbox ) Navbox.__index = Navbox function Navbox.new( args ) local obj = Listbox.new( args ) return setmetatable( obj, Navbox ) end -- override function Navbox:renderContent() local listing = Listing._parseListing( 'User:Locke/Sandbox/Listing' ) -- TODO self.subject ) local content = mw.html.create( 'table' ) if #listing.topLevelLeaves > 0 then local defaultCell = content:tag( 'tr' ) :tag( 'td' ) :addClass( 'odd' ) :attr( 'colspan', '2' ) :css( 'text-align', 'center' ) buildHList( defaultCell, listing.topLevelLeaves ) end if #listing.groups > 0 then for index, group in ipairs( listing.groups ) do local row = content:tag( 'tr' ) row:tag( 'th' ) :addClass( 'label' ) :wikitext( group.name ) local cell = row:tag( 'td' ) :addClass( (index + (#listing.topLevelLeaves > 0 and 1 or 0)) % 2 == 0 and 'even' or 'odd' ) buildHList( cell, group.sections ) end end return content end local p = {} function p.main( frame ) local navbox = Navbox.new( Args.fromFrame( frame ) ) return navbox:render() end -- for use in the debug console: -- =p.main(p.debugframe) p.debugframe = { args = {}, getParent = function() return { args = { [1] = "The Legend of Zelda", [2] = "Enemies" } } end } return p