Ir para o conteúdo

Módulo:Caixa lateral: mudanças entre as edições

De Wiki TokuDrive
Importando predefinição/módulo da Wikipédia em português para manter layout
 
Importando predefinição/módulo da Wikipédia em português para manter layout
 
Linha 2: Linha 2:
local p = {}
local p = {}


local function makeData(args)
-- Tabela de mapeamento: "nome_em_portugues" = "English_name"
local data = {}
local argAliases = {
    metadados      = 'metadata',
    ['posição']        = 'position',
    ['colapsável']    = 'collapsible',
    classe        = 'class',
    imagem        = 'image',
    ['classe-texto'] = 'textclass',
    estilo        = 'style',
    textoestilo    = 'textstyle',
    ['texto-estilo'] = 'textstyle',
    estilotexto    = 'textstyle',
    ['estilo-texto'] = 'textstyle',
    acima          = 'above',
    acimaestilo    = 'abovestyle',
    ['acima-estilo'] = 'abovestyle',
    estiloacima    = 'abovestyle',
    ['estilo-acima'] = 'abovestyle',
    texto          = 'text',
    imagemdireita  = 'imageright',
    ['imagem-direita'] = 'imageright',
    abaixo        = 'below',
}


-- Main table classes
-- Normaliza os argumentos (tradução + tratamento do valor "nenhuma")
data.classes = {}
local function processArgs(rawArgs)
if yesno(args.metadata) ~= false then
    local args = {}
table.insert(data.classes, 'metadata')
    for k, v in pairs(rawArgs) do
end
        if type(k) == 'string' then
if args.position and args.position:lower() == 'left' then
            v = v:match('^%s*(.-)%s*$') -- Remove espaços no início e fim
table.insert(data.classes, 'side-box-left')
            if v ~= '' then
else
                -- Traduz o nome do parâmetro se houver alias registrado
table.insert(data.classes, 'side-box-right')
                local canonicalKey = argAliases[k] or k
end
               
                -- Trata o caso especial do valor da imagem em PT-BR
if args.collapsible then
                if canonicalKey == 'image' and v:lower() == 'nenhuma' then
table.insert(data.classes, 'mw-collapsible')
                    v = 'none'
if args.collapsible == "collapsed" then
                end
table.insert(data.classes, 'mw-collapsed')
               
end
                args[canonicalKey] = v
data.collapsible = true
            end
end
        end
    end
    return args
end


table.insert(data.classes, args.class)
local function makeData(args)
    local data = {}
-- Image
if args.image and args.image ~= 'none' then
data.image = args.image
end
-- we have to check to see if a downstream use has plainlist like
-- Template:Sister_project. also it's the default. wikitext is :(
if args.textclass == 'plainlist' or not args.textclass then
data.textclass = 'plainlist'
data.plainlist_templatestyles = 'Lista simples/styles.css'
else
data.textclass = args.textclass
end
 
-- Copy over data that does not need adjusting
local argsToCopy = {
-- aria qualities
'role',
'labelledby',


-- Styles
    -- Main table classes
'style',
    data.classes = {}
'textstyle',
    if yesno(args.metadata) ~= false then
'templatestyles',
        table.insert(data.classes, 'metadata')
    end
    if args.position and args.position:lower() == 'left' then
        table.insert(data.classes, 'side-box-left')
    else
        table.insert(data.classes, 'side-box-right')
    end
   
    if args.collapsible then
        table.insert(data.classes, 'mw-collapsible')
        if args.collapsible == "collapsed" then
            table.insert(data.classes, 'mw-collapsed')
        end
        data.collapsible = true
    end


-- Above row
    -- CORREÇÃO IMPORTANTE: Só insere se args.class existir para não quebrar a tabela
'above',
    if args.class then
'abovestyle',
        table.insert(data.classes, args.class)
    end
   
    -- Image
    if args.image and args.image ~= 'none' then
        data.image = args.image
    end
   
    if args.textclass == 'plainlist' or not args.textclass then
        data.textclass = 'plainlist'
        data.plainlist_templatestyles = 'Lista simples/styles.css'
    else
        data.textclass = args.textclass
    end


-- Body row
    -- Copy over data that does not need adjusting
'text',
    local argsToCopy = {
'imageright',
        'role',
        'labelledby',
        'style',
        'textstyle',
        'templatestyles',
        'above',
        'abovestyle',
        'text',
        'imageright',
        'below',
    }
    for _, key in ipairs(argsToCopy) do
        data[key] = args[key]
    end


-- Below row
    return data
'below',
}
for i, key in ipairs(argsToCopy) do
data[key] = args[key]
end
 
return data
end
end


local function renderSidebox(data)
local function renderSidebox(data)
-- Renders the sidebox HTML.
    local root = mw.html.create('div')
 
    root:attr('role', data.role)
-- Table root
        :attr('aria-labelledby', data.labelledby)
local root = mw.html.create('div')
        :addClass('side-box')
