Module:Dochead: Difference between revisions

Ganaram inukshuk (talk | contribs)
edit message for templates that have a corresponding module that it does not use
Ganaram inukshuk (talk | contribs)
refactor
Line 43: Line 43:


return cats
return cats
end
-- Helper function
-- Creates an additional hatnote denoting which functions are invoked from which
-- modules, if a has more than one invoke.
local function make_invocation_hatnote(invokes)
local hatnote = ""
if #invokes == 0 then
return ""
else
hatnote = "This template invokes the following functions:"
local calls = {}
for _, call in ipairs(invokes) do
local module_link = iutils.make_module_link(call.module)
table.insert(calls, string.format("'''%s''' from %s", call.func, module_link))
end
return string.format("%s %s", hatnote, table.concat(calls, ", "))
end
end
end


Line 70: Line 52:
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)
has_template = has_template and iutils.invocation_exists(wikitext, pagename)
local invokes = iutils.find_invokes(wikitext)
has_template = has_template and iutils.invocation_exists(invokes, pagename)
end
end
Line 130: Line 113:
end
end


-- Helper function
-- Creates an additional hatnote denoting which functions are invoked from which
-- modules, if a has more than one invoke.
local function make_invocation_hatnote(invokes)
local hatnote = ""
if #invokes == 0 then
return ""
else
hatnote = "This template invokes the following functions:"
local calls = {}
for _, call in ipairs(invokes) do
local module_link = iutils.make_module_link(call.module)
table.insert(calls, string.format("'''%s''' from %s", call.func, module_link))
end
return string.format("%s %s", hatnote, table.concat(calls, ", "))
end
end


-- Helper function to handle templates
-- Helper function to handle templates
Line 136: Line 136:
-- 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)
local wikitext = iutils.get_and_preprocess_content("Template", pagename)
local invokes = iutils.find_invokes(wikitext)
local is_module_invoked = iutils.invocation_exists(wikitext, corr_module)
local is_module_invoked = iutils.invocation_exists(invokes, corr_module)


-- Find all invocations for the template
-- Find all invocations for the template
local invokes = iutils.find_invokes(wikitext)
local invocation_hatnote = make_invocation_hatnote(invokes)
local invocation_hatnote = make_invocation_hatnote(invokes)