Star Citizen Wiki Modul:NavHeader
Wir laden dich herzlich auf den Star Citizen Wiki Discord Server ein! Du kannst uns auch auf unserem neuen YouTube-Chanel finden!

Modul:NavHeader

Aus Star Citizen Wiki

Dokumentation unvollständig.


local NavHeader = {}

local metatable = {}
local methodtable = {}

metatable.__index = methodtable

--- Parse an argument to the recognized format
--- @param arg table|string|nil
--- @return table
local function parseArg( arg )
    if arg == nil then
        return nil
    end

    if type( arg ) == 'table' then
        return {
            [ 'link' ] = tostring( arg[ 1 ] ),
            [ 'text' ] = tostring( arg[ 2 ] ),
            [ 'external' ] = arg[ 3 ] or false
        }
    end

    return {
        [ 'link' ] = tostring( arg ),
        [ 'text' ] = nil,
        [ 'external' ] = false,
    }
end

--- Make a link from data
--- @param dataTable table
--- @return string
local function makeLink( dataTable, isPrev )
    if dataTable == nil then
        return ''
    end

    if dataTable.link == nil then
        error( 'Link must be set' )
    end

    local left = '[['
    local right = ']]'

    if dataTable.external ~= false then
        left = '['
        right = ']'
    end

    local text = ''
    if dataTable.text ~= nil then
        if dataTable.external ~= false then
            text = ' ' .. text
        else
            text = '|' .. text
        end
    end

    local out = left .. mw.text.trim( dataTable.link, '%[%]' ) .. text .. right
    
    local hasArrow = mw.ustring.find( out, '«', 0, true ) or mw.ustring.find( out, '»', 0, true )
    
    if not hasArrow then
    	if isPrev == true then
    		out = '« ' .. out
    	elseif isPrev == false then
    		out = out .. ' »'
    	end
	end

	return out
end


--- Makes the html table
--- @return string
function methodtable.make( self )
    local div = mw.html.create( 'div' )
            :attr( 'class', 'nav-header' )
            :tag( 'span' )
                :wikitext( makeLink( self.prevLink, true ) )
            :done()
            :tag( 'span' )
                :wikitext( makeLink( self.mainLink ) )
            :done()
            :tag( 'span' )
                :wikitext( makeLink( self.nextLink, false ) )
            :done()

    return tostring( div )
end


--- New Instance
--- @return table NavHeader
function NavHeader.new( self, prev, main, next )
    local instance = {
        prevLink = parseArg( prev ),
        mainLink = parseArg( main ),
        nextLink = parseArg( next )
    }

    setmetatable( instance, metatable )

    return instance
end

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

    local instance = NavHeader:new(
        args[ 1 ] or args[ 'prev' ],
        args[ 2 ] or args[ 'main' ],
        args[ 3 ] or args[ 'next' ]
    )

    return instance:make()
end

return NavHeader
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.