Module:Modules
Documentation for this module may be created at Module:Modules/doc
local p = {}
local INDEX_PAGE = 'Module:Data/Modules/index'
local function loadIndex()
return mw.loadJsonData(INDEX_PAGE)
end
local function loadModule(key)
local index = loadIndex()
if not index.modules then
return nil, 'Module index does not contain a "modules" object.'
end
local entry = index.modules[key]
if not entry then
return nil, 'Module "' .. tostring(key) .. '" was not found in the module index.'
end
if not entry.data_page then
return nil, 'Module "' .. tostring(key) .. '" does not have a data_page defined.'
end
return mw.loadJsonData(entry.data_page)
end
function p.testIndex(frame)
local data = loadIndex()
if not data.modules then
return '<strong class="error">Module index loaded, but no "modules" object was found.</strong>'
end
local module = data.modules.frame_shift_drive
if not module then
return '<strong class="error">Module index loaded, but "frame_shift_drive" was not found.</strong>'
end
return string.format(
'Module database connected successfully: [[%s|%s]] — %s',
module.page,
module.name,
module.group
)
end
function p.testModule(frame)
local data, err = loadModule('frame_shift_drive')
if not data then
return '<strong class="error">' .. err .. '</strong>'
end
return string.format(
'Detailed module data loaded successfully: [[%s|%s]] — %s — %d classes — %d ratings',
data.page,
data.name,
data.group,
#(data.classes or {}),
#(data.ratings or {})
)
end
return p