Module:Template introspection: Difference between revisions

Ganaram inukshuk (talk | contribs)
m update todo (wrapper is alraedy made)
Ganaram inukshuk (talk | contribs)
mNo edit summary
 
(5 intermediate revisions by the same user not shown)
Line 35: Line 35:
:gsub("%s+", " ")
:gsub("%s+", " ")
:match("^%s*(.-)%s*$")
:match("^%s*(.-)%s*$")
-- Normalize more by removing subst, safesubst, and any extra curly brackets
normalized = normalized
:gsub("{{{|safesubst:}}}", "")  -- Remove {{{{|safesubst:}}} if used
:gsub("{{{|subst:}}}", "")      -- Remove {{{{|subst:}}} if used
:gsub("{{{{", "{{")            -- Collapse excessive curly brackets
:gsub("}}}}", "}}")            -- Collapse excessive curly brackets


return normalized
return normalized
Line 59: Line 66:
if #invokes == 0 then
if #invokes == 0 then
hatnote = "This template does not invoke any functions."
hatnote = "This template does not invoke any functions."
return hatnote
return string.format(":''%s''\n", hatnote)
else
else
hatnote = "This template invokes the following functions from Lua modules:"
hatnote = "This template invokes the following functions:"
local calls = {}
local calls = {}
for _, call in ipairs(invokes) do
for _, call in ipairs(invokes) do
table.insert(calls, string.format("'''%s''' from [[Module:%s]]", call.func, call.module))
table.insert(calls, string.format("'''%s''' from [[Module:%s]]", call.func, call.module))
end
end
return string.format(":''%s %s''", hatnote, table.concat(calls, ", "))
return string.format(":''%s %s''\n", hatnote, table.concat(calls, ", "))
end
end
end
end


function p._template_introspection(args)
function p._template_introspection(args)
local template_name = args["Template Name"]
local template_name = args["template_name"]


-- Get template wikitext
-- Get template wikitext
Line 96: Line 103:
-- Get template name, with namespace, and strip /doc if present
-- Get template name, with namespace, and strip /doc if present
args["Template Name"] = args["Template Name"] or mw.title.getCurrentTitle().prefixedText
args["template_name"] = args["template_name"] or mw.title.getCurrentTitle().prefixedText
args["Template Name"] = args["Template Name"]:gsub("/doc$", "")
args["template_name"] = args["template_name"]:gsub("/doc$", "")
return p._template_introspection(args)
return p._template_introspection(args)