Module:Arguments

From CG Studios Wiki

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

-- <nowiki>
-- Simple standalone replacement for Module:Arguments

local p = {}

-- Trim helper
local function trim(s)
    return s:match('^%s*(.-)%s*$')
end

-- Get arguments from frame and parent frame
function p.getArgs(frame, options)
    options = options or {}
    local args = {}

    -- First, collect from parent frame (template invocation)
    local parent = frame:getParent()
    if parent then
        for k, v in pairs(parent.args) do
            if type(v) == 'string' then
                v = trim(v)
            end
            if v ~= '' or options.preserveEmpty == true then
                args[k] = v
            end
        end
    end

    -- Then collect from direct module invocation (|arg= inside #invoke)
    for k, v in pairs(frame.args) do
        if type(v) == 'string' then
            v = trim(v)
        end
        if v ~= '' or options.preserveEmpty == true then
            args[k] = v
        end
    end

    return args
end

return p