Module:Infobox Prayer

From RuneScape Classic Wiki
Jump to: navigation, search

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

--------------------------
-- Module for [[Template:Infobox Prayer]]
------------------------
local p = {}

local onmain = require('Module:Mainonly').on_main
local infobox = require('Module:Infobox')

function p.main(frame)
	local args = frame:getParent().args
	local ret = infobox.new(args)

	ret:defineParams{
		{ name = 'name', func = 'name' },
		{ name = 'release', func = 'release' },
		{ name = 'level', func = 'has_content' },
		{ name = 'effect', func = 'has_content' },
		{ name = 'drain', func = 'has_content' },
	}

	ret:defineLinks({ hide = true })

	ret:create()
	ret:cleanParams()

	ret:customButtonPlacement(true)
	ret:addButtonsCaption()

	ret:defineName('Infobox Prayer')
	ret:addClass('infobox-prayer')

	ret:addRow{
		{ tag = 'argh', content = 'name', class='infobox-header', colspan = '5' }
	}
	:pad(5)

	ret:addRow{
		{ tag = 'th', content = 'Released', colspan = '2' },
		{ tag = 'argd', content = 'release', colspan = '3' }
	}
	:addRow{
		{ tag = 'th', content = 'Prayer level', colspan = '2' },
		{ tag = 'argd', content = 'level', colspan = '3' }
	}
	:addRow{
		{ tag = 'th', content = 'Effect', colspan = '2' },
		{ tag = 'argd', content = 'effect', colspan = '3' }
	}
	:addRow{
		{ tag = 'th', content = 'Drain rate', colspan = '2' },
		{ tag = 'argd', content = 'drain', colspan = '3' }
	}
	:pad(5)

	if onmain() then
		local a1 = ret:param('all')
		local a2 = ret:categoryData()
		ret:wikitext(addcategories(a1, a2))
	end
	return ret:tostring()
end

function addcategories(args, catargs)
	local ret = { 'Prayer' }

 	-- Add the associated category if the parameter doesn't have content
 	local notdefined_args = {
 		release = 'Needs release date',
 	}
	for n, v in pairs(notdefined_args) do
		if catargs[n] and catargs[n].all_defined == false then
			table.insert(ret, v)
		end
	end

	-- combine table and format category wikicode
	for i, v in ipairs(ret) do
		if (v ~= '') then
			ret[i] = string.format('[[Category:%s]]', v)
		end
	end

	return table.concat(ret, '')
end

return p