Module:Listbox: Difference between revisions

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
m (Locke moved page Module:Navigation to Module:Navbox without leaving a redirect)
(refactor to inherit from Box in a more O-O way)
Line 1: Line 1:
local p = require ( 'Module:Box' )
local Box = require( 'Module:Box' ).Box


-- for use in the debug console:
local Navbox = Box.new()
-- =p.list(p.debugframe)
Navbox.__index = Navbox
p.debugframe = {
setmetatable( Navbox, Box )
  args = {
    [1] = "A Link to the Past",
    [2] = "Enemies",
  }
}


function p.list( frame )
function Navbox.new( format, args )
   local game = frame.args[1]
   local subject = args[1] .. ' ' .. args[2]
  local category = frame.args[2]
   args.class = 'navbox'
  local intersection = game .. ' ' .. category
  args.title = subject
 
  args.edit = subject
   -- construct the box
  args.hide = 'show' -- TODO count number of navboxes, hide after the second or third (could relegate to the calling template)
  local box, content = p._light{
  local obj = Box.new( 'dark', args )
    class = 'navbox',
  obj.subject = subject
    title = intersection,
   obj.categories = { args[1], subject, args[2] }
    hide = 'show', -- TODO count number of navboxes, hide after the second or third (could relegate to the calling template)
  return setmetatable( obj, Navbox )
    edit = intersection
end
   }


function Navbox:renderContent()
   -- get list of pages in the category
   -- get list of pages in the category
   local pages = mw.ext.dpl.getPagenames{ category = intersection, ordermethod = 'sortkey', order = 'ascending' }
   local pages = mw.ext.dpl.getPagenames{ category = self.subject, ordermethod = 'sortkey', order = 'ascending' }
   -- TODO get the page contents, look for grouping and variant directives, and restructure the table accordingly
   -- TODO get the page contents, look for grouping and variant directives, and restructure the table accordingly


   -- TODO support groupings using table; for now just one big hlist
   -- TODO support groupings using table; for now just one big hlist
   local hlist = content:tag( 'div' )
   local content = mw.html.create( 'div' )
     :addClass( 'hlist' )
     :addClass( 'hlist' )
    :tag( 'ul' )
  local hlist = content:tag( 'ul' )
   for i, v in ipairs(pages) do
   for i, v in ipairs(pages) do
     -- TODO support variants
     -- TODO support variants
Line 37: Line 32:
   end
   end


   -- TODO footer with catlinks (add it to the box module instead of hacking it on the end of the content's table)
   return tostring( content )
end


   return tostring( box )
local p, mt = {}, {}
 
function p._main( format, args )
  local navbox = Navbox.new( format, args )
   return navbox:render()
end
end


return p
-- translates p.function( frame ) to p._main( function, args )
function mt.__index( table, key )
  return function ( frame )
    return table._main( key, frame.args )
  end
end
 
-- for use in the debug console:
-- =p.list(p.debugframe)
p.debugframe = {
  args = {
    [1] = "A Link to the Past",
    [2] = "Enemies",
  }
}
 
return setmetatable( p, mt )

Revision as of 03:58, June 21, 2020

Documentation for this module may be created at Module:Listbox/doc

local Box = require( 'Module:Box' ).Box

local Navbox = Box.new()
Navbox.__index = Navbox
setmetatable( Navbox, Box )

function Navbox.new( format, args )
  local subject = args[1] .. ' ' .. args[2]
  args.class = 'navbox'
  args.title = subject
  args.edit = subject
  args.hide = 'show' -- TODO count number of navboxes, hide after the second or third (could relegate to the calling template)
  local obj = Box.new( 'dark', args )
  obj.subject = subject
  obj.categories = { args[1], subject, args[2] }
  return setmetatable( obj, Navbox )
end

function Navbox:renderContent()
  -- get list of pages in the category
  local pages = mw.ext.dpl.getPagenames{ category = self.subject, ordermethod = 'sortkey', order = 'ascending' }
  -- TODO get the page contents, look for grouping and variant directives, and restructure the table accordingly

  -- TODO support groupings using table; for now just one big hlist
  local content = mw.html.create( 'div' )
    :addClass( 'hlist' )
  local hlist = content:tag( 'ul' )
  for i, v in ipairs(pages) do
    -- TODO support variants
    hlist:tag( 'li' )
      :wikitext( '[[' .. v .. ']]' )
  end

  return tostring( content )
end

local p, mt = {}, {}

function p._main( format, args )
  local navbox = Navbox.new( format, args )
  return navbox:render()
end

-- translates p.function( frame ) to p._main( function, args )
function mt.__index( table, key )
  return function ( frame )
    return table._main( key, frame.args )
  end
end

-- for use in the debug console:
-- =p.list(p.debugframe)
p.debugframe = {
  args = {
    [1] = "A Link to the Past",
    [2] = "Enemies",
  }
}

return setmetatable( p, mt )