Dota 2 Wiki
m
m (Removed the not a module error)
Line 6: Line 6:
 
no_results_text = 'None',
 
no_results_text = 'None',
 
results_header = 'Dependencies',
 
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 13: Line 12:
 
function p.main()
 
function p.main()
 
local current_page = mw.title.getCurrentTitle()
 
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 = current_page.basePageTitle

Revision as of 08:56, 25 April 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 current_page = mw.title.getCurrentTitle()
  
  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) == i18n.module_namespace then
      table.insert(requirements, string.format('* [[%s]]', require))
    end
  end

  if next(requirements) ~= nil then
    return '==' .. i18n.results_header .. '==\n' .. table.concat(requirements, '\n')
  end
end


return p