root:attr('role', data.role)
       
:attr('aria-labelledby', data.labelledby)
    for _, class in ipairs(data.classes or {}) do
:addClass('side-box')
        root:addClass(class)
for i, class in ipairs(data.classes or {}) do
    end
root:addClass(class)
   
end
    if data.style then
if data.style then
        root:cssText(data.style)
root:cssText(data.style)
    end
end
   
    local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
    if data.plainlist_templatestyles then
if data.plainlist_templatestyles then
        root:wikitext(frame:extensionTag{
root:wikitext(frame:extensionTag{
            name = 'templatestyles', args = { src = data.plainlist_templatestyles }
name = 'templatestyles', args = { src = data.plainlist_templatestyles }
        })
})
    end
end


-- The "above" row
    -- Above row
if data.above then
    if data.above then
local above = root:newline():tag('div')
        local above = root:newline():tag('div')
above:addClass('side-box-abovebelow')
        above:addClass('side-box-abovebelow')
:newline()
            :newline()
:wikitext(data.above)
            :wikitext(data.above)
if data.textstyle then
        if data.textstyle then above:cssText(data.textstyle) end
above:cssText(data.textstyle)
        if data.abovestyle then above:cssText(data.abovestyle) end
end
    end
if data.abovestyle then
above:cssText(data.abovestyle)
end
end


-- The body row
    -- Body row
local body = root:newline():tag('div')
    local body = root:newline():tag('div')
body:addClass('side-box-flex')
    body:addClass('side-box-flex')
:addClass(data.collapsible and 'mw-collapsible-content')
        :addClass(data.collapsible and 'mw-collapsible-content')
:newline()
        :newline()
if data.image then
       
body:tag('div')
    if data.image then
:addClass('side-box-image')
        body:tag('div')
:wikitext(data.image)
            :addClass('side-box-image')
end
            :wikitext(data.image)
local text = body:newline():tag('div')
    end
text:addClass('side-box-text')
   
:addClass(data.textclass)
    local text = body:newline():tag('div')
if data.textstyle then
    text:addClass('side-box-text')
text:cssText(data.textstyle)
        :addClass(data.textclass)
end
    if data.textstyle then
text:wikitext(data.text)
        text:cssText(data.textstyle)
if data.imageright then
    end
body:newline():tag('div')
    text:wikitext(data.text)
:addClass('side-box-imageright')
   
:wikitext(data.imageright)
    if data.imageright then
end
        body:newline():tag('div')
            :addClass('side-box-imageright')
            :wikitext(data.imageright)
    end


-- The below row
    -- Below row
if data.below then
    if data.below then
local below = root:newline():tag('div')
        local below = root:newline():tag('div')
below
        below:addClass('side-box-abovebelow')
:addClass('side-box-abovebelow')
            :wikitext(data.below)
:wikitext(data.below)
        if data.textstyle then
if data.textstyle then
            below:cssText(data.textstyle)
below:cssText(data.textstyle)
        end
end
    end
end


root:newline()
    root:newline()
local templatestyles = ''
    local templatestyles = ''
if data.templatestyles then
    if data.templatestyles then
templatestyles = frame:extensionTag{
        templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = data.templatestyles }
            name = 'templatestyles', args = { src = data.templatestyles }
}
        }
end
    end
return frame:extensionTag{
    return frame:extensionTag{
name = 'templatestyles', args = { src = 'Módulo:Caixa lateral/styles.css' }
        name = 'templatestyles', args = { src = 'Módulo:Caixa lateral/styles.css' }
} .. templatestyles .. tostring(root)
    } .. templatestyles .. tostring(root)
end
end


function p._main(args)
function p._main(args)
local data = makeData(args)
    local data = makeData(args)
return renderSidebox(data)
    return renderSidebox(data)
end
end


