Module:Goetia

From para.wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Goetia/doc

require "string"
require "table"

local p = {}

local COLUMNS = 9

function p.entry(frame)
	local args
	
	-- If called via #invoke, use the args passed into the invoking template.
	-- Otherwise, for testing purposes, assume args are being passed directly in.
	if frame == mw.getCurrentFrame() then
		args = frame:getParent().args
	else
		args = frame
	end
	
	return args[1] .. ";[[File:" .. args[2] .. "]]"
end

function p.all(frame)
	local args
	
	-- If called via #invoke, use the args passed into the invoking template.
	-- Otherwise, for testing purposes, assume args are being passed directly in.
	if frame == mw.getCurrentFrame() then
		args = frame:getParent().args
	else
		args = frame
	end
	
	local col = 0
	local sigils = ""
	local pages = ""
	local rows = {}
	
	for k, v in ipairs(args) do
		data = mw.text.split(v, ";", true)
		
		sigils = sigils .. "\n|" .. data[2]
		pages = pages .. "\n|" .. data[1]
		
		col = col + 1
		if col >= COLUMNS then
			col = 0
			rows.insert(sigils .. "\n|-" .. pages)
			sigils = ""
			pages = ""
		end
	end
	
	if col ~= 0 then
		table.insert(rows, sigils .. "\n|-" .. pages)
	end
	
	return "{|" .. mw.text.listToText(rows, "\n|-", "") .. "\n|}\n"
end

return p