Ir al contenido

Módulo:Línea

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


Uso

Esta documentación está transcluida desde Módulo:Línea/doc.
Los editores pueden experimentar en la zona de pruebas
Por favor, añade las categorías a la subpágina de documentación.
(subpáginas - enlaces)

-- Modulo para plantillas de líneas

local p = {}
local opciones = {
	['ac'] = 'Arrow Cross',
	['al'] = 'Arrow Left',
	['ar'] = 'Arrow Right',
	['atl'] = 'Arrow Thin Left',
	['atr'] = 'Arrow Thin Right',
	['bcrb'] = 'Black Crescent bottom',
	['bcrl'] = 'Black Crescent left',
	['bcrr'] = 'Black Crescent right',
	['bcrt'] = 'Black Crescent top',
	['c'] = 'Circle',
	['cll'] = 'Curl Left',
	['clr'] = 'Curl Right',
	['co'] = 'Circle open',
	['col'] = 'Colon',
	['crb'] = 'Crescent bottom',
	['crl'] = 'Crescent left',
	['crr'] = 'Crescent right',
	['crt'] = 'Crescent top',
	['d'] = 'Diamond',
	['do'] = 'Diamond open',
	['el'] = 'Ellipse',
	['elo'] = 'Ellipse open',
	['fc'] = 'Flare Centre',
	['fct'] = 'Flare Centre 5px',
	['fcw'] = 'Flare Centre White',
	['fl'] = 'Flare Left',
	['fr'] = 'Flare Right',
	['fy1'] = 'Fancy1',
	['fy2'] = 'Fancy2',
	['fy3'] = 'Fancy3',
	['fy4'] = 'Fancy4',
	['lo'] = 'loops',
	['lz'] = 'Lozenge',
	['lzt'] = 'Lozenge 5px',
	['qc'] = 'Quatrefoil in circle',
	['r'] = 'Rectangle',
	['s'] = 'Square',
	['so'] = 'Square open',
	['sp'] = 'Span',
	['str'] = 'Star',
	['tl'] = 'Tear Left',
	['tr'] = 'Tear Right',
	['ltr'] = 'Lefttriangle',
	['rtr'] = 'Righttriangle',
	['w'] = 'Wave',
}

local sugerencias= {
	["sp"] = "5, 10, 20, 40, 50, 100",
	["w"] = "1 a 40",
	["s"] = "5 10",
	["so"] = "5 10",
	["d"] = "4, 6, 10",
	["do"] = "7",
	["c"] = "6",
	["co"] = "6, 10, 20",
	["el"] = "15",
	["fl"] = "11,12,15,30,40",
	["fr"] = "11,12,15,30,40",
	["fc"] = "14, 22, 140",
	["tl"] = "20, 40",
	["tr"] = "20, 40",
	["cll"] = "10",
	["clr"] = "10",
	["fy1"] = "40",
	["fy2"] = "100",
	["fy3"] = "40",
	["str"] = "6, 10"
}
local altparams= {
	['align']='alinear', 
	['a']='alinear', 
	['width']='ancho', 
	['e']='espacio', 
	['height']='altura',
	['h']='altura',
	['style']='estilo',
	['class']='clase' 
}

function p.adornada( frame )
	local argus = {}
	for k,v in pairs(frame.args) do
		argus[k] = v 
	end
	for k,v in pairs(frame:getParent().args) do -- crea una tabla con los parámetros incluídos en la plantilla, y elimina parámetros vacíos
		argus[k] = v 
	end
	for k,v in pairs(altparams) do --parámetros con nobmres alternativos.
	if argus[k] and not argus[v] then
		argus[v] = argus[k]
	end
	end

	local html = mw.html.create() -- cuerpo principal de la plantilla
	local div=html:tag('div'):addClass('adornada')
	local i=1
	while argus[i]~= nil and argus[i+1]~=nil do
		-- si no lo reconocemos, pasarlo idéntico nomás
		if not opciones[argus[i]] then 
			opciones[argus[i]] = argus[i]
		end
		
		filename = "Rule Segment - "..opciones[argus[i]].." - " ..argus[i+1].."px.svg"
		file = mw.title.new(filename, 'File')
		
		if file.file.exists then
			div:wikitext("[[Archivo:"..filename .."|middle|alt=|link=]]")
		else
			div:wikitext("<small>[ "..filename.." no existe. ]</small>")
			if sugerencias[argus[i]] then
				div:wikitext("<small>{'''Sugerencias''': "..sugerencias[argus[i]]..". }</small>")
			end
		end
		
		i=i+2
	end
	if argus['espacio']~=nil then
		div:css('margin-top',argus['espacio'])
		div:css('margin-bottom',argus['espacio'])
	end
	return tostring(html)
end

function p.comun( frame )
	local argus = {}
	for k,v in pairs(frame.args) do
		argus[k] = v 
	end
	for k,v in pairs(frame:getParent().args) do -- crea una tabla con los parámetros incluídos en la plantilla, y elimina parámetros vacíos
		argus[k] = v 
	end
	
	for k,v in pairs(altparams) do --parámetros con nobmres alternativos.
	if argus[k] and not argus[v] then
		argus[v] = argus[k]
	end
    end

	local html = mw.html.create() -- cuerpo principal de la plantilla
	local div=html:tag('div')
	if argus['alinear']~=nil then
		if argus['alinear']=='left' or argus['alinear']=='izquierda' then
			div:css('margin','0em auto 0em 0em')
		elseif argus['alinear']=='right' or argus['alinear']=='derecha' then
			div:css('margin','0em 0em 0em auto')
		else
			div:css('margin','0em auto 0em auto')
		end
	else
		div:css('margin','0em auto 0em auto')
	end
	if argus['ancho']~=nil or argus[1]~=nil then
		div:css('width',argus['ancho'] or argus[1])
	end
	
	local clase='comun'
	if argus['clase']~=nil  then
		clase=argus['clase']
	end
	local hr =div:tag('hr'):addClass(clase)
	if argus['espacio']~=nil then
		hr:css('margin-top',argus['espacio'])
		hr:css('margin-bottom',argus['espacio'])
	end
	if argus['altura']~=nil then
		hr:css('height',argus['altura'])
	end
	if argus['color']  then
		if mw.ustring.sub( argus['color'], 0, 1 ) == '#' then
			color = argus['color']	
		else
			color = frame:expandTemplate{ title = 'RGB', args = { argus['color'] } }
		end
		
		color = mw.ustring.gsub(color, '&#35;', '#')
		
		hr:css('background-color',color)
	end
	if argus['estilo'] then  --estilo personalizado, al final para poder sobreescribir todo
		hr:cssText(argus['estilo'])
	end
	return tostring(html)
end

return p