Módulo:Caixa lateral: diferenças entre revisões
Conteúdo apagado Conteúdo adicionado
Desfeita a edição 56002251 de Jmarchn Erro!! Etiqueta: Desfazer |
|||
Linha 1: | Linha 1: | ||
-- This module implements {{side box}}. |
-- This module implements {{side box}}. |
||
local yesno = require(' |
local yesno = require('Módulo:Yesno') |
||
local p = {} |
local p = {} |
||
Linha 27: | Linha 27: | ||
-- Main table classes |
-- Main table classes |
||
data.classes = {} |
data.classes = {} |
||
if yesno(args.metadata) ~= false then |
if yesno(args.metadata) ~= false or yesno(args.metadados) ~= false then |
||
table.insert(data.classes, 'metadata') |
table.insert(data.classes, 'metadata') |
||
end |
end |
||
if |
if args.position and args.position:lower() == 'left' or args['posição'] and args['posição']:lower() == 'left' then |
||
table.insert(data.classes, 'mbox-small-left') |
table.insert(data.classes, 'mbox-small-left') |
||
else |
else |
||
table.insert(data.classes, 'mbox-small') |
table.insert(data.classes, 'mbox-small') |
||
end |
end |
||
table.insert(data.classes, args.class) |
table.insert(data.classes, args.class or args.classe) |
||
-- Image |
-- Image |
||
if args.image and args.image ~= 'none' then |
if args.image and args.image ~= 'none' and args.image ~= 'nenhuma' then |
||
data.image = args.image |
data.image = args.image |
||
elseif args. |
elseif args.imagem and args.imagem ~= 'none' and args.imagem ~= 'nenhuma' then |
||
data. |
data.imagem = args.imagem |
||
end |
end |
||
Linha 48: | Linha 48: | ||
-- Styles |
-- Styles |
||
'style', |
'style', |
||
'estilo', |
|||
'textstyle', |
'textstyle', |
||
' |
'estilotexto', |
||
' |
'textoestilo', |
||
'estilo-texto', |
|||
'texto-estilo', |
|||
-- Above row |
-- Above row |
||
'above', |
'above', |
||
'acima', |
|||
'abovestyle', |
'abovestyle', |
||
' |
'acimaestilo', |
||
' |
'estiloacima', |
||
'acima-estilo', |
|||
'estilo-acima', |
|||
-- Body row |
-- Body row |
||
'text', |
'text', |
||
'texto', |
|||
'imageright', |
'imageright', |
||
' |
'imagemdireita', |
||
'imagem-direita', |
|||
-- Below row |
-- Below row |
||
'below', |
'below', |
||
' |
'abaixo', |
||
} |
} |
||
for i, key in ipairs(argsToCopy) do |
for i, key in ipairs(argsToCopy) do |
||
Linha 84: | Linha 92: | ||
end |
end |
||
root:css{border = '1px solid #aaa', ['background-color'] = '#f9f9f9', color = '#000'} |
root:css{border = '1px solid #aaa', ['background-color'] = '#f9f9f9', color = '#000'} |
||
if data.style or data. |
if data.style or data.estilo then |
||
root:cssText(data.style or data. |
root:cssText(data.style or data.estilo) |
||
end |
end |
||
-- The "above" row |
-- The "above" row |
||
if data.above or data. |
if data.above or data.acima then |
||
local aboveCell = root:newline():tag('tr'):tag('td') |
local aboveCell = root:newline():tag('tr'):tag('td') |
||
aboveCell |
aboveCell |
||
:attr('colspan', |
:attr('colspan', data.imageright and 3 or 2) |
||
:addClass('mbox-text') |
:addClass('mbox-text') |
||
if data.textstyle or data. |
if data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'] then |
||
aboveCell:cssText(data.textstyle or data. |
aboveCell:cssText(data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo']) |
||
end |
end |
||
if data.abovestyle or data. |
if data.abovestyle or data.estiloacima or data.acimaestilo or data['estilo-acima'] or data['acima-estilo'] then |
||
aboveCell:cssText(data.abovestyle or data. |
aboveCell:cssText(data.abovestyle or data.estiloacima or data.acimaestilo or data['estilo-acima'] or data['acima-estilo']) |
||
end |
end |
||
aboveCell |
aboveCell |
||
:newline() |
:newline() |
||
:wikitext(data.above or data. |
:wikitext(data.above or data.acima) |
||
end |
end |
||
-- The body row |
-- The body row |
||
local bodyRow = root:newline():tag('tr'):newline() |
local bodyRow = root:newline():tag('tr'):newline() |
||
if data.image or data. |
if data.image or data.imagem then |
||
bodyRow:tag('td') |
bodyRow:tag('td') |
||
:addClass('mbox-image') |
:addClass('mbox-image') |
||
:wikitext(data.image or data. |
:wikitext(data.image or data.imagem) |
||
else |
else |
||
bodyRow:tag('td'):css('width', '1px') |
bodyRow:tag('td'):css('width', '1px') |
||
Linha 116: | Linha 124: | ||
local textCell = bodyRow:newline():tag('td') |
local textCell = bodyRow:newline():tag('td') |
||
textCell:addClass('mbox-text plainlist') |
textCell:addClass('mbox-text plainlist') |
||
if data.textstyle or data. |
if data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'] then |
||
textCell:cssText(data.textstyle or data. |
textCell:cssText(data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo']) |
||
end |
end |
||
textCell:wikitext(data.text) |
textCell:wikitext(data.text or data.texto) |
||
if data.imageright or data. |
if data.imageright or data.imagemdireita or data['imagem-direita'] then |
||
bodyRow:newline():tag('td') |
bodyRow:newline():tag('td') |
||
:addClass('mbox-imageright') |
:addClass('mbox-imageright') |
||
:wikitext(data.imageright or data. |
:wikitext(data.imageright or data.imagemdireita or data['imagem-direita']) |
||
end |
end |
||
-- The below row |
-- The below row |
||
if data.below or data. |
if data.below or data.abaixo then |
||
local belowCell = root:newline():tag('tr'):tag('td') |
local belowCell = root:newline():tag('tr'):tag('td') |
||
belowCell |
belowCell |
||
:attr('colspan', (data.imageright and 3) or (data. |
:attr('colspan', (data.imageright and 3) or (data.imagemdireita and 3) or (data['imagem-direita'] and 3) or 2) |
||
:addClass('mbox-text') |
:addClass('mbox-text') |
||
if data.textstyle or data. |
if data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'] then |
||
belowCell:cssText(data.textstyle or data. |
belowCell:cssText(data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo']) |
||
end |
end |
||
belowCell:wikitext(data.below or data. |
belowCell:wikitext(data.below or data.abaixo) |
||
end |
end |
||
root:newline() |
|||
return tostring(root) |
return tostring(root) |
||
end |
end |
Edição atual tal como às 20h37min de 15 de agosto de 2019
Este módulo é usado em mais de 4 000 páginas e as alterações em seu conteúdo serão amplamente notadas. Por favor, teste as alterações na subpágina de testes deste módulo, na subpágina de testes de módulos ou na subpágina de testes em seu espaço usuário. Considere discutir mudanças na página de discussão antes de implementá-las. |
Descrição[editar código-fonte]
Este Módulo implementa a predefinição {{Caixa lateral}}
. Por favor consulte a predefinição para mais instruções.
Uso[editar código-fonte]
Outra documentação:
A documentação acima é transcluída de Módulo:Caixa lateral/doc. (editar | histórico) Editores podem experimentar nas páginas de teste (editar | dif) e de exemplos para testes (criar) deste módulo. Subpáginas deste módulo. |
-- This module implements {{side box}}.
local yesno = require('Módulo:Yesno')
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 data = p.makeData(args)
return p.renderSidebox(data)
end
function p.makeData(args)
local data = {}
-- Main table classes
data.classes = {}
if yesno(args.metadata) ~= false or yesno(args.metadados) ~= false then
table.insert(data.classes, 'metadata')
end
if args.position and args.position:lower() == 'left' or args['posição'] and args['posição']:lower() == 'left' then
table.insert(data.classes, 'mbox-small-left')
else
table.insert(data.classes, 'mbox-small')
end
table.insert(data.classes, args.class or args.classe)
-- Image
if args.image and args.image ~= 'none' and args.image ~= 'nenhuma' then
data.image = args.image
elseif args.imagem and args.imagem ~= 'none' and args.imagem ~= 'nenhuma' then
data.imagem = args.imagem
end
-- Copy over data that doesn't need adjusting
local argsToCopy = {
-- Styles
'style',
'estilo',
'textstyle',
'estilotexto',
'textoestilo',
'estilo-texto',
'texto-estilo',
-- Above row
'above',
'acima',
'abovestyle',
'acimaestilo',
'estiloacima',
'acima-estilo',
'estilo-acima',
-- Body row
'text',
'texto',
'imageright',
'imagemdireita',
'imagem-direita',
-- Below row
'below',
'abaixo',
}
for i, key in ipairs(argsToCopy) do
data[key] = args[key]
end
return data
end
function p.renderSidebox(data)
-- Renders the sidebox HTML.
-- Table root
local root = mw.html.create('table')
root:attr('role', 'presentation')
for i, class in ipairs(data.classes or {}) do
root:addClass(class)
end
root:css{border = '1px solid #aaa', ['background-color'] = '#f9f9f9', color = '#000'}
if data.style or data.estilo then
root:cssText(data.style or data.estilo)
end
-- The "above" row
if data.above or data.acima then
local aboveCell = root:newline():tag('tr'):tag('td')
aboveCell
:attr('colspan', data.imageright and 3 or 2)
:addClass('mbox-text')
if data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'] then
aboveCell:cssText(data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'])
end
if data.abovestyle or data.estiloacima or data.acimaestilo or data['estilo-acima'] or data['acima-estilo'] then
aboveCell:cssText(data.abovestyle or data.estiloacima or data.acimaestilo or data['estilo-acima'] or data['acima-estilo'])
end
aboveCell
:newline()
:wikitext(data.above or data.acima)
end
-- The body row
local bodyRow = root:newline():tag('tr'):newline()
if data.image or data.imagem then
bodyRow:tag('td')
:addClass('mbox-image')
:wikitext(data.image or data.imagem)
else
bodyRow:tag('td'):css('width', '1px')
end
local textCell = bodyRow:newline():tag('td')
textCell:addClass('mbox-text plainlist')
if data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'] then
textCell:cssText(data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'])
end
textCell:wikitext(data.text or data.texto)
if data.imageright or data.imagemdireita or data['imagem-direita'] then
bodyRow:newline():tag('td')
:addClass('mbox-imageright')
:wikitext(data.imageright or data.imagemdireita or data['imagem-direita'])
end
-- The below row
if data.below or data.abaixo then
local belowCell = root:newline():tag('tr'):tag('td')
belowCell
:attr('colspan', (data.imageright and 3) or (data.imagemdireita and 3) or (data['imagem-direita'] and 3) or 2)
:addClass('mbox-text')
if data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'] then
belowCell:cssText(data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'])
end
belowCell:wikitext(data.below or data.abaixo)
end
return tostring(root)
end
return p