Actions

Module

Module:Chain

From Project Rebearth

Revision as of 13:57, 26 February 2026 by East6 (talk | contribs) (Created page with "local p = {} function p.render(frame) local args = frame.args local parent = frame:getParent() local pargs = parent and parent.args or {} local items = {} for i = 1, 15 do local val = args[i] or pargs[i] if val then val = mw.text.trim(val) if val ~= '' then items[#items + 1] = val end end end if #items < 1 then return '' end local title = args.title...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Chain/doc

local p = {}

function p.render(frame)
    local args = frame.args
    local parent = frame:getParent()
    local pargs = parent and parent.args or {}

    local items = {}
    for i = 1, 15 do
        local val = args[i] or pargs[i]
        if val then
            val = mw.text.trim(val)
            if val ~= '' then
                items[#items + 1] = val
            end
        end
    end

    if #items < 1 then
        return ''
    end

    local title = args.title or pargs.title or ''
    title = mw.text.trim(title)

    local direction = args.direction or pargs.direction or ''
    direction = mw.text.trim(direction):lower()
    local isVertical = (direction == 'vertical')

    local root = mw.html.create('div')
        :addClass('rb-chain')
    if isVertical then
        root:addClass('rb-chain-vertical')
    end

    if title ~= '' then
        root:tag('div')
            :addClass('rb-chain-title')
            :wikitext(title)
    end

    for i, name in ipairs(items) do

        if i > 1 then
            root:tag('div')
                :addClass('rb-chain-arrow')
                :wikitext('→')
        end

        local isResource = (i % 2 == 1)  

        local step = root:tag('div')
            :addClass('rb-chain-step')

        if isResource then
            step:addClass('rb-chain-resource')

            local icon = frame:expandTemplate{ title = 'Icon', args = { name } }
            step:tag('span')
                :addClass('rb-chain-icon')
                :wikitext(icon)
            step:tag('span')
                :addClass('rb-chain-label')
                :wikitext('[[' .. name .. ']]')
        else
            step:addClass('rb-chain-building')

            step:tag('span')
                :addClass('rb-chain-label')
                :wikitext('[[' .. name .. ']]')
        end
    end

    return tostring(root)
end

return p