Module:Listbox

From Zelda Dungeon Wiki
Revision as of 01:19, June 21, 2020 by Locke (talk | contribs) (Locke moved page Module:Navigation to Module:Navbox without leaving a redirect)
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.

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

local p = require ( 'Module:Box' )

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

function p.list( frame )
  local game = frame.args[1]
  local category = frame.args[2]
  local intersection = game .. ' ' .. category

  -- construct the box
  local box, content = p._light{
    class = 'navbox',
    title = intersection,
    hide = 'show', -- TODO count number of navboxes, hide after the second or third (could relegate to the calling template)
    edit = intersection
  }

  -- get list of pages in the category
  local pages = mw.ext.dpl.getPagenames{ category = intersection, 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 hlist = content:tag( 'div' )
    :addClass( 'hlist' )
    :tag( 'ul' )
  for i, v in ipairs(pages) do
    -- TODO support variants
    hlist:tag( 'li' )
      :wikitext( '[[' .. v .. ']]' )
  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( box )
end

return p