Módulo:Helper module

De RuneScape Wiki
Ir para: navegação, pesquisa
Documentação de predefinição
Esta documentação é transcrita de Módulo:Helper module/doc. [editar] [atualizar]
Módulo:Helper module evoca Módulo:Helper module usando Lua.

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


-- <nowiki>
-- Helps [[RuneScape: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('Módulo'):done()
				:tag('th'):wikitext('Função'):done()
				:tag('th'):wikitext('Tipo'):done()
				:tag('th'):wikitext('Uso'):done()
			:done()
			:wikitext(p._main(args.name,function_list))
		local category = ''
		if not (title.isSubpage and title.subpageText == 'doc') then
			category = '[[Categoria:Módulos de apoio]]'
		end
		return 'This module is a helper module to be used by other modules; it may not 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