Diferencia entre revisiones de «Módulo:Centrar»

Contenido eliminado Contenido añadido
Sin resumen de edición
versión funcionalmente idéntica pero casi la mitad de grande, código más limpio // avisar cualquier catástrofe por favor
Etiqueta: Revertido
Línea 1:
-- módulo para plantillas de formato
local p = {}
local make_style_string = require('Module:Optional style').make_style_string
 
local tamFuente = { --tamaños de letra segun nombre de las plantillas
['xx-menor']="58%" ,
Línea 61 ⟶ 63:
['ancho']=1,['estilo']=1,['color']=1,['fondo']=1,['plantilla']=1,['colgante']=1,['bloque']=1, ['clase']=1}
 
function argus_estilo(argus)
function p.centrar( frame ) -- función principal para llamar desde {{centrar}}
-- Función que procesa la lista de parámetros (argus) y
local argus = {}
-- regresa una table con todos los estilos CSS
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
 
local css = {}
for k,v in pairs(altparams) do --parámetros con nobmres alternativos.
local clases = {}
if argus[k] and not argus[v] then
argus[v] = argus[k]
css['text-align'] = argus.alinear
end
css['width'] = argus.ancho
end
css['float'] = argus.float
 
local html = mw.html.create() -- cuerpo principal de la plantilla
local div = html:tag(argus['tag'] or 'div')
-- sección de parámetros
div:css('text-align', argus['alinear'])
---- tamaño
if argus['ancho'] then
if argus.fs and tamFuente[argus.fs]~=nil then
div:css('width', argus['ancho'])
css['font-size'] = tamFuente[argus.fs] -- tamaños usando el nombre de las plantillas de tamaño de fuente
end
ifelseif argus['float'].fs then
css['font-size'] = argus.fs -- tamaño personalizado
div:css('float', argus['float'])
end
if argus.lh then
-- sección de parámetros
if argus css['fsline-height'] and= tamFuente[argus['fs']]~=nil then.lh
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'].sp then
div:css(['lineletter-heightspacing',] = argus['lh']).sp
end
if argus['sp'] then
div:css('letter-spacing',argus['sp'])
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, '#', '#')
div:css('color',color)
end
if argus['fondo'] then
if mw.ustring.sub( argus['fondo'], 0, 1 ) == '#' then
fondo = argus['fondo']
else
fondo = frame:expandTemplate{ title = 'RGB', args = { argus['fondo'] } }
end
fondo = mw.ustring.gsub(fondo, '#', '#')
div:css('background',fondo)
end
-- sección de opciones
Línea 126 ⟶ 93:
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]])
elseif fontWeight[argus[k]] ~= nil then -- opcion de peso de fuente (negrita)
div:css(['font-weight',] = fontWeight[argus[k]])
elseif fontStyle[argus[k]] ~= nil then -- opcion de estilo de fuente (cursiva)
div:css(['font-style',] = fontStyle[argus[k]])
elseif textDecoration[argus[k]] ~= nil then -- opcion de decoracion de texto (subrayado)
div:css(['text-decoration',] = textDecoration[argus[k]])
end
end
end
-- div:css(['clear',] = 'both') — No utilidad aparente?
 
--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])
end
if argus['.float'] == 'right' then --asimilar comportamieto de {{float right}} y {{flotador derecha}}
div:addClasstable.insert(clases, 'ws-flotador-d')
div:css(['margin-right',] = argus['.margen'] or argus[2])
div:css(['margin-top',] = argus[3])
div:css(['margin-bottom',] = argus[3])
div:css(['margin-left',] = argus[4])
end
if argus['.float'] == 'left' then --asimilar comportamieto de {{float left}} y {{flotador izquierda}}
div:addClasstable.insert(clases, 'ws-flotador-i')
div:css(['margin-top',] = argus[2])
div:css(['margin-bottom',] = argus[2])
div:css(['margin-right',] = argus[3])
end
if argus['.colgante'] == 's' then --asimilar comportamieto de {{sangría colgante}}
div:addClasstable.insert(clases, 'ws-sangria-colgante')
local margen = argus.margen or argus[2] or 'NaN'
if tonumber(margen:sub(1,1)) then
css['margin-left'] = margen
css['text-indent'] = '-'..margen
end
if argus['colgante'] == 'm' then --asimilar comportamieto de {{sangría colgante/m}}
table.insert(clases,'ws-sangria-colgante-m')
local margen = argus['margen'] or argus[2] or 'NaN'
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}}
div:addClass('ws-bloque-centro')
table.insert(clases, 'ws-bloque-centro')
if argus['max-width'] then
div:css(['max-width',] = argus['max-width'])
end
elseif argus['.bloque'] == 'derecha' then --asimilar comportamiento de {{bloque derecha}}
div:addClasstable.insert(clases, 'ws-bloque-derecha')
div:css(['margin-right',] = argus['.margen'])
div:css(['text-align',] = argus['.alinear'])
if argus['max-width'] then
div:css(['max-width',] = argus['max-width'])
end
 
