Dota 2 Wiki
Advertisement

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',
  error_not_a_module = 'This template is only supported on Module pages',
  error_module_empty = 'The module appears to be empty',
}


function p.main()
  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)
  
  local requirements = {}
  for require in string.gmatch(module_text, 'require%(%s*["\'](.-)["\']%s*%)') do
    if string.sub(require, 1, #i18n.module_namespace) == 'Module'then
      table.insert(requirements, string.format('* [[%s]]', require))
    end
  end

  if next(requirements) == nil then
    return ':<span style="font-style: italic;">' .. i18n.no_results_text .. '</span>'
  end
  
  return table.concat(requirements, '\n')
end


return p
Advertisement