Module:Infobox: Difference between revisions

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
m (change label class to zdw-label to distinguish from bootstrap)
(update to new Box implementation. Still need to implement the actual infobox part)
 
Line 1: Line 1:
local p = require( 'Module:Box' )
local Args = require( 'Module:Args' )
local Box = require( 'Module:Box' ).Box


function p.hostile( frame )
local Infobox = Box.new()
    return tostring( p._infobox( 'hostile', frame:getParent().args ) )
Infobox.__index = Infobox
end
setmetatable( Infobox, Box )


function p.dungeon( frame )
local p, mt = {}, {}
    return tostring( p._infobox( 'dungeon', frame:getParent().args ) )
end


function p.location( frame )
p.Infobox = Infobox
    return tostring( p._infobox( 'location', frame:getParent().args ) )
end


function p.character( frame )
function Infobox.new( type, args )
    return tostring( p._infobox( 'character', frame:getParent().args ) )
  local obj = Box.new( 'light', {
end
    class = 'zdw-infobox zdw-infobox--' .. type,
    title = args.title
  } )
  obj.infoboxArgs = args -- TODO don't like this. would it make sense to preprocess args here and store some other structure(s) on obj? or pass all args to box (more flexibility for callers but breaks encapsulation)?


function p.item( frame )
  return setmetatable( obj, Infobox )
    return tostring( p._infobox( 'item', frame:getParent().args ) )
end
end


function p.knowledge( frame )
-- override
    return tostring( p._infobox( 'knowledge', frame:getParent().args ) )
function Infobox:renderContent()
end
  local args = self.infoboxArgs
  local content = mw.html.create( 'div' )


function p.meta( frame )
  -- add logo (TODO better way of loading images?)
     return tostring( p._infobox( 'meta', frame:getParent().args ) )
  if args.logo then
end
     content:tag( 'div' )
      :addClass( 'zdw-label center' )
      :wikitext( args.logo )
  end


function p._infobox( type, args )
  -- add image/boxart (TODO better way of loading images?)
    -- translate "name" from infobox template to "title" box parameter
  if args.boxart or args.image then
    local boxargs = args
     content:tag( 'div' )
    boxargs.title = args.name
      :addClass( 'center' )
     boxargs.class = 'infobox infobox-' .. type
      :wikitext( args.boxart or args.image )
  end


    -- construct box
  -- TODO table
    local box, content = p._light( boxargs )


    -- add logo (TODO better way of loading images?)
  return tostring( content )
    if args.logo then
end -- function Infobox:renderContent()
        content:tag( 'div' )
            :addClass( 'zdw-label center' )
            :wikitext( args.logo )
    end


    -- add image/boxart (TODO better way of loading images?)
function p._main( type, args )
    if args.boxart or args.image then
  local infobox = Infobox.new( type, args )
        content:tag( 'div' )
  return infobox:render()
            :addClass( 'center' )
end
            :wikitext( args.boxart or args.image )
    end


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


    return tostring( box )
-- for use in the debug console:
end
-- =p.infoboxType(p.debugFrame)
p.debugFrame = {
  args = { -- #invoke args
  },
  getParent = function() return {
    args = { -- template args
      title = 'The Legend of Zelda'
    }
  } end
}


return p
return setmetatable( p, mt )

Latest revision as of 22:32, December 17, 2020

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

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

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

local p, mt = {}, {}

p.Infobox = Infobox

function Infobox.new( type, args )
  local obj = Box.new( 'light', {
    class = 'zdw-infobox zdw-infobox--' .. type,
    title = args.title
  } )
  obj.infoboxArgs = args -- TODO don't like this. would it make sense to preprocess args here and store some other structure(s) on obj? or pass all args to box (more flexibility for callers but breaks encapsulation)?

  return setmetatable( obj, Infobox )
end

-- override
function Infobox:renderContent()
  local args = self.infoboxArgs
  local content = mw.html.create( 'div' )

  -- add logo (TODO better way of loading images?)
  if args.logo then
    content:tag( 'div' )
      :addClass( 'zdw-label center' )
      :wikitext( args.logo )
  end

  -- add image/boxart (TODO better way of loading images?)
  if args.boxart or args.image then
    content:tag( 'div' )
      :addClass( 'center' )
      :wikitext( args.boxart or args.image )
  end

  -- TODO table

  return tostring( content )
end -- function Infobox:renderContent()

function p._main( type, args )
  local infobox = Infobox.new( type, args )
  return infobox:render()
end

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

-- for use in the debug console:
-- =p.infoboxType(p.debugFrame)
p.debugFrame = {
  args = { -- #invoke args
  },
  getParent = function() return {
    args = { -- template args
      title = 'The Legend of Zelda'
    }
  } end
}

return setmetatable( p, mt )