Module:Stats/REQ: Difference between revisions
From Halopedia, the Halo wiki
No edit summary |
No edit summary |
||
(11 intermediate revisions by the same user not shown) | |||
Line 13: | Line 13: | ||
-- Load the REQ data from the correct module page | -- Load the REQ data from the correct module page | ||
local card = tostring( frame.args[1] ) | local card = tostring( frame.args[1] ) | ||
local | local data = utils.loadDataIfExists( 'Module:Stats/REQ/H5G/' .. card ) | ||
-- Return an error message if it does not exist | -- Return an error message if it does not exist | ||
if | if data == nil or type( data ) ~= 'table' then | ||
return utils.error( 'Invalid REQ card "' .. card .. '"! Is there a typo in the name?' ) | return utils.error( 'Invalid REQ card "' .. card .. '"! Is there a typo in the name?' ) | ||
end | end | ||
Line 37: | Line 37: | ||
-- Render the card and return | -- Render the card and return | ||
return | return frame:preprocess( card.render() ) | ||
end | end | ||
return p | return p |
Latest revision as of 18:36, September 28, 2020
Documentation for this module may be created at ModuleDoc: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