Module:Stats/REQ: Difference between revisions
From Halopedia, the Halo wiki
No edit summary |
No edit summary |
||
Line 37: | Line 37: | ||
-- Render the card and return | -- Render the card and return | ||
return frame:preprocess( card.render() ) | return mw.text.trim( frame:preprocess( card.render() ) ) | ||
end | end | ||
return p | return p |
Revision as of 17:27, 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 = mw.loadData( 'Module:Stats/REQ/H5G/' .. card )
-- Return an error message if it does not exist
if data == nil or data == {} 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 mw.text.trim( frame:preprocess( card.render() ) )
end
return p