Documentation for this module may be created at Module:Cargo banner/doc
local yesno = require('Module:Yesno')
local List = require('Module:List')
local TableTools = require('Module:TableTools')
local MessageBox = require('Module:Message box')
local p = {}
function p.main(frame)
local origArgs = frame:getParent().args
local args = {}
for k, v in pairs(origArgs) do
v = v:match('^%s*(.-)%s*$')
if v ~= '' then
args[k] = v
end
end
return p._main(args)
end
function p._main(args)
local modules = TableTools.compressSparseArray(args)
local box = p.renderBox(modules)
local trackingCategories = p.renderTrackingCategories(args, modules)
return box .. trackingCategories
end
function p.renderBox(tables)
local boxArgs = {}
if #tables < 1 then
boxArgs.text = '<strong class="error">Error: no tables specified</strong>'
else
local tableLinks = {}
for i, tbl in ipairs(tables) do
tableLinks[i] = string.format('[[Special:CargoTables/%s|%s]]', tbl, tbl)
end
local tableList = List.makeList('bulleted', tableLinks)
local title = mw.title.getCurrentTitle()
if title.subpageText == "doc" then
title = title.basePageTitle
end
if title.contentModel == "Scribunto" then
boxArgs.text = 'This module uses the following [[mw:Extension:Cargo|Cargo]] tables:' .. tableList
else
boxArgs.text = 'This template uses the following [[mw:Extension:Cargo|Cargo]] tables:\n' .. tableList
end
end
boxArgs.type = 'notice'
boxArgs.small = true
boxArgs.image = '[[File:Cargo logo.png|30px|alt=|link=]]'
return MessageBox.main('mbox', boxArgs)
end
function p.renderTrackingCategories(args, modules, titleObj)
if yesno(args.nocat) then
return ''
end
local cats = {}
-- Error category
if #modules < 1 then
cats[#cats + 1] = 'Templates using Cargo tables with errors'
end
-- Cargo templates category
titleObj = titleObj or mw.title.getCurrentTitle()
local subpageBlacklist = {
doc = true,
sandbox = true,
sandbox2 = true,
testcases = true
}
if not subpageBlacklist[titleObj.subpageText] then
if titleObj.namespace == 10 then
local category = args.category or 'Templates using Cargo tables'
cats[#cats + 1] = category
end
end
for i, cat in ipairs(cats) do
cats[i] = string.format('[[Category:%s]]', cat)
end
return table.concat(cats)
end
return p