Module:Stats/REQ

local utils = require( 'Module:Utils' ) local infocard = require( 'Module:Infocard' ) local templates = require( 'Module:Stats/REQ/H5G/TEMPLATES' )

local p = {}

function p.infocard( frame ) -- Return an error if no card name is given if frame.args[1] == nil or frame.args[1] == '' then return utils.error( 'Please specify a card name!' ) end -- Load the REQ data from the correct module page local card = tostring( frame.args[1] ) local data = utils.loadDataIfExists( 'Module:Stats/REQ/H5G/' .. card ) -- Return an error message if it does not exist if data == nil or type( data ) ~= 'table' then return utils.error( 'Invalid REQ card "' .. card .. '"! Is there a typo in the name?' ) end -- Retrieve the category local category = data[ 'category' ] -- Return an error message if the REQ card does not match a known category if category == nil or templates[ category ] == nil or type( templates[ category ] ) ~= 'function' then return utils.error( 'Internal data on REQ card "' .. card .. '" invalid!' ) end -- Create the infocard local card = infocard.new.withTitle( 'REQ information' ) -- Pass the card to the relevant template, for it to be filled out templates[ category ]( card, data ) -- Render the card and return return frame:preprocess( card.render ) end

return p