Modul:Card

Aus Star Citizen Wiki
Modul Dokumentation[view][edit][history][purge]
Diese Dokumentation wird von Modul:Card/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.
Function list
L 9 — checkRequiredArgs
L 20 — methodtable.make
L 50 — Card.new
L 64 — Card.fromArgs

Das Modul Common stellt Funktionen für die Vorlage Card bereit.


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
Cookies helfen uns bei der Bereitstellung dieses Wikis. Durch die Nutzung des Star Citizen Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.