@DeletedUser41170185 (talk | contribs) (Created page with "local p = {} local i18n = { doc_subpage = 'doc', module_namespace = 'Module', no_results_text = 'None', error_not_a_module = 'This template is only supported on Modul...") |
@DeletedUser41170185 (talk | contribs) mNo edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
module_namespace = 'Module', |
module_namespace = 'Module', |
||
no_results_text = 'None', |
no_results_text = 'None', |
||
+ | results_header = 'Dependencies', |
||
− | error_not_a_module = 'This template is only supported on Module pages', |
||
error_module_empty = 'The module appears to be empty', |
error_module_empty = 'The module appears to be empty', |
||
} |
} |
||
Line 11: | Line 11: | ||
function p.main() |
function p.main() |
||
− | local |
+ | local module_text = mw.title.getCurrentTitle().basePageTitle:getContent() |
− | |||
− | -- Throw an error if the function is used on a non-module page. |
||
− | if current_page.nsText ~= i18n.module_namespace then error(i18n.error_not_a_module, 0) end |
||
− | |||
− | local module = current_page.basePageTitle |
||
− | local module_text = module:getContent() |
||
assert(module_text, i18n.error_module_empty) |
assert(module_text, i18n.error_module_empty) |
||
local requirements = {} |
local requirements = {} |
||
for require in string.gmatch(module_text, 'require%(%s*["\'](.-)["\']%s*%)') do |
for require in string.gmatch(module_text, 'require%(%s*["\'](.-)["\']%s*%)') do |
||
− | if string.sub(require, 1, #i18n.module_namespace) == |
+ | if string.sub(require, 1, #i18n.module_namespace) == i18n.module_namespace then |
− | + | requirements[require] = true |
|
end |
end |
||
end |
end |
||
− | if next(requirements) |
+ | if next(requirements) then |
− | + | local output = '==' .. i18n.results_header .. '==\n' |
|
+ | for k,_ in pairs(requirements) do |
||
+ | output = output .. '* [[' .. k .. ']]\n' |
||
+ | end |
||
+ | return output |
||
end |
end |
||
− | |||
− | return table.concat(requirements, '\n') |
||
end |
end |
||
Latest revision as of 10:19, 1 June 2018
Documentation for this module may be created at Module:Dependencies/doc
local p = {}
local i18n = {
doc_subpage = 'doc',
module_namespace = 'Module',
no_results_text = 'None',
results_header = 'Dependencies',
error_module_empty = 'The module appears to be empty',
}
function p.main()
local module_text = mw.title.getCurrentTitle().basePageTitle:getContent()
assert(module_text, i18n.error_module_empty)
local requirements = {}
for require in string.gmatch(module_text, 'require%(%s*["\'](.-)["\']%s*%)') do
if string.sub(require, 1, #i18n.module_namespace) == i18n.module_namespace then
requirements[require] = true
end
end
if next(requirements) then
local output = '==' .. i18n.results_header .. '==\n'
for k,_ in pairs(requirements) do
output = output .. '* [[' .. k .. ']]\n'
end
return output
end
end
return p