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 19:13, 19 February 2017 (start conversion to concatenation method). 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
		a = "{{WikiProject Central America"
		if args.class then
			a = a .. "| class = " .. args.class
		else
			a = a .. "| class = "
		end
		if args.importance then
			a = a .. "|importance = " .. args.importance
		else
			a = a .. "|importance = "
		end
		if args.attention then
			a = a .. "| attention = " .. args.attention
		end
		if args.needsinfobox then
			a = a .. "| needs-infobox = " .. args.needsinfobox
		end
		if args.small then
			a = a .. "| small = " .. args.small
		end
		if args.listas then
			a = a .. "| listas = " .. args.listas
		end
		if args.category then
			a = a .. "| category = " .. args.category
		end
		print(a)
	end
	
	if i == 1 or i == 2 then
		if args.Belize == "yes" then
			print("{{WikiProject Belize")
			printfd("| class = %s", args.class)
			if args.Belizeimportance then
				printfd("| importance = %s", args.Belizeimportance)
			else
				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")
			printfd("| class = %s", args.class)
			if args.CostaRicaimportance then
				printfd("| importance = %s", args.CostaRicaimportance)
			else
				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")
			printfd("| class = %s", args.class)
			if args.ElSalvadorimportance then
				printfd("| importance = %s", args.ElSalvadorimportance)
			else
				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")
			printfd("| class = %s", args.class)
			if args.Guatemalaimportance then
				printfd("| importance = %s", args.Guatemalaimportance)
			else
				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")
			printfd("| class = %s", args.class)
			if args.Hondurasimportance then
				printfd("| importance = %s", args.Hondurasimportance)
			else
				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")
			printfd("| class = %s", args.class)
			if args.Nicaraguaimportance then
				printfd("| importance = %s", args.Nicaraguaimportance)
			else
				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")
			printfd("| class = %s", args.class)
			if args.Panamaimportance then
				printfd("| importance = %s", args.Panamaimportance)
			else
				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