Модуль:Галерея

Материал из Posmotrelisu
Перейти к навигации Перейти к поиску

Для документации этого модуля может быть создана страница Модуль:Галерея/doc

local p = {}

-- Делаем строку с ютуб-шаблоном
function youtubestring (id, text, width, height, shorts )

local res = '<td>{{Youtube|'..id

	if text~=nil 
	then
	res=res..'|'..text 
	end 
	
	if width~=nil
	then
	res=res..'|width='..width 
	end
	
	if height~=nil
	then	
	res=res..'|height='..height 
	end
	
	if shorts~=nil 
	then
	res=res..'|shorts=1' 
	end

return res..'}}</td>'

end 

p.videogallery = function ( frame )
local args = require('Module:Arguments').getArgs(frame)

-- Эти параметры могут быть пустыми	
local w = args['w']
local h = args['h']
local shorts = args['shorts']




-- Эти параметры дб инициализированы 

local align='left'
if args['align'] ~= nil then align=args['align'] end

local cols = 2
if args['cols'] ~= nil then cols=tonumber(args['cols']) end
	if cols<1 then return '<font color="red">Ошибка: попытка создать видеогалерею меньше чем в 1 ряд</font>' end
	
	-- Устанавливаем ширину, если много столбцов 
	if w==nil then
		if cols == 3 then w=200 end
		if cols > 3 then w=150 end
	
	end 


local i=1
local icols = 0

local result='<tr valign="top" >'

while true do

if args[i] == nil and args[i+1] == nil then break end

	if icols == cols 
		then 
		result=result..'</tr><tr valign="top">'
		icols=0
		end 

	result=result..youtubestring ( args[i], args[i+1], w, h, shorts )
	i=i+2
	icols=icols+1
	
end

-- Полируем всё препроцесором, чтоб работало
return '<table align="'..align..'" style="border: solid 1px #CCCCCC; background-color: inherit;" class="videogallery">'..frame:preprocess(result)..'</tr></table><br clear="both" />'
end 



return p
КлассикаАтлас