Модуль:Infobox

Материал из Викимультии — энциклопедии мультипликации
Перейти к навигации Перейти к поиску


Документация
local p = {}
local yn = require('Module:Yesno')

-- Start the infobox
function p.start(frame)
	local args = frame:getParent().args
	
	--Start the box
	local text = '<div '
	local itt = args.itemtype
	
	if yn(itt, true) then
		text = text..' itemscope itemtype="https://schema.org/'..itt..'" class="infobox">' 
	else
		text = text..' class="infobox">'
	end
	
	--заголовок
	if yn(args.itemprop, true) then
		text = text..'<div class="infobox-title"><span itemprop="'..args.itemprop..'">'..(args["заголовок"])..'</span>'
			if yn(args["примечание"], true) then
				text = text..'<sup>'..args["примечание"]..'</sup>'
			end
		text = text..'</div>'
	else
		text = text..'<div class="infobox-title"><span>'..(args["заголовок"])..'</span>'
			if yn(args["примечание"], true) then
				text = text..'<sup>'..args["примечание"]..'</sup>'
			end
		text = text..'</div>'
	end
	
	--подзаголовок
	if yn(args["подзаголовок"], true) then 
		text = text..'<div class="infobox-subtitle">'
		
		if yn(args.itemprop2, true) then
			text = text..frame:expandTemplate{ title = 'lang-'..args["язык"], args = {'<i><span itemprop="'..args.itemprop2..'">'..args["подзаголовок"]..'</span></i>'} }
		else
			text = text..frame:expandTemplate{ title = 'lang-'..args["язык"], args = {'<i><span>'..args["подзаголовок"]..'</span></i>'} }
		end
		text = text..'</div>'
	end
	
	--изображение
	if yn(args['изображение'], true) then
		text = text..'<div class="infobox-image">'..
		frame:expandTemplate{ title = 'Карточка/Tabber', args = {
			args['изображение'],
			size = args['размер изображения']
		} }..'<span style="display: none;" itemprop="image">'..frame:callParserFunction{ name = 'filepath', args = {args['изображение'], 'nowiki'} }..'</span>'
		
		if yn(args["описание изображения"], true) then
			text = text..'<div class="infobox-caption"><span>'..args["описание изображения"]..'</span></div>'
		end
		text = text..'</div>'
	end
	
	return text
end

-- Generates a header
function p.header(frame)
	local args = frame:getParent().args
	if args["условия"] == '' then return '' end
 
	local text = '<div class="infobox-header">'
	text = text..''..(args["заголовок"] or '')
	
	if yn(args.itemprop, true) then 
		text = text..'<span style="display: none;" itemprop="'..args.itemprop..'">'..args.content..'</span>'
	end
	
	text = text..'</div>'
	
	return text
end

-- Generates a single row
function p.row(frame)
	local args = frame:getParent().args
	if args["условия"] == '' then return '' end
	
	local text = '<div class="infobox-data">'
	text = text..'<div class="infobox-data-label">\n\n'..(args["метка"] or '')..'</div>'
	text = text..'<div class="infobox-data-value">\n\n'..(args["значение"] or '')..''
	if yn(args.itemprop, true) then 
		text = text..'<span style="display: none;" itemprop="'..args.itemprop..'">'..args.content..'</span>'
	end
	if yn(args.itemprop2, true) then 
		text = text..'<span style="display: none;" itemprop="'..args.itemprop2..'">'..args.content2..'</span>'
	end
	text = text..'</div></div>'
	
	return text
end

-- Generates rows
function p.rows(frame)
	local args = frame:getParent().args
	if args["условия"] == '' then return '' end
	
	local text = '<div class="infobox-header">'
	text = text..''..(args["метка"] or '')
	text = text..'</div>'
	text = text..'<div class="infobox-data">'
	text = text..'<div class="infobox-data-left">\n\n'..(args["значение1"] or '')..'</div>'
	text = text..'<div class="infobox-data-right">\n\n'..(args["значение2"] or '')..'</div>'
	text = text..'</div>'
	
	return text
end

-- Collapsible boxes
function p.box(frame)
	local args = frame:getParent().args
	if args["условия"] == '' then return '' end

	local text = '<div class="infobox-group BoxFrame '
	
	local st = args["скрывать"]
	if st == 'да' then 
		text = text..'collapsed">'
	elseif st == 'нет' then 
		text = text..'">'
	else
		text = text..'collapsed">'
	end
	
	text = text..'<div class="infobox-header BoxHead">'..(args["метка"] or '')..'</div>'
	text = text..'<div class="infobox-horizontal BoxContent"><div class="infobox-horizontal-value">'..(args["значение"] or '')..'</div></div>'
	text = text..'</div>'
	return text
end

-- Generates the ending part
function p.ending(frame)
	return '</div>'
end

return p
--[[Category:Lua Modules]]