Module:Animate

local table = require('Module:Table') local string = require('Module:String') local getArgs = require('Module:Arguments').getArgs local itemVariants = require('Module:Item/Variants') -- use require; metatables from mw.loadData doesn't work with table.concat

local p = {}

- -- Template: Animate -- -- Creates a cycling animation. -\ local function appendPNG(image) if not(image:match('%.%a%a%a?%a?')) then image = image..".png" end return image end

function p.animate(frame) local args = getArgs(frame) local files = args[1] or '' local size = args[2] or '' local link = args['link'] or args[3] or '' local class = args['class'] or '' if size ~= '' then size = '|' .. size end

if link ~= '' then link = '|link=' .. link end if class ~= '' then class = '|class=' .. class end local images = {} files = table.concat(table.map(string.split(files, '%s*;%s*'), function(s) local t = itemVariants[s] or {s} return table.concat(t,';') end),';') for image in string.gsplit(files, '%s*;%s*') do		if image == '' then table.insert(images, string.wrapTag(' ', 'span')) else table.insert(images, string.wrapTag(string.makeLink{ "File:", appendPNG(image), size, link, class }, 'span')) end end if files:match( ';' ) then images[1] = images[1]:gsub('^ ', ' ') return string.wrapHtml(images, ' ', {class="animated"}) else return table.concat(images) end end

return p