Module:Sandbox/Ahecht/flag

This is an old revision of this page, as edited by Ahecht (talk | contribs) at 04:33, 12 June 2020 (test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p._main(args)
	output = {}
	subcats = {}

	for k,v in pairs(args) do
		k = mw.text.split(k, "-", true)
		if (k[2] or '') ~= '' then
			if not subcats[k[1]] then
				subcats[k[1]] = {}
			end
			subcats[k[1]][#subcats[k[1]] + 1] = '\t\t["' .. table.concat(k,"",2) .. '"] = "' .. v .. '"'
		else
			output[#output+1] = '\t["' .. k[1] .. '"] = "' .. v .. '"'
		end
	end
	
	for k,v in pairs(subcats) do
		output[#output+1] = '\t["' .. k .. '"] = {\n' .. table.concat(v,",\n") .. '\n\t}'
	end

	return output
end


function p.main(frame)
	local args={}
	
	for k,v in pairs(frame:getParent().args) do
		if (v or '') ~= '' then
			args[k] = v
		end
	end
	for k,v in pairs(frame.args) do
		if (v or '') ~= '' then
			args[k] = v
		end
	end
	
	if args.alias then
		output = p._main(args)
		return '<pre>["' .. args.alias .. '"] = {\n' .. table.concat(output,",\n") .. '\n},\n</pre>'
	else
		return ""
	end
end

return p