Module:Module introspection: Difference between revisions
mNo edit summary |
normalize arg names to snake case |
||
| Line 314: | Line 314: | ||
function p._module_introspection(args) | function p._module_introspection(args) | ||
local args = args or {} | local args = args or {} | ||
local module_name = args[" | local module_name = args["module_name" ] | ||
local main_function = args[" | local main_function = args["main_function"] | ||
local descriptions = args[" | local descriptions = args["descriptions" ] | ||
-- Preprocess module and blank-out comments | -- Preprocess module and blank-out comments | ||
| Line 367: | Line 367: | ||
-- Get module name from arguments, or default to current page | -- Get module name from arguments, or default to current page | ||
local module_name = args[" | local module_name = args["module_name"] or mw.title.getCurrentTitle().text | ||
-- Strip trailing "/doc" if the template is used on a documentation subpage | -- Strip trailing "/doc" if the template is used on a documentation subpage | ||
| Line 376: | Line 376: | ||
-- is used for function names. (If this fails, it can be entered manually.) | -- is used for function names. (If this fails, it can be entered manually.) | ||
local normalized_name = module_name:gsub("[^%w]", "_"):lower() | local normalized_name = module_name:gsub("[^%w]", "_"):lower() | ||
local main_function = args[" | local main_function = args["main_function"] or "_" .. normalized_name | ||
-- Process all function descriptions, if provided as desc_function_name | -- Process all function descriptions, if provided as desc_function_name | ||
| Line 389: | Line 389: | ||
-- Return | -- Return | ||
local result = p._module_introspection({ | local result = p._module_introspection({ | ||
[" | ["module_name" ] = module_name, | ||
[" | ["main_function"] = main_function, | ||
[" | ["descriptions" ] = func_descriptions | ||
}) | }) | ||