Module:Introspection utils: Difference between revisions

Ganaram inukshuk (talk | contribs)
add function to check whether an invocation exists; add function to produce a normalized module name from an invocation
Ganaram inukshuk (talk | contribs)
mNo edit summary
Line 16: Line 16:
-- --------------- CODE EXTRACTION AND PREPROCESSING FUNCTIONS -----------------
-- --------------- CODE EXTRACTION AND PREPROCESSING FUNCTIONS -----------------
-- -----------------------------------------------------------------------------
-- -----------------------------------------------------------------------------
function p.extract_and_preprocess_content(namespace, pagename)
local title = mw.title.new(string.format("%s:%s", namespace, pagename))
local content = title:getContent()
if string.lower(namespace) == "module" then
return p.preprocess_code(content)
elseif string.lower(namespace) == "template" then
return p.preprocess_wikitext(content)
else
return ""
end
end


-- Helper function: preprocess lua code
-- Helper function: preprocess lua code
Line 112: Line 99:


return normalized
return normalized
end
function p.get_and_preprocess_content(namespace, pagename)
local title = mw.title.new(string.format("%s:%s", namespace, pagename))
local content = title:getContent()
if string.lower(namespace) == "module" then
return p.preprocess_code(content)
elseif string.lower(namespace) == "template" then
return p.preprocess_wikitext(content)
else
return ""
end
end
end