Diferencia entre revisiones de «Módulo:Centrar»
Contenido eliminado Contenido añadido
Sin resumen de edición |
bugfix |
||
Línea 121: | Línea 121: | ||
end |
end |
||
if argus['colgante'] == 's' then --asimilar comportamieto de {{sangría colgante}} |
if argus['colgante'] == 's' then --asimilar comportamieto de {{sangría colgante}} |
||
div:css('margin-left', |
div:css('margin-left', '2em') |
||
div:css('text-indent', '- |
div:css('text-indent', '-2em') |
||
local margen = argus['margen'] or argus[2] |
|||
if tonumber(margen:sub(1,1)) then |
|||
div:css('margin-left', margen) |
|||
div:css('text-indent', '-'..margen) |
|||
end |
|||
end |
end |
||
if argus['bloque'] == 'centro' then --asimilar comportamiento de {{bloque centro}} |
if argus['bloque'] == 'centro' then --asimilar comportamiento de {{bloque centro}} |
Revisión del 23:19 19 nov 2017
[editar] [ ]
Documentación del módulo
Uso
En: {{centrar}}, {{derecha}}, {{Flotador izquierda}}, {{Flotador derecha}}, {{sangría colgante}}, {{bloque centro}}, {{bloque derecha}}, {{bloque izquierda}}Esta documentación está transcluida desde Módulo:Centrar/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.
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.
-- módulo para plantillas de formato
local p = {}
local tamFuente = { --tamaños de letra segun nombre de las plantillas
['xx-menor']="58%" ,
['x-menor']="69%" ,
['menor']="83%" ,
['grande']="120%" ,
['x-grande']="144%" ,
['xx-grande']="182%" ,
['xxx-grande']="207%" ,
['xxxx-grande']="249%" ,
['xxxxx-grande']="283%" ,
['xxxxxx-grande']="323%",
['sm']="smaller"
}
local textTransform = {
['lc']='lowercase' ,
['uc']='uppercase' ,
['cap']='capitalize'
}
local fontVariant = {
['sc']='small-caps',
['may']='small-caps'
}
local fontFamily = { --familia genérica de fuentes
['monospace']='monospace',
['serif']='serif',
['sans-serif']='sans-serif',
['cursive']='cursive',
['fantasy']='fantasy'
}
local altparams= {['font-size']='fs', ['tamaño']='fs',
['line-height']='lh', ['interlineado']='lh',
['letter-spacing']='sp', ['espaciado']='sp',
['offset']='margen',
['id']='anclaje',
['width']='ancho',
['align'] = 'alinear',
['style'] = 'estilo'
}
function p.centrar( frame ) -- función principal para llamar desde {{centrar}}
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(argus['tag'] or 'div')
div:css('text-align', argus['alinear'])
if argus['float'] then
div:css('float', argus['float'])
end
-- sección de parámetros
if argus['fs'] and tamFuente[argus['fs']]~=nil then
div:css('font-size',tamFuente[argus['fs']]) --tamaños usando el nombre de las plantillas de tamaño de fuente
elseif argus['fs'] then
div:css('font-size',argus['fs']) -- tamaño personalizado
end
if argus['lh'] then
div:css('line-height',argus['lh'])
end
if argus['sp'] then
div:css('letter-spacing',argus['sp'])
end
if argus['color'] then
div:css('color',argus['color'])
end
-- sección de opciones
for k,v in pairs(argus) do -- opciones
if type(k) == 'number' and k~= 1 then
if textTransform[argus[k]] ~= nil then
div:css('text-transform',textTransform[argus[k]]) --opciones transformación de texto
elseif fontVariant[argus[k]] ~= nil then -- opcion variante de fuente (small caps)
div:css('font-variant',fontVariant[argus[k]])
elseif fontFamily[argus[k]] ~= nil then -- opcion familia de fuentes
div:css('font-family',fontFamily[argus[k]])
elseif tamFuente[argus[k]] ~= nil then -- opciones de tamaño de fuente sin usar el parámetro fs
div:css('font-size',tamFuente[argus[k]])
end
end
end
-- div:css('clear','both') — No utilidad aparente?
if argus['estilo'] then --estilo personalizado
div:cssText(argus['estilo'])
end
--texto
div:wikitext(argus[1])
--otros parámetros
if argus['plantilla'] == 'derecha' then --para reutilizar código en {{derecha}}
div:css('margin-right', argus['margen'] or argus[2] or '' )
end
if argus['float'] == 'right' then --asimilar comportamieto de {{float right}} y {{flotador derecha}}
div:css('margin-right', argus['margen'] or argus[2] or '0')
div:css('margin-top', argus[3] or '0')
div:css('margin-bottom', argus[3] or '0')
div:css('margin-left', argus[4] or '0')
end
if argus['float'] == 'left' then --asimilar comportamieto de {{float left}} y {{flotador izquierda}}
div:css('margin-top', argus[2] or '0')
div:css('margin-bottom', argus[2] or '0')
div:css('margin-right', argus[3] or '0')
end
if argus['colgante'] == 's' then --asimilar comportamieto de {{sangría colgante}}
div:css('margin-left', '2em')
div:css('text-indent', '-2em')
local margen = argus['margen'] or argus[2]
if tonumber(margen:sub(1,1)) then
div:css('margin-left', margen)
div:css('text-indent', '-'..margen)
end
end
if argus['bloque'] == 'centro' then --asimilar comportamiento de {{bloque centro}}
div:cssText('display: table; margin-right:auto; margin-left:auto')
div:css('width', argus['ancho'] or 'auto')
if argus['max-width'] then
div:css('max-width',argus['max-width'])
end
end
if argus['bloque'] == 'derecha' then --asimilar comportamiento de {{bloque derecha}}
div:css('width', argus['ancho'] or 'auto')
div:css('margin-right', argus['margen'] or '0em')
div:css('text-align', argus['alinear'] or 'inherit')
if argus['max-width'] then
div:css('max-width',argus['max-width'])
end
html:tag('div'):css('clear','right')
end
-- anclaje
if argus['anclaje'] then
div:attr('id', argus['anclaje'])
div:addClass('anclaje')
end
return tostring(html)
end
return p