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 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 plantillas de líneas

local p = {}
local opciones={ ["c"]="Circle", 
["co"]="Circle open", 
["col"]="Colon",
["d"]="Diamond",
["do"]="Diamond open",
["fl"]="Flare Left",
["fr"]="Flare Right",
["fc"]="Flare Centre",
["fy1"]="Fancy1",
["fy2"]="Fancy2",
["fy3"]="Fancy3",
["cll"]="Curl Left",
["clr"]="Curl Right",
["el"]="Ellipse",
["lz"]="Lozenge",
["lzt"]="Lozenge 5px",
["r"]="Rectangle",
["so"]="Square open",
["s"]="Square",
["w"]="Wave",
["tr"]="Tear Right",
["tl"]="Tear Left",
["str"]="Star",
["crt"]="Crescent top",
["crr"]="Crescent right",
["crb"]="Crescent bottom",
["crl"]="Crescent left",
["sp"]="Span" }
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