Módulo:Caixa lateral

Origem: Wikipédia, a enciclopédia livre.
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