Módulo:Caixa lateral: diferenças entre revisões

Origem: Wikipédia, a enciclopédia livre.
Conteúdo apagado Conteúdo adicionado
Jmarchn (discussão | contribs)
Jmarchn (discussão | contribs)
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('Module:Yesno')
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 (args.position and args.position:lower() == 'left') or (args['posició'] and args['posició']:lower() == 'esquerra') then
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.imatge and args.imatge ~= 'none' then
elseif args.imagem and args.imagem ~= 'none' and args.imagem ~= 'nenhuma' then
data.imatge = args.imatge
data.imagem = args.imagem
end
end


Linha 48: Linha 48:
-- Styles
-- Styles
'style',
'style',
'estilo',
'textstyle',
'textstyle',
'estil',
'estilotexto',
'estil_de_text',
'textoestilo',
'estilo-texto',
'texto-estilo',


-- Above row
-- Above row
'above',
'above',
'acima',
'abovestyle',
'abovestyle',
'dalt',
'acimaestilo',
'estil_de_dalt',
'estiloacima',
'acima-estilo',
'estilo-acima',


-- Body row
-- Body row
'text',
'text',
'texto',
'imageright',
'imageright',
'imatge_dreta',
'imagemdireita',
'imagem-direita',


-- Below row
-- Below row
'below',
'below',
'sota',
'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.estil then
if data.style or data.estilo then
root:cssText(data.style or data.estil)
root:cssText(data.style or data.estilo)
end
end


-- The "above" row
-- The "above" row
if data.above or data.dalt then
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', (data.imageright and 3) or (data.imatge_dreta and 3) or 2)
:attr('colspan', data.imageright and 3 or 2)
:addClass('mbox-text')
:addClass('mbox-text')
if data.textstyle or data.estil_de_text then
if data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'] then
aboveCell:cssText(data.textstyle or data.estil_de_text)
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.estil_de_dalt then
if data.abovestyle or data.estiloacima or data.acimaestilo or data['estilo-acima'] or data['acima-estilo'] then
aboveCell:cssText(data.abovestyle or data.estil_de_dalt)
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.dalt)
: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.imatge then
if data.image or data.imagem then
bodyRow:tag('td')
bodyRow:tag('td')
:addClass('mbox-image')
:addClass('mbox-image')
:wikitext(data.image or data.imatge)
: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.estil_de_text then
if data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'] then
textCell:cssText(data.textstyle or data.estil_de_text)
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.imatge_dreta then
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.imatge_dreta)
:wikitext(data.imageright or data.imagemdireita or data['imagem-direita'])
end
end


-- The below row
-- The below row
if data.below or data.sota then
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.imatge_dreta and 3) or 2)
: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.estil_de_text then
if data.textstyle or data.estilotexto or data.textoestilo or data['estilo-texto'] or data['texto-estilo'] then
belowCell:cssText(data.textstyle or data.estil_de_text)
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.sota)
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

Documentação do módulo[ver] [editar] [histórico] [purgar]

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:

-- 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