Module:Databox Gravestone

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Databox Gravestone/doc. [edit]
Module:Databox Gravestone's function main is invoked by Template:Databox Gravestone.
Module:Databox Gravestone requires Module:Infobox.
Module:Databox Gravestone requires Module:Mainonly.
Function list
L 10 — p.main
L 84 — costlinearg
L 94 — addcategories
L 95 — is_def

--------------------------
-- Module for [[Template:Databox Gravestone]]
------------------------
local p = {}

-- "imports"
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 = 'vanchor', func = { name = 'has_content', params = { 'version' }, flag = 'p' } },
		{ name = 'seller', func = 'has_content' },
		{ name = 'cost', func = 'has_content' },
		{ name = 'currency', func = 'has_content' },
		{ name = 'costline', func = { name = costlinearg, params = { 'cost', 'currency' } } },
		{ name = 'duration', func = 'has_content' },
		{ name = 'message', func = 'has_content' },
		{ name = 'description', func = 'has_content' }
	}

	ret:setMaxButtons(4)
	ret:setAddRSWDataboxClass(true)
	ret:create()
	ret:cleanParams()
	ret:customButtonPlacement(true)
	
	ret:defineLinks({ links = {{ 'Template:%s', 'Databox' },
		{ 'Template_talk:%s', 'Talk page' }}, colspan = '2' })

	ret:defineName('Databox Gravestone')
	ret:addClass('wikitable')

	ret:addButtonsCaption()

	-- PARAMETER: name
	ret:addRow{
		{ tag = 'argh', content = 'name', colspan = '2', class = 'infobox-header' }
	}

	-- PARAMETER: seller
	ret:addRow{
		{ tag = 'th', content = 'Seller' },
		{ tag = 'argd', content = 'seller' }
	}
	
	-- PARAMETER: costline
	:addRow{
		{ tag = 'th', content = 'Cost' },
		{ tag = 'argd', content = 'costline' }
	}
	
	-- PARAMETER: duration
	ret:addRow{
		{ tag = 'th', content = 'Duration' },
		{ tag = 'argd', content = 'duration' }
	}
	
	-- PARAMETER: message
	:addRow{
		{ tag = 'th', content = 'Message' },
		{ tag = 'argd', content = 'message' }
	}
	
	-- PARAMETER: description
	:addRow{
		{ tag = 'th', content = 'Description' },
		{ tag = 'argd', content = 'description' }
	}
	
	ret:finish()
	if onmain() then
		local a1 = ret:param('all')
		local a2 = ret:categoryData()
		ret:wikitext(addcategories(a1, a2))
	end
	return ret:tostring()
end

function costlinearg(cost, currency)
	if infobox.isDefined(cost) then
		local costline = cost .. ' '
		if infobox.isDefined(currency) then
			return costline .. currency
		end
		return costline .. 'coins'
	end
end

function addcategories(args, catargs)
	function is_def(x, y)
		y = y or 'd'
		if infobox.isDefined(x) then
			return infobox.isDefined(x[y])
		end
		return false
	end
	
	local ret = { 'Gravestones' }
	
	local cat_map = {
		-- Added if the parameter has content
		defined = {
		},
		-- Added if the parameter has no content
		notdefined = {
		},
	}
	
	-- Run and add mapped categories
	for n, v in pairs(cat_map.defined) do
		if catargs[n] and catargs[n].one_defined then
			table.insert(ret,v)
		end
	end
	for n, v in pairs(cat_map.notdefined) 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