Módulo:Tabla de episodios
La documentación para este módulo puede ser creada en Módulo:Tabla de episodios/doc
-- Este módulo implementa {{Tabla de episodios}} y {{Tabla de episodios/parte}}. local HTMLcolor = mw.loadData( 'Módulo:Color contrast/colors' ) -------------------------------------------------------------------------------- -- TabladeEpisodios class -- The main class. -------------------------------------------------------------------------------- local contrast_ratio = require('Módulo:Color contrast')._ratio local TabladeEpisodios = {} function TabladeEpisodios.cell(background, width, text, reference) local cell = mw.html.create('th') -- Cell cell:attr('scope','col') :css('background',background or '#CCCCFF') :css('width',width ~= '' and width .. '%' or nil) :wikitext(text) -- Reference if reference then cell:wikitext(" " .. TabladeEpisodios.reference(reference, background)) end return cell end function TabladeEpisodios.reference(reference, background) local link1_cr = contrast_ratio{'#0645AD', background or '#CCCCFF', ['error'] = 0} local link2_cr = contrast_ratio{'#0B0080', background or '#CCCCFF', ['error'] = 0} local refspan = mw.html.create('span') :wikitext(reference) if link1_cr < 7 or link2_cr < 7 then refspan :css('background-color','white') :css('padding','1px') :css('display','inline-block') :css('line-height','50%') end return tostring(refspan) end function TabladeEpisodios.abbr(text,title) local abbr = mw.html.create('abbr') :attr('title',title) :wikitext(text) return tostring(abbr) end function TabladeEpisodios.part(frame,args) local row = mw.html.create('tr') local black_cr = contrast_ratio{args.c, 'black', ['error'] = 0} local white_cr = contrast_ratio{'white', args.c, ['error'] = 0} local displaytext = (not args.nopart and 'Parte ' or '') .. (args.p or '') row:tag('td') :attr('colspan',13) :css('text-align','center') :css('background-color', args.c) :css('color', black_cr > white_cr and 'black' or 'white') :wikitext("'''" .. frame:expandTemplate({title='Anclavis',args={displaytext}}) .. "'''" .. (args.r and " " .. TabladeEpisodios.reference(args.r, args.c) or '')) return tostring(row) end function TabladeEpisodios.new(args) args = args or {} local categories = '' local background = (args.background and args.background ~= '' and args.background ~= '#') and args.background or nil -- Add # to background if necessary if background ~= nil and HTMLcolor[background] == nil then background = '#'..(mw.ustring.match(background, '^[%s#]*([a-fA-F0-9]*)[%s]*$') or '') end -- Create episode table local root = mw.html.create('table') root :addClass('wikitable') :addClass('plainrowheaders') :addClass('wikiepisodetable') :css('width', args.total_width and string.gsub(args.total_width,'%%','') .. '%' or '100%') -- Caption if args.caption then root:tag('caption'):wikitext(args.caption) end -- Colour contrast; add to category only if it's in the mainspace local title = mw.title.getCurrentTitle() local black_cr = contrast_ratio{background, 'black', ['error'] = 0} local white_cr = contrast_ratio{'white', background, ['error'] = 0} if title.namespace == 0 and (args.background and args.background ~= '' and args.background ~= '#') and black_cr < 7 and white_cr < 7 then categories = categories .. '[[Categoría:Wikipedia:Tablas de episodios con combinación de colores no válida]]' end -- Main row local mainRow = root:tag('tr') mainRow :css('color', background and (black_cr > white_cr and 'black' or 'white') or 'black') :css('text-align', 'center') -- Cells do local cellNames = { {'general','EpisodioNúmero',TabladeEpisodios.abbr('N.º','Número') .. ((args.temporada or args.serie or args['EpisodioNúmero2'] or args['EpisodioNúmero2Serie'] or args.forcegeneral) and ' en serie' or '')}, {'temporada','EpisodioNúmero2',TabladeEpisodios.abbr('N.º en temp.','Número en temporada')}, {'serie','EpisodioNúmero2Serie',TabladeEpisodios.abbr('N.º','Número') .. ' en serie'}, {'título','Título','Título'}, {'aux1','Aux1',''}, {'director','DirigidoPor','Dirigido por'}, {'escritor','EscritoPor','Escrito por'}, {'aux2','Aux2',''}, {'aux3','Aux3',''}, {'fechadeemisión','FechadeEmisiónorig','Fecha de ' .. (args.lanzamiento and 'lanzamiento' or 'emisión') .. ' original'}, {'altfecha','AltFecha',''}, {'altfecha2','AltFecha2',''}, {'códigodeprod','CódigodeProd','Código <br />de ' .. TabladeEpisodios.abbr('prod.','producción')}, {'audiencia','Audiencia','Audiencia <br /> (millones)'}, {'aux4','Aux4',''} } for k,v in pairs(cellNames) do local thisCell = args[v[1]] or args[v[2]] if thisCell and (v[1] ~= 'serie' or (v[1] == 'serie' and used_temporada == false)) then if v[1] == 'temporada' then used_temporada = true end -- if (k <= 3 and thisCell == '') then thisCell = '5' end local thisCellT = args[v[1] .. 'T'] or args[v[2] .. 'T'] local thisCellR = args[v[1] .. 'R'] or args[v[2] .. 'R'] mainRow:node(TabladeEpisodios.cell(background, thisCell, thisCellT or v[3], thisCellR)) end end if args.episodios then -- Elimino una categoría de mantenimiento que se agrega automáticamente en Lista de episodios -- Nota: el nombre de esta categoría debe coincidir aquí y en el Módulo:Lista de episodios args.episodios = string.gsub(args.episodios, string.gsub( '[[Categoría:Wikipedia:Listas de episodios que no usan Tabla de episodios]]', '([%[%:%]])', '%%%1'), '') -- Episodios root:node(args.episodios) end end return (args.dontclose and mw.ustring.gsub(tostring(root), "</table>", "") or tostring(root)) .. categories end -------------------------------------------------------------------------------- -- Exports -------------------------------------------------------------------------------- local p = {} function p.main(frame) local args = require('Módulo:Argumentos').obtenerArgumentos(frame, { removeBlanks = false, wrappers = 'Plantilla:Lista de episodios' }) return TabladeEpisodios.new(args) end function p.part(frame) local args = require('Módulo:Argumentos').obtenerArgumentos(frame, { removeBlanks = false, wrappers = 'Plantilla:Lista de episodios/parte' }) return TabladeEpisodios.part(frame,args) end function p.ref(frame) local args = require('Módulo:Argumentos').obtenerArgumentos(frame, { removeBlanks = false, }) return TabladeEpisodios.reference(args.r,args.b) end return p