Módulo:Título

De Wikisource, la biblioteca libre.
Documentación del módulo

Módulo para implementar {{Título}}, la plantilla para simplificar portadas tradicionales de libros

El formato es el que sigue

{{título|
{+++}NUEVA PLANTILLA
{+} PARA EL USO EN PORTADAS
Y PÁGINAS  DE LIBROS SEMEJANTES
{>, -} Texto a la derecha
{<, -} Texto a la izquierda 
{_2}
{+}2024
}}
NUEVA PLANTILLA
PARA EL USO EN PORTADAS
Y PÁGINAS DE LIBROS SEMEJANTES
Texto a la derecha
Texto a la izquierda

2024

Uso

Pendiente documentar las intrincaciones del código LUA
Esta documentación está transcluida desde Módulo:Título/doc.
Los editores pueden experimentar en la zona de pruebas de este módulo.
Por favor, añade las categorías e interwikis a la subpágina de documentación. Subpáginas de este módulo.

-- Modulo para portadas de título y páginas con diseño complejo como esas

require('strict')
local FACTOR = 1.2

local p = {}

local getArgs = require('Módulo:Arguments').getArgs

local function formatdiv(frame, div, style)
	local styles = mw.text.split(style, ',')
	for _, st in ipairs(styles) do  -- loop entre estilos
		local st = mw.text.trim(st)
		local GRANDE  = mw.ustring.match(st, '%++')
		if GRANDE then	div:css('font-size',tostring(FACTOR^tonumber(#GRANDE)*100)..'%') end
		local CHICO  = mw.ustring.match(st, '%-+')
		if CHICO then	div:css('font-size',tostring(FACTOR^tonumber(-#CHICO)*100)..'%') end
		
		local IZQ = mw.ustring.match(st, '%<')
		if IZQ then	div:css('text-align','left') end
		local DER = mw.ustring.match(st, '%>')
		if DER then	div:css('text-align','right') end
		
		local LIN = mw.ustring.match(st, '%_(%d*)')
		if LIN then
			if LIN ~= '' then LIN = LIN..'em' end
			div:wikitext(frame:expandTemplate{ title = 'línea', args = { LIN } }) 
		end
		local WAVE = mw.ustring.match(st, '%~(%d+)')
		if WAVE then div:wikitext(string.rep("[[Archivo:Rule_Segment_-_Wave_-_40px.svg]]", tonumber(WAVE))) end
	end
	
	return div
end

local function processdiv(frame, text)
	-- PROCESAMIENTO DE LÍNEAS INDIVIDUALES
	-- Acá se definirán los estilos a aplicarse a cada línea, separados por ,
	-- El formato general será {estilo1, estilo2, estilo3} y podríamos copiar el estándar q se usa en el Módulo:Centrar
	--[[ TODO: 
	  4) máquina q convierta palabra (menor, underline) en función
	  5) exportar esa máquina de vuelta al Módulo:Centrar                
	  ]]--
	  local div = mw.html.create('div'):css('page-break-after', 'always')
	  local components = mw.text.split(text,'[{}]')
	  
	  if #components == 1 then          --caso base, sin formato
	  	if #text == 0 then text = '&nbsp;' end --línea en blanco: agregar espacio para q no colapse. 
	  	return div:wikitext(text)
	  elseif #components == 3 then      --caso bien formatetado
	  	div = formatdiv(frame, div,components[2])
	  	return div:wikitext(components[3])
	  else                             --cualquier otra cosa
	  	return div:wikitext('LÍNEA MAL FORMATEADA'):cssText('color:red;font-weight:bold')
	  end

end

function p.portada( frame )
	
	local argus = getArgs(frame) -- crea una tabla con los parámetros incluídos en la plantilla, y elimina parámetros vacíos
	
	local html = mw.html.create() -- cuerpo principal de la plantilla
	
	local BIG=html:tag('div'):addClass('ws-titleblock'):cssText('margin:auto;text-align:center')
	local ancho = argus['ancho'] or 'fit-content' --MEJORAR
	local lineheight = argus['lh'] or '1.6'
	
	if argus['factor'] then FACTOR = tonumber(argus['factor']) end
	
	BIG:css('width',ancho)
	BIG:css('line-height',lineheight)
	
	local texto = argus[1] or ''
	local lineas = mw.text.split(texto, '\n')
	
	for i, v in ipairs(lineas) do
		local div = processdiv(frame, v)
		div:addClass('ws-titleblock-line'..i)
		
		BIG:node(div)
		
	end

	return tostring(html)
end

return p