Módulo:Lua banner: diferenças entre revisões
(Criou a página com "-- This module implements the {{lua}} template. local yesno = require('Módulo:Yesno') local mList = require('Módulo:Lista') local mTableTools = require('Módulo:TableTool...") |
m (Protegeu "Módulo:Lua banner" ([Editar=Permitir apenas utilizadores autoconfirmados] (indefinidamente) [Mover=Permitir apenas utilizadores autoconfirmados] (indefinidamente))) |
(Sem diferenças)
| |
Edição atual desde as 16h12min de 15 de junho de 2018
-- This module implements the {{#invoke:Lua banner|main}} template.
local yesno = require('Módulo:Yesno') local mList = require('Módulo:Lista') local mTableTools = require('Módulo:TableTools') local mMessageBox = require('Módulo: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 = mTableTools.compressSparseArray(args) local box = p.renderBox(modules) local trackingCategories = p.renderTrackingCategories(args, modules) return box .. trackingCategories end
function p.renderBox(modules)
local boxArgs = {}
local title
local endtext =
if #modules < 1 then
boxArgs.text = 'Erro: não foi especificado o módulo'
else
local moduleLinks = {}
for i, module in ipairs(modules) do
moduleLinks[i] = string.format('%s', module)
end
if #modules == 1 then
endtext = 'o seguinte módulo'
else
endtext = 'os seguintes módulos'
end
local moduleList = mList.makeList('bulleted', moduleLinks)
boxArgs.text = "Esta predefinição utiliza um script escrito na linguagem de programação Lua. Por favor, consulte Wikimotorpedia:Lua para aprender mais sobre a extensão Scribunto ou ajudar na conversão de outras predefinições. Veja como fazer provas de predefinições.\nEsta predefinição utiliza " ..endtext .. ":\n" .. moduleList
end
boxArgs.type = 'notice'
boxArgs.small = true
boxArgs.image = '
'
return mMessageBox.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] = '!Predefinições com base em Lua com erros' end
-- Lua templates category titleObj = titleObj or mw.title.getCurrentTitle() local subpageBlacklist = { doc = true, Testes = true, Testes2 = true, Exemplos_para_testes = true } if titleObj.namespace == 10 and not subpageBlacklist[titleObj.subpageText] then local category = args.category if not category then local categories = { ['Módulo:String'] = '!Predefinições de manipulação de cadeias baseadas em Lua', ['Módulo:Math'] = '!Predefinições com base no módulo Lua Math', ['Módulo:BaseConvert'] = '!Predefinições com base no módulo BaseConvert', ['Módulo:Citação/CS1'] = '!Predefinições de citação com base em Lua' } categories['Módulo:Citação/CS1'] = categories['Module:Citation'] category = modules[1] and categories[modules[1]] category = category or '!Predefinições com base em Lua' end cats[#cats + 1] = category end
for i, cat in ipairs(cats) do cats[i] = string.format(, cat) end return table.concat(cats) end
return p