Módulo:Su

Permanently protected module
Origem: Wikipédia, a enciclopédia livre.
Documentação do módulo[ver] [editar] [histórico] [purgar]


Descrição

Este módulo implementa a predefinição {{su}}. Ela é utilizada para criar duas linhas mais pequenas de texto em uma linha atual.

Utilização desde texto wiki

Este módulo não pode ser usado diretamente de texto wiki. Apenas pode ser utilizada através de uma predefinição, que é normalmente a predefinição {{su}}. Por favor consulte a página de documentação da predefinição.

Utilização desde módulos Lua

Para utilizar este módulo desde outros módulos Lua, primeiro carregue o módulo.

local mSu = require('Módulo:Su')

Voçê pode gerar as ligações su ao utilizar a função _main.

mSu._main(sup, sub, options)

sup é o conteúdo do topo da linha, e sub é o conteúdo inferior da linha. options é uma tabela que tem os seguintes campos:

  • align - este pode definir-se "r" ou "right" para alinhamento à direita, e "c" ou "center" para centrar. Qualquer outro valor mostra-se alinhado à esquerda. Ele deve ser um valor de cadeia de texto.
  • fontSize - o tamanho ou largura da fonte do texto, e.g. "90%". Se está definido para "f" ou "fixed", o módulo mostra o texto com fonte de largura fixa de 85%. Valor tem que ser texto.
  • lineHeight - a distância do topo até fundo (incluindo caractere no topo). Valor padrão é 1.2em. Valor tem que ser texto.
  • verticalAlign - o alinhamento base da parte inferior. Valor padrão depende se existe sub; -0.4em se estiver definido, 0.8em se não estiver definido. Valor tem que ser texto.

Todos os argumentos são opcionais.

Exemplos

Code Resultado
mSu._main('texto linha-cima', 'texto linha-inferior') texto linha-cima
texto linha-inferior
mSu._main('texto linha-cima', 'texto linha-inferior', {fontSize = '100%'}) texto linha-cima
texto linha-inferior
mSu._main('texto linha-cima', 'texto linha-inferior', {fontSize = 'f'}) texto linha-cima
texto linha-inferior
mSu._main('texto linha-cima', 'texto linha-inferior', {align = 'r'}) texto linha-cima
texto linha-inferior
mSu._main('texto linha-cima', 'texto linha-inferior', {align = 'c'}) texto linha-cima
texto linha-inferior
mSu._main('12', '8', {align = 'c', lineHeight = '0.8em'}) 12
8
mSu._main('texto linha-cima') texto linha-cima
mSu._main(nil, 'texto linha-inferior')
texto linha-inferior

-- This module implements {{su}}.

local p = {}

function p.main(frame)
	-- Use arguments from the parent frame only, and remove any blank arguments.
	-- We don't need to trim whitespace from any arguments, as this module only
	-- uses named arguments, and whitespace is trimmed from them automatically. 
	local origArgs = frame:getParent().args
	local args = {}
	for k, v in pairs(origArgs) do
		if v ~= '' then
			args[k] = v
		end
	end

	-- Define the variables to pass to luaMain.
	local sup = args.p
	local sub = args.b
	local options = {
		align = args.a,
		fontSize = args.w,
		lineHeight = args.lh,
		verticalAlign = args.va
	}
	return p._main(sup, sub, options)
end

function p._main(sup, sub, options)
	options = options or {}
	local span = mw.html.create('span')

	-- Set the styles.
	span:css{
		['display']        = 'inline-block',
		['margin-bottom']  = '-0.3em',
		['vertical-align'] = options.verticalAlign or sub and '-0.4em' or '0.8em',
		['line-height']    = options.lineHeight or '1.2em'
	}
	if options.fontSize == 'f' or options.fontSize == 'fixed' then
		span:css{
			['font-family'] = 'monospace,monospace',
			['font-size']   = '80%'
		}
	else
		span:css('font-size', options.fontSize and options.fontSize or '80%')
	end
	if options.align == 'r' or options.align == 'right' then
		span:css('text-align', 'right')
	elseif options.align == 'c' or options.align == 'center' then
		span:css('text-align', 'center')
	else
		span:css('text-align', 'left')
	end

	-- Add the wikitext.
	span
		:wikitext(sup)
		:tag('br', {selfClosing = true}):done()
		:wikitext(sub)
	
	return tostring(span)
end

return p