Module:Helper module

From Brighter Shores 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.
Module:Helper module requires Module:Mw.html extension.
Module:Helper module is invoked by Template:Helper module.

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

-- Helps [[Brighter Shores:Lua/Helper modules]] format its table with dynamic documentation
-- See [[Template:Helper module]] for documentation and usage
require('Module:Mw.html extension')
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
	local title = mw.title.getCurrentTitle()
	if title.namespace == 828 and (title.text == or title.text =='/doc') then
		local t = mw.html.create('table')
		t	:addClass('wikitable')
			:node(p._main(, function_list, nil, false))

		local category = ''
		if not (title.isSubpage and title.subpageText == 'doc') then
			category = '[[Category:Helper modules]][[Category:Modules required by modules]]'
		local reqby = ''
		if not (title.isSubpage and title.subpageText == 'doc') then
			local uri = mw.uri.canonicalUrl('Special:WhatLinksHere', 'target=Module:''&namespace=828')
			reqby = 'For a full list of modules using this helper <span class="plainlinks">[' .. tostring(uri) .. ' click here]</span>\n'
		local example = ''
		if args.example then
			example = "'''Example:'''\n" .. args.example
		return 'This module is a helper module to be used by other modules; it may not designed to be invoked directly. See [[Brighter Shores:Lua/Helper modules]] for a full list and more information.\n' .. reqby .. tostring(t) .. example .. category
		return p._main(, function_list, args.example or '', true)

local function formatFuncNames(list)
	list = mw.text.split(list or '', ';;')
	local res = {}

	for _, v in ipairs(list) do
		v = mw.text.trim(v)
		table.insert(res, string.format("<code>%s</code>", v))

	return table.concat(res, '<br>')

function p._main(modn, func_list, example, showModuleName)
	local ret = mw.html.create('tr')
	ret :IF(showModuleName)
			:td{'[[Module:'..modn..'|'..modn..']]', attr={'rowspan', #func_list}} -- Name will group together with all functions once

	for i = 2, #func_list do
	return ret

return p