模块:Utils

来自少前2百科

可在模块:Utils/doc创建此模块的帮助文档

local p = {}

function p.foreach(frame)
    local template = frame.args[1]:gsub('\n$', '')
    template = template:gsub('\\n', '\n')
    template = template:gsub('%(%(!%)%)', '|')
    local ret = ''
    for i, arg in ipairs(frame.args) do
    	arg = arg:gsub('\n$', '')
        if i > 1 and arg ~= '' then
            local text = template:gsub('%(%(%(1%)%)%)', arg)
            ret = ret .. text
        end
    end
    return ret
end

function p.inherit_args(frame)
    local template = frame.args[1]
    local parent = frame:getParent()
    return frame:expandTemplate{title = template, args = parent.args}
end

function p.d()
    local frame = {
        args = { '((!))hello (((1)))\n', 'x\n', 'y\n', 'z' }
    }
    local r = p.foreach(frame)
    mw.log(r)
end

return p