Module:Introspection utils: Difference between revisions

Ganaram inukshuk (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:


-- TODO:
-- TODO:
-- - Detect whether a template invokes a specific module
-- Add support for detecting modules providing data, not just functions.
-- Address edge case of lazy-loaded modules (loaded within a function)


-- Common functions for module and template introspection.
-- Common functions for module and template introspection.
Line 82: Line 83:
end
end


-- Normalize tags and subst
-- Normalize tags
text_to_scan = text_to_scan
text_to_scan = text_to_scan
:gsub("<noinclude>.-</noinclude>", "")
:gsub("<noinclude>.-</noinclude>", "")
Line 90: Line 91:
:gsub("<onlyinclude>", "")
:gsub("<onlyinclude>", "")
:gsub("</onlyinclude>", "")
:gsub("</onlyinclude>", "")
:gsub("{{%s*safesubst:", "{{")
:gsub("{{%s*subst:", "{{")


-- Normalize:
-- Normalize subst/safesubst
text_to_scan = text_to_scan
    :gsub("{{+%s*[Ss]afesubst:", "{{")
    :gsub("{{+%s*[Ss]ubst:", "{{")
 
-- Normalize spaces
text_to_scan = text_to_scan
text_to_scan = text_to_scan
:gsub("[\r\n]", " ")
:gsub("[\r\n]", " ")
Line 328: Line 332:
local function normalize_module_name(name)
local function normalize_module_name(name)
if not name then return "" end
if not name then return "" end
-- Trim, replace spaces with underscores, remove namespace
-- Trim, replace spaces with underscores, remove namespace, lowercase first
-- letter
name = mw.text.trim(name)
name = mw.text.trim(name)
name = name:gsub(" ", "_")
name = name:gsub(" ", "_")
name = name:gsub("^[Mm]odule:", "")
name = name:gsub("^[Mm]odule:", "")
name = name:gsub("^%a", string.lower)
return name
return name
end
end