Module:Sister project

From Path of Exile 2 Wiki
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]


Implements {{sister}}

-------------------------------------------------------------------------------
-- 
--                            Module:Sister project
-- 
-- This module implements Template:Sister
-------------------------------------------------------------------------------

local c = {}

c.projects = {
    poewiki = {
        param = 'poewiki',
        interwiki = 'poewiki',
        name = 'Path of Exile Wiki',
    },
}

c.display_order = {'poewiki'}

-- ----------------------------------------------------------------------------
-- Main functions
-- ----------------------------------------------------------------------------

local function _sister(args)
    local pagename = mw.title.getCurrentTitle().fullText
    local params = {}
    local selected = {}
    for k, v in pairs(c.projects) do
        params[v.param] = true
        if args[v.param] and not selected[k] then
            selected[k] = args[v.param]
        end
    end
    for _, v in ipairs(args) do
        if params[v] and not selected[v] then
            selected[v] = pagename
        end
    end
    local html = mw.html.create('div')
    html
        :addClass('noexcerpt noprint nomobile navigation-not-searchable js-sister-data')
        :css('display', 'none')
    for _, v in ipairs(c.display_order) do
        if selected[v] then
            local span = html:tag('span')
            span:attr({
                ['data-project'] = c.projects[v].name,
                ['data-interwiki'] = c.projects[v].interwiki,
                ['data-page'] = selected[v],
            })

        end
    end
    return tostring(html)
end

-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------

local p = {}

function p.sister(frame)
    local args
    if type(frame.args) == 'table' then
        -- Called via #invoke, so use the parent args (those that were passed 
        -- into the template. Ignore args passed to #invoke.
        args = frame:getParent().args
    else
        -- Called from another module or from the debug console, so assume args 
        -- are passed in directly.
        args = frame
    end
    return _sister(args)
end

return p