html:tag('div'):css('clear','right')
elseif argus.bloque == 'izquierda' then --asimilar comportamiento de {{bloque izquierda}}
table.insert(clases, 'ws-bloque-izquierda')
elseif argus['bloque'] == 'izquierda' then --asimilar comportamiento de {{bloque izquierda}}
css['margin-left'] = argus.margen or argus[2]
div:addClass('ws-bloque-izquierda')
div:css('margin-left', argus['margen'] or argus[2])
if argus['max-width'] then
div:css(['max-width',] = argus['max-width'])
end
end
if argus['.estilo'] then --estilo personalizado, al final para poder sobreescribir todo
div:cssText(arguscss['estilo']) = argus.estilo
end
return css, clases
-- anclaje
end
if argus['anclaje'] then
function color_string(frame, color)
div:attr('id', argus['anclaje'])
if mw.ustring.sub( color, 0, 1 ) == '#' then
div:addClass('anclaje')
color = color
else
color = frame:expandTemplate{ title = 'RGB', args = { color } }
end
color = mw.ustring.gsub(color, '#', '#')
return color
end
-- función principal para llamar desde {{centrar}} o similar
function p._centrar(frame, argus )
if local texto = argus['clase'1] then
div:addClass(local id = argus[.anclaje or 'clase'])
local css, clases = argus_estilo(argus)
local tag = argus.tag or 'div'
-- manejo especial para el color
if argus.color then
css['color'] = color_string(frame, argus.color)
end
if argus.fondo then
css['background'] = color_string(frame, argus.fondo)
end
-- anclaje (ID)
if id ~= '' then
table.insert(clases, 'anclaje')
end
-- clases CSS adicionales
if argus.clase then
table.insert(clases, argus.clase)
end
-- inicio de tag
contenido = '<'..tag..' '
-- atributos HTML
atributos = {
'id="'..id..'"',
'class="'..table.concat(clases, ' ')..'"',
make_style_string(css)
}
-- agregar atributos
contenido = contenido..table.concat(atributos, ' ')..'>'
-- agregar texto y cerrar tag si no estamos en {{plantilla/c}}
if not argus.open then
contenido = contenido..texto..'</'..tag..'>'
if argus.bloque == 'derecha' then -- fix para {{bloque derecha}}
contenido = contenido..'<br style="clear:right"/>'
end
end
-- categorías de mantenimiento
for k,v in pairs(argus) do
if (type(k) ~= 'number') and (params[k]==nil) and (altparams[k]==nil) then
html:wikitext(contenido = contenido .. '[[Categoría:Wikisource:Artículos que usan parámetros no reconocidos en el módulo Centrar]]')
end
end
return contenido
return tostring(html)
end
 
function p.open( frame ) -- función principal para llamar desde {{bloque centro/c}} y similares
local argus = {}
local clases = {}
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
 
-- metafunciones
for k,v in pairs(altparams) do --parámetros con nobmres alternativos.
function main(frame, argus)
if argus[k] and not argus[v] then
--parámetros con nobmres alternativos
argus[v] = argus[k]
for k,v in pairs(altparams) do
end
if argus[k] and not argus[v] then
end
argus[v] = argus[k]
 
local div = '<'..(argus['tag'] or 'div').. ' style="'
div=div..'text-align:'..(argus['alinear'] or '')..';'
if argus['ancho'] then
div=div..'width:'..(argus['ancho'])..';'
end
if argus['float'] then
div=div..'float:'..argus['float']..';'
end
-- sección de parámetros
if argus['fs'] and tamFuente[argus['fs']]~=nil then
div=div..'font-size:'..tamFuente[argus['fs']]..';' --tamaños usando el nombre de las plantillas de tamaño de fuente
elseif argus['fs'] then
div=div..'font-size:'..argus['fs']..';' -- tamaño personalizado
end
if argus['lh'] then
div=div..'line-height:'..argus['lh']..';'
end
if argus['sp'] then
div=div..'letter-spacing:'..argus['sp']..';'
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;', '#')
div=div..'color:'..color..';'
end
if argus['fondo'] then
if mw.ustring.sub( argus['fondo'], 0, 1 ) == '#' then
fondo = argus['fondo']
else
fondo = frame:expandTemplate{ title = 'RGB', args = { argus['fondo'] } }
end
fondo = mw.ustring.gsub(fondo, '&#35;', '#')
div=div..'background:'..fondo..';'
end
-- sección de opciones
for k,v in pairs(argus) do -- opciones
if type(k) == 'number' then
if textTransform[argus[k]] ~= nil then
div=div..'text-transform:'..textTransform[argus[k]]..';' --opciones transformación de texto
elseif fontVariant[argus[k]] ~= nil then -- opcion variante de fuente (small caps)
div=div..'font-variant:'..fontVariant[argus[k]]..';'
elseif fontFamily[argus[k]] ~= nil then -- opcion familia de fuentes
div=div..'font-family:'..fontFamily[argus[k]]..';'
elseif tamFuente[argus[k]] ~= nil then -- opciones de tamaño de fuente sin usar el parámetro fs
div=div..'font-size:'..tamFuente[argus[k]]..';'
elseif fontWeight[argus[k]] ~= nil then -- opcion de peso de fuente (negrita)
div=div..'font-weight:'..fontWeight[argus[k]]..';'
elseif fontStyle[argus[k]] ~= nil then -- opcion de estilo de fuente (cursiva)
div=div..'font-style:'..fontStyle[argus[k]]..';'
elseif textDecoration[argus[k]] ~= nil then -- opcion de decoracion de texto (subrayado)
div=div..'text-decoration:'..textDecoration[argus[k]]..';'
end
end
end
return p._centrar(frame, argus)
-- div:css('clear','both') — No utilidad aparente?
end
 
