Edge Rewrite
Jump to content

Module:MakeInvokeFunc

Permanently protected module
From Wikipedia, the free encyclopedia

--- This module quickly and easily makes a function invokable in a module.
-- Based on work in [[Module:Documentation]].
--
-- @module MakeInvokeFunc
-- @require Module:Arguments
-- @type function
-- @param {table} p Package
-- @return Invokable function generator
return function(p)
	--- Invokable function generator
	--
	-- @param {string} funcName Name of function
	-- @return Entrypoint for the function
	return function(funcName)
		--- Entrypoint for invokable functions
		--
		-- @param {table} frame Invokable frame
		-- @return Output wikitext for invoked function
		return function (frame)
			local args = require("Module:Arguments").getArgs(frame, {
				valueFunc = function (key, value)
					if type(value) == 'string' then
						value = value:match('^%s*(.-)%s*$') -- Remove whitespace.
						if key == 'heading' or value ~= '' then
							return value
						else
							return nil
						end
					else
						return value
					end
				end
			})
			return p[funcName](args)
		end
	end
end