function p.main(frame)
function p.main(frame)
--local origArgs = frame:getParent().args
    -- Captura tanto chamadas diretas (#invoke) quanto parâmetros da predefinição chamadora
local args = {}
    local origArgs = frame:getParent() and frame:getParent().args or frame.args
for k, v in pairs(frame.args) do -- 'origArgs' foi substituído por 'frame.args' nesta linha
    local args = processArgs(origArgs)
v = v:match('%s*(.-)%s*$')
   
if v ~= '' then
    return p._main(args)
args[k] = v
end
end
return p._main(args)
end
end


return p
return p

Edição atual tal como às 06h16min de 26 de julho de 2026

local yesno = require('Módulo:Yesno') local p = {}

-- Tabela de mapeamento: "nome_em_portugues" = "English_name" local argAliases = {

   metadados      = 'metadata',
   ['posição']        = 'position',
   ['colapsável']     = 'collapsible',
   classe         = 'class',
   imagem         = 'image',
   ['classe-texto'] = 'textclass',
   estilo         = 'style',
   textoestilo    = 'textstyle',
   ['texto-estilo'] = 'textstyle',
   estilotexto    = 'textstyle',
   ['estilo-texto'] = 'textstyle',
   acima          = 'above',
   acimaestilo    = 'abovestyle',
   ['acima-estilo'] = 'abovestyle',
   estiloacima    = 'abovestyle',
   ['estilo-acima'] = 'abovestyle',
   texto          = 'text',
   imagemdireita  = 'imageright',
   ['imagem-direita'] = 'imageright',
   abaixo         = 'below',

}

-- Normaliza os argumentos (tradução + tratamento do valor "nenhuma") local function processArgs(rawArgs)

   local args = {}
   for k, v in pairs(rawArgs) do
       if type(k) == 'string' then
           v = v:match('^%s*(.-)%s*$') -- Remove espaços no início e fim
           if v ~=  then
               -- Traduz o nome do parâmetro se houver alias registrado
               local canonicalKey = argAliases[k] or k
               
               -- Trata o caso especial do valor da imagem em PT-BR
               if canonicalKey == 'image' and v:lower() == 'nenhuma' then
                   v = 'none'
               end
               
               args[canonicalKey] = v
           end
       end
   end
   return args

end

local function makeData(args)

   local data = {}
   -- Main table classes
   data.classes = {}
   if yesno(args.metadata) ~= false then
       table.insert(data.classes, 'metadata')
   end
   if args.position and args.position:lower() == 'left' then
       table.insert(data.classes, 'side-box-left')
   else
       table.insert(data.classes, 'side-box-right')
   end
   
   if args.collapsible then
       table.insert(data.classes, 'mw-collapsible')
       if args.collapsible == "collapsed" then
           table.insert(data.classes, 'mw-collapsed')
       end
       data.collapsible = true
   end
   -- CORREÇÃO IMPORTANTE: Só insere se args.class existir para não quebrar a tabela
   if args.class then
       table.insert(data.classes, args.class)
   end
   
   -- Image
   if args.image and args.image ~= 'none' then
       data.image = args.image
   end
   
   if args.textclass == 'plainlist' or not args.textclass then
       data.textclass = 'plainlist'
       data.plainlist_templatestyles = 'Lista simples/styles.css'
   else
       data.textclass = args.textclass
   end
   -- Copy over data that does not need adjusting
   local argsToCopy = {
       'role',
       'labelledby',
       'style',
       'textstyle',
       'templatestyles',
       'above',
       'abovestyle',
       'text',
       'imageright',
       'below',
   }
   for _, key in ipairs(argsToCopy) do
       data[key] = args[key]
   end
   return data

end

local function renderSidebox(data)

   local root = mw.html.create('div')
   root:attr('role', data.role)
       :attr('aria-labelledby', data.labelledby)
       :addClass('side-box')
       
   for _, class in ipairs(data.classes or {}) do
       root:addClass(class)
   end
   
   if data.style then
       root:cssText(data.style)
   end
   
   local frame = mw.getCurrentFrame()
   if data.plainlist_templatestyles then
       root:wikitext(frame:extensionTag{
           name = 'templatestyles', args = { src = data.plainlist_templatestyles }
       })
   end
   -- Above row
   if data.above then
       local above = root:newline():tag('div')
       above:addClass('side-box-abovebelow')
           :newline()
           :wikitext(data.above)
       if data.textstyle then above:cssText(data.textstyle) end
       if data.abovestyle then above:cssText(data.abovestyle) end
   end
   -- Body row
   local body = root:newline():tag('div')
   body:addClass('side-box-flex')
       :addClass(data.collapsible and 'mw-collapsible-content')
       :newline()
       
   if data.image then
       body:tag('div')
           :addClass('side-box-image')
           :wikitext(data.image)
   end
   
   local text = body:newline():tag('div')
   text:addClass('side-box-text')
       :addClass(data.textclass)
   if data.textstyle then
       text:cssText(data.textstyle)
   end
   text:wikitext(data.text)
   
   if data.imageright then
       body:newline():tag('div')
           :addClass('side-box-imageright')
           :wikitext(data.imageright)
   end
   -- Below row
   if data.below then
       local below = root:newline():tag('div')
       below:addClass('side-box-abovebelow')
           :wikitext(data.below)
       if data.textstyle then
           below:cssText(data.textstyle)
       end
   end
   root:newline()
   local templatestyles = 
   if data.templatestyles then
       templatestyles = frame:extensionTag{
           name = 'templatestyles', args = { src = data.templatestyles }
       }
   end
   return frame:extensionTag{
       name = 'templatestyles', args = { src = 'Módulo:Caixa lateral/styles.css' }
   } .. templatestyles .. tostring(root)

end

function p._main(args)

   local data = makeData(args)
   return renderSidebox(data)

end

function p.main(frame)

   -- Captura tanto chamadas diretas (#invoke) quanto parâmetros da predefinição chamadora
   local origArgs = frame:getParent() and frame:getParent().args or frame.args
   local args = processArgs(origArgs)
   
   return p._main(args)

end

return p