Module:Template introspection: Difference between revisions

Ganaram inukshuk (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
No edit summary
Line 54: Line 54:
return results
return results
end
function p.make_hatnote(invokes)
local hatnote = ""
if #invokes == 0 then
hatnote = "This template does not invoke any functions."
return hatnote
else
hatnote = "This template invokes functions from Lua modules:"
local calls = {}
for _, call in ipairs(invokes) do
table.insert(calls, string.format("function %s from %s"))
end
return string.format(":''%s %s''", hatnote, table.concat(calls, ", "))
end
end
end


Line 65: Line 80:
end
end


-- Get template's code and preprocess
local wikitext = titleObj:getContent()
local wikitext = titleObj:getContent()
wikitext = p.preprocess_wikitext(wikitext)
wikitext = p.preprocess_wikitext(wikitext)
Line 72: Line 88:
end
end
-- Run invoke finder
-- Run invoke finder and return as a hatnote
local invokes = p.find_invokes(wikitext)
local invokes = p.find_invokes(wikitext)
return p.make_hatnote(invokes)
-- Format result for readability (or later, you could return a table)
local out = {}
table.insert(out, "== Invoked modules ==")
for _, call in ipairs(invokes) do
table.insert(out, string.format("* %s → %s", call.module, call.func))
end
if #invokes == 0 then
table.insert(out, "No #invoke calls found.")
end
return table.concat(out, "\n")
end
end