Module:Sandbox/ProcrastinatingReader/Dbm

This is an old revision of this page, as edited by ProcrastinatingReader (talk | contribs) at 13:05, 9 September 2020 (split func). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}
local getArgs = require('Module:Arguments').getArgs
local tWrapper = require('Module:Template wrapper')

local function constructArgs(args)
	local tbl = {}
    local current = ''
    for k,v in pairs(args) do
        if string.match(v, '[GgAaFfCcUuRrTtPp]%d%d?') then
            current = v
            tbl[current] = {}
        else
        	local arg = mw.text.split(v, '=')
        	tbl[current][arg[1]] = arg[2]
        end
    end
    
    return tbl
end

local function build(frame, args)
	args = constructArgs(args)

    local out = mw.html.create('')
    for k,v in pairs(args) do
        out:newline():wikitext(tWrapper.wrap(frame:newChild{ title = frame:getTitle(), args = {
            ['_template'] = 'db-'..mw.ustring.lower(k),
            ['raw'] = 'yes',
            ['rationale'] = 'test'
        }}))
    end

    return out
end

-- Exports

function p.main(frame)
	local args = getArgs(frame)
	return build(frame, args)
end

function p.dump(frame)
	return mw.dumpObject(mw.text.unstripNoWiki(frame.args[1]))
end

return p