Module:Helper module

From Discord Dungeons Wiki
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Helper module/doc. [edit] [history] [purge]
Module:Helper module's function main is invoked by Template:Helper module.
{{#replace:Module:Helper module|/doc}} is invoked by Template:Helper module.

Generates helper module information for use in documentation, which is automatically used by DD_Wiki:Lua/Helper modules.


-- <nowiki>
-- Helps [[DD_Wiki:Lua/Helper modules]] format its table with dynamic documentation
-- See [[Template:Helper module]] for documentation and usage
local p = {}

function p.main(frame)
	local args = frame:getParent().args
	local function_list = {}
	-- Let there be no limit to number of parameters
	local i = 1
	while args['fname'..i] do
		local funcname = args['fname'..i] or ''
		local functype = args['ftype'..i] or ''
		local funcuse = args['fuse'..i] or ''
		function_list[i] = {
				fname = funcname,
				ftype = functype,
				fdesc = funcuse
		}
		i = i + 1
	end
	local title = mw.title.getCurrentTitle()
	if title.namespace == 828 and (title.text == args.name or title.text == args.name..'/doc') then
		local t = mw.html.create('table')
		t	:addClass('wikitable')
			:tag('tr')
				:tag('th'):wikitext('Module'):done()
				:tag('th'):wikitext('Function'):done()
				:tag('th'):wikitext('Type'):done()
				:tag('th'):wikitext('Use'):done()
			:done()
			:wikitext(p._main(args.name,function_list))
		local category = ''
		if not (title.isSubpage and title.subpageText == 'doc') then
			category = '[[Category:Helper modules]]'
		end
		return 'This module is a helper module to be used by other modules; it may not be designed to be invoked directly. See [[RuneScape:Lua/Helper modules]] for a full list and more information.\n' .. tostring(t) .. category
	else
		return p._main(args.name,function_list)
	end
end

function p._main(modn,func_list)
	local ret_row = mw.html.create('tr')
				:tag('td')
					-- Name will group together with all functions once
					:attr('rowspan',#func_list)
					:wikitext('[[Module:'..modn..'|'..modn..']]')
				:done()
				:tag('td')
					:tag('code')
						:wikitext(func_list[1].fname)
					:done()
				:done()
				:tag('td')
					:wikitext(func_list[1].ftype)
				:done()
				:tag('td')
					:wikitext(func_list[1].fdesc)
				:done()
			:done()
	local ret = tostring(ret_row)
	for i=2,#func_list,1 do
		local next_row = mw.html.create('tr')
				:tag('td')
					:tag('code')
						:wikitext(func_list[i].fname)
					:done()
				:done()
				:tag('td')
					:wikitext(func_list[i].ftype)
				:done()
				:tag('td')
					:wikitext(func_list[i].fdesc)
				:done()
			:done()
		ret = ret..tostring(next_row)
	end
	return ret
end

return p