stringtranslate.com

Módulo:Lista

local  libUtil  =  require ( 'libraryUtil' ) local  checkType  =  libUtil . checkType local  mTableTools  =  require ( 'Module:TableTools' ) local p = {} local listTypes = { [ 'bulleted' ] = true , [ 'unbulleted' ] = true , [ 'horizontal' ] = true , [ 'ordered' ] = true , [ 'horizontal_ordered' ] = true } function p . makeListData ( listType , args ) -- Construye una tabla de datos para pasarla a p.renderList. local data = {} -- Clases y TemplateStyles data . classes = {} data . templatestyles = '' if listType == 'horizontal' or listType == 'horizontal_ordered' then table. insert ( data . classes , 'hlist' ) data . templatestyles = mw . getCurrentFrame ( ) : extensionTag { nombre = 'templatestyles' , args = { src = 'Hlist/styles.css' } } elseif listType == 'unbulleted' then tabla.insert ( datos.classes , 'plainlist' ) datos.templatestyles = mw.getCurrentFrame ( ) : extensionTag { nombre = ' templatestyles ' , args = { src = ' Plainlist / styles.css' } } fin tabla.insert ( datos.classes ,argumentos .                                                              class ) -- Estilo div principal data . style = args . style -- Sangría para listas horizontales if listType == 'horizontal' or listType == 'horizontal_ordered' then local indent = tonumber ( args . indent ) indent = indent and indent * 1.6 or 0 if indent > 0 then data . marginLeft = indent .. 'em' end end -- Tipos de estilo de lista para listas ordenadas -- Puede ser "1, 2, 3", "a, b, c" o algún otro. El tipo de estilo de lista se establece mediante el atributo "type" o la propiedad CSS "list-style-type". if listType == 'ordered' or listType == 'horizontal_ordered' then data . listStyleType = args . list_style_type or args [ 'list-style-type' ] data . type = args [ 'type' ] - Detecta atributos de tipo no válidos e intenta convertirlos en propiedades CSS list-style-type. if data . type y no data . listStyleType y no tostring ( data . type ): find ( '^%s*[1AaIi]%s*$' ) then data . listStyleType = data . type data . type = nil end end - Tipo de etiqueta de lista if listType == 'ordered' or listType == 'horizontal_ordered' then data . listTag = 'ol' else data . listTag = 'ul' end - Número de inicio para listas ordenadas data . start = args .empezar si                                                                     listType  ==  'horizontal_ordered'  then -- Aplicar corrección para que los números iniciales funcionen con listas ordenadas horizontalmente. local startNum = tonumber(data.start) if startNum then data.counterReset = 'listitem' .. tostring(startNum - 1 ) end end -- Estilo de lista -- ul_style y ol_style están incluidos para compatibilidad con versiones anteriores . No -- se hace distinción entre listas ordenadas o no ordenadas. data.listStyle = args.list_style -- Elementos de lista -- li_style está incluido para compatibilidad con versiones anteriores. item_style fue incluido -- para que sea más fácil de entender para quienes no saben codificar. data.itemStyle = args.item_style or args.li_style data.items = { } for _ , num in ipairs ( mTableTools.numKeys ( args ) ) do local item = { } item.content = args [ num ] item . estilo = args [ 'item' .. tostring ( num ) .. '_style' ] o args [ 'item_style' .. tostring ( num )] item .value = args [ ' item ' .. tostring ( num ) .. ' _value ' ] o args [ ' item_value ' .. tostring ( num ) ] tabla.insert ( data .items , item ) end return data end función p .renderList ( data ) -- Representa la lista HTML . -- Devuelve la cadena en blanco si no hay elementos en la lista . if                                                     tipo ( datos.items )        ~ = ' tabla' o # datos.items < 1 entonces devuelve ' ' fin - Representa la etiqueta div principal. raíz local = mw.html.create ( ' div ' ) para _ , clase en ipairs ( datos.classes o { } ) hacer raíz : addClass ( clase ) fin raíz : css { [ 'margin-left' ] = datos.marginLeft } si datos.style entonces raíz : cssText ( datos.style ) fin - Representa la etiqueta lista. lista local = raíz : etiqueta ( datos.listTag o ' ul ' ) lista : attr { inicio = datos.start , tipo = datos.type } : css { [ ' counter - reset ' ] = datos.counterReset , [ ' list - style - type ' ] = datos.listStyleType } si datos . listStyle entonces list : cssText ( data . listStyle ) fin - Representa los elementos de la lista para _ , t en ipairs ( data . items o {}) do local item = list : tag ( 'li' ) if data . itemStyle then item : cssText ( data . itemStyle ) fin if t . style then                                             elemento : cssText ( t.style ) fin elemento : attr { valor = t.value } : wikitext ( t.content ) fin devolver datos.templatestyles..tostring ( root ) fin función p.renderTrackingCategories ( args ) local isDeprecated = false -- Realiza un seguimiento de los parámetros obsoletos. para k, v en pares(args) hacer k = tostring ( k ) si k : find ( ' ^ item_style % d + $ ' ) o k : find ( ' ^ item_value % d + $ ' ) entonces isDeprecated = true break fin fin local ret = ' ' si isDeprecated entonces ret = ret .. ' [ [ Categoría :Plantillas de lista con parámetros obsoletos ] ] ' fin devolver ret fin función p . makeList ( listType , args ) si no es listType o no listTypes [ listType ] entonces error ( string.format ( "argumento incorrecto n.° 1 para 'makeList' ('%s' no es un tipo de lista válido)" , tostring ( listType ) ) , 2 ) fin checkType ( 'makeList ' , 2 , args , ' table ' ) datos locales = p.makeListData ( listType , args ) lista local = p.renderList ( data ) categorías de seguimiento locales = p.renderTrackingCategories                                                       ( args ) devuelve lista .. trackingCategories fin para listType en pares ( listTypes ) hacer p [ listType ] = función ( frame ) local mArguments = require ( 'Module:Arguments' ) local origArgs = mArguments . getArgs ( frame , { frameOnly = (( frame y frame . args y frame . args . frameonly o '' ) ~= '' ), valueFunc = función ( key , value ) si no value o no mw . ustring . find ( value , '%S' ) entonces devuelve nil fin si mw . ustring . find ( value , '^%s*[%*#;:]' ) entonces devuelve valor de lo contrario devuelve valor : match ( '^%s*(.-)%s*$' ) fin devuelve nil fin }) - Copiar todos los argumentos a una nueva tabla, para una indexación más rápida. argumentos locales = {} para k , v en pares ( origArgs ) do args [ k ] = v end return p . makeList ( listType , args ) fin fin retorno p