Module:Helper module
Jump to navigation
Jump to search
Module documentation
This documentation is transcluded from Module:Helper module/doc. [edit] [purge]
Module:Helper module's function main is invoked by Template:Helper module.
Module:Helper module requires Module:Mw.html extension.
Module:Helper module requires Module:Tooltip.
Generates helper module information for use in documentation, which is automatically used by GSWiki:Lua/Helper modules.
-- <nowiki> -- Helps [[GSWiki:Lua/Helper modules]] format its table with dynamic documentation -- See [[Template:Helper module]] for documentation and usage require('Module:Mw.html extension') local tooltip = require('Module:Tooltip') 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() :IF(args.example) :tag('th'):wikitext('Example'):done() :END() :done() :wikitext(p._main(args.name, function_list, args.example or 'no example cell')) local category = '' if not (title.isSubpage and title.subpageText == 'doc') then category = '[[Category:Helper modules]][[Category:Modules required by modules]]' end local reqby = '' if not (title.isSubpage and title.subpageText == 'doc') then local uri = mw.uri.canonicalUrl('Special:WhatLinksHere', 'target=Module:'..args.name..'&namespace=828') reqby = 'For a full list of modules using this helper <span class="plainlinks">[' .. tostring(uri) .. ' click here]</span>\n' end return 'This module is a helper module to be used by other modules; it may not designed to be invoked directly. See [[GSWiki:Lua/Helper modules]] for a full list and more information.\n' .. reqby .. tostring(t) .. category else return p._main(args.name, function_list, args.example) end end 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)) end return table.concat(res, '<br>') end function p._main(modn, func_list, example) 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') :wikitext(formatFuncNames(func_list[1].fname)) :done() :tag('td') :wikitext(func_list[1].ftype) :done() :tag('td') :wikitext(func_list[1].fdesc) :done() :IF(example ~= 'no example cell') :tag('td') :attr('rowspan',#func_list) :IF(example) :wikitext(tostring(tooltip._span{ name = modn, alt = 'Click to view'}), tostring(tooltip._div{name = modn, limitwidth = 'no', content = '<br>' .. (example or '')})) :END() :done() :END() :done() local ret = tostring(ret_row) for i=2,#func_list,1 do local next_row = mw.html.create('tr') :tag('td') :wikitext(formatFuncNames(func_list[i].fname)) :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