Module:Sandbox/ProcrastinatingReader/Dbm

This is an old revision of this page, as edited by ProcrastinatingReader (talk | contribs) at 13:34, 9 September 2020 (that note too). 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 function constructCsdTable(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)
	csdList = constructCsdTable(args)

    local requestedReasons = {}
    for k,v in pairs(csdList) do
    	table.insert(requestedReasons, frame:expandTemplate{ title = 'Db-'..string.lower(k), args = {
    		['raw'] = 'yes',
            ['rationale'] = v['rationale'] or '',
            ['nocat'] = 'true'													-- for test purposes
        }})

        --if true then return mw.dumpObject(dbtemplate) end
    end
    
    local dbTemplate = frame:expandTemplate{ title = 'Db-meta', args = {
    		[1] = '&#32;for the following reasons:</b><ul><li>'..table.concat(requestedReasons, '</li><li>') .. '</li></ul> <b>The page may be deleted under any criterion that is valid',
    		['criterion'] = 'NA',
            ['nocat'] = 'true'													-- for test purposes
        }}
    return dbTemplate
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