Module:Dochead: Difference between revisions
add newline to avoid breaking adjacent templates |
bugfix removing /doc |
||
| Line 65: | Line 65: | ||
-- Check whether corresponding template exists | -- Check whether corresponding template exists | ||
-- Then check whether that template invokes the module | -- Then check whether that template invokes the module | ||
local has_template = iutils.page_exists("Template:" .. corr_template) | local has_template = iutils.page_exists("Template:" .. corr_template:gsub("/doc$", "")) | ||
-- Check whether to use detect_corr_page option | -- Check whether to use detect_corr_page option | ||
| Line 76: | Line 76: | ||
-- If the module has a template, check for whether it invokes it. | -- If the module has a template, check for whether it invokes it. | ||
if has_template then | if has_template then | ||
local wikitext = iutils.get_and_preprocess_content("Template", corr_template) | local wikitext = iutils.get_and_preprocess_content("Template", corr_template:gsub("/doc$", "")) | ||
local invokes = iutils.find_invokes(wikitext) | local invokes = iutils.find_invokes(wikitext) | ||
has_template = has_template and iutils.invocation_exists(invokes, pagename) | has_template = has_template and iutils.invocation_exists(invokes, pagename:gsub("/doc$", "")) | ||
end | end | ||
| Line 100: | Line 100: | ||
result = string.format( | result = string.format( | ||
"This module may be invoked by templates using its corresponding template [[Template:%s]], or used directly from other modules.", | "This module may be invoked by templates using its corresponding template [[Template:%s]], or used directly from other modules.", | ||
corr_template | corr_template:gsub("/doc$", "") | ||
) | ) | ||
else | else | ||
result = string.format( | result = string.format( | ||
"This module has a corresopnding template that is currently missing or does not use this module. ([[Special:EditPage/Template:%s|edit template]])", | "This module has a corresopnding template that is currently missing or does not use this module. ([[Special:EditPage/Template:%s|edit template]])", | ||
corr_template | corr_template:gsub("/doc$", "") | ||
) | ) | ||
end | end | ||
| Line 113: | Line 113: | ||
result = string.format( | result = string.format( | ||
"This module implements a metatemplate, and may be invoked by templates using its corresponding template [[Template:%s]], or used directly from other modules.", | "This module implements a metatemplate, and may be invoked by templates using its corresponding template [[Template:%s]], or used directly from other modules.", | ||
corr_template | corr_template:gsub("/doc$", "") | ||
) | ) | ||
else | else | ||
| Line 123: | Line 123: | ||
result = string.format( | result = string.format( | ||
"This module should not be invoked directly; use its corresponding instead: [[Template:%s]].", | "This module should not be invoked directly; use its corresponding instead: [[Template:%s]].", | ||
corr_template | corr_template:gsub("/doc$", "") | ||
) | ) | ||
else | else | ||
result = string.format( | result = string.format( | ||
"This module implements a template that is currently missing or does not use this module. ([[Special:EditPage/Template:%s|edit template]])", | "This module implements a template that is currently missing or does not use this module. ([[Special:EditPage/Template:%s|edit template]])", | ||
corr_template | corr_template:gsub("/doc$", "") | ||
) | ) | ||
end | end | ||
| Line 137: | Line 137: | ||
else | else | ||
if has_template and header ~= "" then | if has_template and header ~= "" then | ||
result = string.format("%s This module implements [[Template:%s]].", header, corr_template) | result = string.format("%s This module implements [[Template:%s]].", header, corr_template:gsub("/doc$", "")) | ||
elseif has_template and header == "" then | elseif has_template and header == "" then | ||
result = string.format("This module implements [[Template:%s]].", corr_template) | result = string.format("This module implements [[Template:%s]].", corr_template:gsub("/doc$", "")) | ||
else | else | ||
result = header | result = header | ||
| Line 192: | Line 192: | ||
-- Check whether corresponding module exists | -- Check whether corresponding module exists | ||
-- Then check whether this template invokes the module | -- Then check whether this template invokes the module | ||
local has_module = iutils.page_exists("Module:" .. corr_module) | local has_module = iutils.page_exists("Module:" .. corr_module:gsub("/doc$", "")) | ||
-- Check whether to use detect_corr_page option | -- Check whether to use detect_corr_page option | ||
| Line 204: | Line 204: | ||
-- Check for whether the template invokes that module, regardless of whether | -- Check for whether the template invokes that module, regardless of whether | ||
-- it uses the corresponding module. | -- it uses the corresponding module. | ||
local wikitext = iutils.get_and_preprocess_content("Template", pagename) | local wikitext = iutils.get_and_preprocess_content("Template", pagename:gsub("/doc$", "")) | ||
local invokes = iutils.find_invokes(wikitext) | local invokes = iutils.find_invokes(wikitext) | ||
local is_module_invoked = iutils.invocation_exists(invokes, corr_module) | local is_module_invoked = iutils.invocation_exists(invokes, corr_module:gsub("/doc$", "")) | ||
-- Heading meanings and usage on templates | -- Heading meanings and usage on templates | ||
| Line 226: | Line 226: | ||
result = string.format( | result = string.format( | ||
"This template is implemented by the Lua module [[Module:%s]]. See its module page for Lua-based template implementation.", | "This template is implemented by the Lua module [[Module:%s]]. See its module page for Lua-based template implementation.", | ||
corr_module | corr_module:gsub("/doc$", "") | ||
) | ) | ||
elseif has_module and not is_module_invoked then | elseif has_module and not is_module_invoked then | ||
result = string.format( | result = string.format( | ||
"This template has a corresponding Lua module [[Module:%s]], but does not invoke its functions.", | "This template has a corresponding Lua module [[Module:%s]], but does not invoke its functions.", | ||
corr_module | corr_module:gsub("/doc$", "") | ||
) | ) | ||
else | else | ||
result = string.format( | result = string.format( | ||
"This template is implemented by a module that is currently missing. [[Special:EditPage/Module:%s]]", | "This template is implemented by a module that is currently missing. [[Special:EditPage/Module:%s]]", | ||
corr_module | corr_module:gsub("/doc$", "") | ||
) | ) | ||
end | end | ||
| Line 244: | Line 244: | ||
result = string.format( | result = string.format( | ||
"This template is a metatemplate. It is used to build other templates and should not be used standalone, except for testing or simple usage. This template is implemented by the Lua module [[Module:%s]].", | "This template is a metatemplate. It is used to build other templates and should not be used standalone, except for testing or simple usage. This template is implemented by the Lua module [[Module:%s]].", | ||
corr_module | corr_module:gsub("/doc$", "") | ||
) | ) | ||
elseif has_module and not is_module_invoked then | elseif has_module and not is_module_invoked then | ||
result = string.format( | result = string.format( | ||
"This metatemplate has a corresponding Lua module [[Module:%s]], but does not invoke its functions.", | "This metatemplate has a corresponding Lua module [[Module:%s]], but does not invoke its functions.", | ||
corr_module | corr_module:gsub("/doc$", "") | ||
) | ) | ||
else | else | ||
| Line 263: | Line 263: | ||
"%s. This template is implemented by the Lua module [[Module:%s]].", | "%s. This template is implemented by the Lua module [[Module:%s]].", | ||
header, | header, | ||
corr_module | corr_module:gsub("/doc$", "") | ||
) | ) | ||
elseif has_module and header ~= "" and not is_module_invoked then | elseif has_module and header ~= "" and not is_module_invoked then | ||
| Line 269: | Line 269: | ||
"%s. This template has a corresponding Lua module [[Module:%s]], but does not invoke its functions.", | "%s. This template has a corresponding Lua module [[Module:%s]], but does not invoke its functions.", | ||
header, | header, | ||
corr_module | corr_module:gsub("/doc$", "") | ||
) | ) | ||
elseif has_module and header == "" and is_module_invoked then | elseif has_module and header == "" and is_module_invoked then | ||
result = string.format( | result = string.format( | ||
"This template is implemented by the Lua module [[Module:%s]].", | "This template is implemented by the Lua module [[Module:%s]].", | ||
corr_module | corr_module:gsub("/doc$", "") | ||
) | ) | ||
elseif has_module and header == "" and not is_module_invoked then | elseif has_module and header == "" and not is_module_invoked then | ||
result = string.format( | result = string.format( | ||
"This template has a corresponding Lua module [[Module:%s]], but does not invoke its functions.", | "This template has a corresponding Lua module [[Module:%s]], but does not invoke its functions.", | ||
corr_module | corr_module:gsub("/doc$", "") | ||
) | ) | ||
else | else | ||