Dota 2 Wiki

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 5: Line 5:
 
module_namespace = 'Module',
 
module_namespace = 'Module',
 
no_results_text = 'None',
 
no_results_text = 'None',
  +
error_not_a_module = 'This template is only supported on Module pages',
results_header = 'Dependencies',
 
 
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 module_text = mw.title.getCurrentTitle().basePageTitle:getContent()
+
local current_page = mw.title.getCurrentTitle()
  +
  +
-- 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) == i18n.module_namespace then
+
if string.sub(require, 1, #i18n.module_namespace) == 'Module'then
requirements[require] = true
+
table.insert(requirements, string.format('* [[%s]]', require))
 
end
 
end
 
end
 
end
   
if next(requirements) then
+
if next(requirements) == nil then
local output = '==' .. i18n.results_header .. '==\n'
+
return ':<span style="font-style: italic;">' .. i18n.no_results_text .. '</span>'
for k,_ in pairs(requirements) do
 
output = output .. '* [[' .. k .. ']]\n'
 
end
 
return output
 
 
end
 
end
  +
  +
return table.concat(requirements, '\n')
 
end
 
end
   

Please note that all contributions to the Dota 2 Wiki are considered to be released under the CC BY-NC-SA 3.0

Cancel Editing help (opens in new window)

Template used on this page:

  • Module:Dependencies/doc (edit)