Modul:Card

Aus Steel Beasts Wiki

Die Dokumentation für dieses Modul kann unter Modul:Card/Doku erstellt werden

local Card = {}

local metatable = {}
local methodtable = {}

metatable.__index = methodtable


local function checkRequiredArgs( args )
    local titleExists = args['Titel'] ~= nil or args['title'] ~= nil or args[1] ~= nil
    local bodyExists = args['Inhalt'] ~= nil or args['body'] ~= nil or args[2] ~= nil

    return titleExists and bodyExists
end


--- Outputs the card
---
--- @return string
function methodtable.make( self )
    if not checkRequiredArgs( self.args ) then
        return '<p class="hatnote">Die Argumente "Titel" und "Inhalt" müssen ausgefüllt sein.</p>'
    end

    local bodyClass = 'card-body'
    if self.args['Großes Erstes Bild'] ~= nil or self.args['hero_first_image'] ~= nil or self.args[3] ~= nil then
    	bodyClass = bodyClass .. ' card-body__hero-image'
	end

    local div = mw.html.create( 'div' )

    div
        :addClass( 'card' )
        :tag( 'h4' )
            :addClass( 'card-header' )
            :wikitext( self.args['Titel'] or self.args['title'] or self.args[1] )
            :done()
        :tag( 'div' )
            :addClass( bodyClass )
            :wikitext( self.args['Inhalt'] or self.args['body'] or self.args[2] )
            :done()
        :done()

    return mw.text.trim( tostring( div ) )
end


--- New Instance
--- @return table Card
function Card.new( self, frameArgs )
    local instance = {
        args = frameArgs,
    }

    setmetatable( instance, metatable )

    return instance
end


--- Entry for module calls
---
--- @return string
function Card.fromArgs( frame )
    local args = require( 'Module:Arguments ').getArgs( frame )

    local instance = Card:new( args )

    return instance:make()
end


return Card