Jump to content

Module:Sandbox/BU Rob13

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Renamed user mou89p43twvqcvm8ut9w3 (talk | contribs) at 20:08, 12 February 2017 (add support for country importance). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- [SublimeLinter luacheck-globals:mw]

-- This module serves to convert [[Template:WikiProject Central America]] from
-- using country task forces to the new country WikiProject templates.
-- Due to some changes of parameters needed for this module to run, it
-- SHOULD NOT be run by anyone other than the module author without consultation
-- Direct questions to User talk:BU Rob13.

local p = {}
local getBuffer, print = require("Module:OutputBuffer")()

local function printfd(formatString, ...)
	local default = ""

	local args, argsNum = {...}, select("#", ...)
	local newArgs = {}
	for i = 1, argsNum do
		if args[i] ~= nil then
			table.insert(newArgs, args[i])
		else
			table.insert(newArgs, default)
		end
	end
	print(string.format(formatString, unpack(newArgs)))
end

function p._main(args)
	local i = 0
	if args.Belize == "yes" then
		i = i + 1
	end
	if args.CostaRica == "yes" then
		i = i + 1
	end
	if args.ElSalvador == "yes" then
		i = i + 1
	end
	if args.Guatemala == "yes" then
		i = i + 1
	end
	if args.Honduras == "yes" then
		i = i + 1
	end
	if args.Nicaragua == "yes" then
		i = i + 1
	end
	if args.Panama == "yes" then
		i = i + 1
	end
	
	if i == 0 or i > 2 then
		print("{{WikiProject Central America")
		if args.class then
			printfd("| class = %s", args.class)
		end
		if args.importance then
			printfd("| importance = %s", args.importance)
		end
		if args.attention then
			printfd("| attention = %s", args.attention)
		end
		if args.needsinfobox then
			printfd("| needs-infobox = %s", args.needsinfobox)
		end
		if args.small then
			printfd("| small = %s", args.small)
		end
		if args.listas then
			printfd("| listas = %s", args.listas)
		end
		if args.category then
			printfd("| category = %s", args.category)
		end
		print("}}")
	end
	
	if i == 1 or i == 2 then
		if args.Belize == "yes" then
			print("{{WikiProject Belize")
			if args.class then
				printfd("| class = %s", args.class)
			end
			if args.Belizeimportance then
				printfd("| importance = %s", args.Belizeimportance)
			elseif args.importance then
				printfd("| importance = %s", args.importance)
			end
			if args.small then
				printfd("| small = %s", args.small)
			end
			if args.listas then
				printfd("| listas = %s", args.listas)
			end
			if args.category then
				printfd("| category = %s", args.category)
			end
			print("}}")
		end
		if args.CostaRica == "yes" then
			print("{{WikiProject Costa Rica")
			if args.class then
				printfd("| class = %s", args.class)
			end
			if args.CostaRicaimportance then
				printfd("| importance = %s", args.CostaRicaimportance)
			elseif args.importance then
				printfd("| importance = %s", args.importance)
			end
			if args.small then
				printfd("| small = %s", args.small)
			end
			if args.listas then
				printfd("| listas = %s", args.listas)
			end
			if args.category then
				printfd("| category = %s", args.category)
			end
			print("}}")
		end
		if args.ElSalvador == "yes" then
			print("{{WikiProject El Salvador")
			if args.class then
				printfd("| class = %s", args.class)
			end
			if args.ElSalvadorimportance then
				printfd("| importance = %s", args.ElSalvadorimportance)
			elseif args.importance then
				printfd("| importance = %s", args.importance)
			end
			if args.small then
				printfd("| small = %s", args.small)
			end
			if args.listas then
				printfd("| listas = %s", args.listas)
			end
			if args.category then
				printfd("| category = %s", args.category)
			end
			print("}}")
		end
		if args.Guatemala == "yes" then
			print("{{WikiProject Guatemala")
			if args.class then
				printfd("| class = %s", args.class)
			end
			if args.Guatemalaimportance then
				printfd("| importance = %s", args.Guatemalaimportance)
			elseif args.importance then
				printfd("| importance = %s", args.importance)
			end
			if args.small then
				printfd("| small = %s", args.small)
			end
			if args.listas then
				printfd("| listas = %s", args.listas)
			end
			if args.category then
				printfd("| category = %s", args.category)
			end
			print("}}")
		end
		if args.Honduras == "yes" then
			print("{{WikiProject Honduras")
			if args.class then
				printfd("| class = %s", args.class)
			end
			if args.Hondurasimportance then
				printfd("| importance = %s", args.Hondurasimportance)
			elseif args.importance then
				printfd("| importance = %s", args.importance)
			end
			if args.small then
				printfd("| small = %s", args.small)
			end
			if args.listas then
				printfd("| listas = %s", args.listas)
			end
			if args.category then
				printfd("| category = %s", args.category)
			end
			print("}}")
		end
		if args.Nicaragua == "yes" then
			print("{{WikiProject Nicaragua")
			if args.class then
				printfd("| class = %s", args.class)
			end
			if args.Nicaraguaimportance then
				printfd("| importance = %s", args.Nicaraguaimportance)
			elseif args.importance then
				printfd("| importance = %s", args.importance)
			end
			if args.small then
				printfd("| small = %s", args.small)
			end
			if args.listas then
				printfd("| listas = %s", args.listas)
			end
			if args.category then
				printfd("| category = %s", args.category)
			end
			print("}}")
		end
		if args.Panama == "yes" then
			print("{{WikiProject Panama")
			if args.class then
				printfd("| class = %s", args.class)
			end
			if args.Panamaimportance then
				printfd("| importance = %s", args.Panamaimportance)
			elseif args.importance then
				printfd("| importance = %s", args.importance)
			end
			if args.small then
				printfd("| small = %s", args.small)
			end
			if args.listas then
				printfd("| listas = %s", args.listas)
			end
			if args.category then
				printfd("| category = %s", args.category)
			end
			print("}}")
		end
	end

	return getBuffer("\n")
end

function p.main(frame)
	local args = require("Module:Arguments").getArgs(frame)
	return p._main(args)
end

return p