Module:Gallery
Jump to navigation
Jump to search
Want an adless experience? Log in or Create an account.
Documentation for this module may be created at Module:Gallery/doc
local File = {} File.__index = File function File.new( filename, caption, args ) return setmetatable( { filename = filename, caption = type( caption ) == 'string' and caption or nil, args = args or type( caption ) == 'table' and caption or nil }, File ) end function File:render() local parts = {} parts[1] = self.filename if self.caption then parts[2] = self.caption end if self.args then for k, v in pairs(self.args) do parts[#parts + 1] = k .. '=' .. v end end return table.concat( parts, '|' ) end local Gallery = {} Gallery.__index = Gallery function Gallery.new( args ) return setmetatable( { args = args, files = {} }, Gallery ) end function Gallery:addFile( filename, caption, args ) self.files[#self.files + 1] = File.new( filename, caption, args ) end function Gallery:render() local lines = {} for index, file in ipairs( self.files ) do lines[index] = file:render() end return mw.getCurrentFrame():extensionTag( 'gallery', table.concat( lines, '\n' ), self.args ) end local p = {} p.Gallery = Gallery return p