-- función para plantillas cerradas
--otros parámetros
function p.centrar(frame)
if argus['plantilla'] == 'derecha' then --para reutilizar código en {{derecha}}
local argus = require('Module:Arguments').getArgs(frame)
div=div..'margin-right:'..(argus['margen'] or argus[1] or '')..';'
return main(frame, argus)
end
end
if argus['float'] == 'right' then --asimilar comportamieto de {{float right}} y {{flotador derecha}}
-- función para plantillas abiertas
table.insert(clases,'ws-flotador-d')
function p.open(frame)
div=div..'margin-right:'..( argus['margen'] or argus[1] or '')..';'
local argus = require('Module:Arguments').getArgs(frame)
div=div..'margin-top:'..( argus[2] or '')..';'
table.insert(argus, 1, '') -- inserta primer parámetro vacío para asimilar
div=div..'margin-bottom:'..( argus[2] or '')..';'
argus.open = true
div=div..'margin-left:'..( argus[3] or '')..';'
return main(frame, argus)
end
if argus['float'] == 'left' then --asimilar comportamieto de {{float left}} y {{flotador izquierda}}
table.insert(clases,'ws-flotador-i')
div=div..'margin-top:'..(argus[1] or '')..';'
div=div..'margin-bottom:'..(argus[1] or '')..';'
div=div..'margin-right:'..(argus[2] or '')..';'
end
if argus['colgante'] == 's' then --asimilar comportamieto de {{sangría colgante}}
table.insert(clases,'ws-sangria-colgante')
local margen = argus['margen'] or argus[1] or 'NaN'
if tonumber(margen:sub(1,1)) then
div=div..'margin-left:'..margen..';'
div=div..'text-indent:'..'-'..margen..';'
end
end
if argus['colgante'] == 'm' then --asimilar comportamieto de {{sangría colgante/m}}
table.insert(clases,'ws-sangria-colgante-m')
local margen = argus['margen'] or argus[1] or 'NaN'
if tonumber(margen:sub(1,1)) then
div=div..'margin-left:'..margen..';'
end
end
if argus['bloque'] == 'centro' then --asimilar comportamiento de {{bloque centro}}
table.insert(clases,'ws-bloque-centro')
if argus['max-width'] then
div=div..'max-width:'..argus['max-width']..';'
end
elseif argus['bloque'] == 'derecha' then --asimilar comportamiento de {{bloque derecha}}
table.insert(clases,'ws-bloque-derecha')
if argus['margen'] then
div=div..'margin-right:'..(argus['margen'] or '')..';'
end
if argus['alinear'] then
div=div..'text-align:'..(argus['alinear'])..';'
end
if argus['max-width'] then
div=div..'max-width:'..(argus['max-width'])..';'
end
--html:tag('div'):css('clear','right') -- ATENCION!!!
elseif argus['bloque'] == 'izquierda' then --asimilar comportamiento de {{bloque izquierda}}
table.insert(clases,'ws-bloque-izquierda')
if (argus['margen'] or argus[1]) then
div=div..'margin-left:'..(argus['margen'] or argus[1])..';'
end
if argus['max-width'] then
div=div..'max-width:'..(argus['max-width'])..';'
end
end
if argus['estilo'] then --estilo personalizado, al final para poder sobreescribir todo
div=div..argus['estilo']..';'
end
div=div..'" '
-- anclaje
if argus['anclaje'] then
div=div..'id="'..argus['anclaje']..'"'
div=div..'class="anclaje" '
end
--clases
div=div..'class="'
for k,c in ipairs(clases) do
div = div..c..' '
end
if argus['clase'] then
div=div..argus['clase']
end
div=div..'"'
--
div=div..'>'
mw.log(div)
return tostring(div)
end
 
return p