Модуль:Песочница/Vavilexxx

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация
-- return require [[Модуль:Песочница/Vavilexxx]]

local p = {}

local getArgs = require('Module:Arguments').getArgs

local root, legend

--------------------------------------------------------------------------------
-- ВСПОМОГАТЕЛЬНЫЕ ФУНКЦИИ
--------------------------------------------------------------------------------

function p.legendTable(color, text, number)
	root
		:tag('span') --начало span 1
			:css('font-size', '90%')
			:css('margin', '0px 0px 1px 0px')
			:css('display', 'block')
				:tag('span') --начало span 2
					:css('vertical-align', 'top')
					:css('border', '1px solid black')
					:css('background', color)
					:css('text-align', 'center')
					:attr('title', color)
					:wikitext('    ')
					:done() --конец span 2
			:wikitext(' ' .. text)
				:tag('span') --начало span 3
					:css('font-weight', 'bold')
					:wikitext(' ' .. number)
					:done() --конец span 3
			:done() --конец span 1
end

function p.createTable(frame)
	root = mw.html.create('table')
	root
		:addClass('wikitable sortable')
		--:addClass('infobox')
		--:css('width', '23em')
		--:attr('data-name', 'templateName')
end

function p.topTable(background, width, cellTh, reference)
	-- Ячейка
	root
		:tag('th')
			:attr('scope', 'col')
			--:attr('colspan', '4')
			--:attr('scope', 'colgroup')
			--:addClass('infobox-above')
			--:css('width', width)
			--:css('background', background)
			:wikitext(cellTh)
			:done() --end th
	
	-- Сноска на примечание
	if reference ~= nil and reference ~= '' then
		cell:wikitext(" " .. p.reference(reference, background))
	end
end

	--Создание заголовка
function p.captionTable(text)
	--заголовок
	local title = mw.title.getCurrentTitle()
	local pageTitle = title.text
	root
		:tag('caption') --начало caption
			:wikitext(text)
				:tag('span') --начало span
					:addClass('noprint purgelink')
					:attr('data-pagename', pageTitle)
					:css('float', 'right')
					:css('clear', 'right')
					:css('font-style', 'italic')
					:css('font-size', 'xx-small')
					:wikitext('[[Special:Purge/' .. pageTitle .. '|Очистить кеш сервера]]')
					:done() --конец span
			:done() --конец caption
	return tostring(root)
end

	--Создание изображения
function p.renderImage(image)
	root
		:tag('tr')
			:tag('td')
				:attr('colspan', '4')
				:addClass('infobox-image')
				:wikitext(image)
				:done() --end td
			:done() --end tr
end

	--Создание ссылки
function p.reference(reference)
	local refspan = mw.html.create('span')
			:wikitext(reference)
			:css('background-color', 'transparent')
			:css('color', 'black')
			:css('padding','1px')
			:css('display','inline-block')
			:css('line-height','50%')
	
	return tostring(refspan)
end

	--Ячейка ряда строки
function p.renderRow(text, reference)
	-- Ячейка
	root
		:tag('td') --начало td
			:wikitext(text)
	
	-- Сноска на примечание
	if reference ~= nil and reference ~= '' then
		root:wikitext(" " .. p.reference(reference))
	end
	
	root:done() --конец td
	
	return tostring(root)
end

	-- Создание подвала
function p.footerTable(text, reference)
	-- подвал
	root
		:tag('tr')
			:tag('td') --начало td
				:wikitext(text)
	
	-- Сноска на примечание
	if reference ~= nil and reference ~= '' then
		root:wikitext(" " .. p.reference(reference))
	end
	
	root:allDone() --конец td, tr, table (закрытие всех незакрытых тегов)
	
	return tostring(root)
end

--------------------------------------------------------------------------------
-- ОСНОВНЫЕ ФУНКЦИИ
--------------------------------------------------------------------------------

function p._main(args)
	-- Основной код модуля.
	legend = p.legendTable()
	root = p.createTable()
	root:node('<tr>') --начало tr
	p.topTable()
	root:node('</tr>')  --конец tr
	p.captionTable()
	root:node('<tr>') --начало tr
	p.renderRow()
	root:node('</tr>')  --конец tr
	p.renderImage(image)
	p.footerTable()

	return tostring(legend) .. tostring(root)
end


--------------------------------------------------------------------------------
-- ЭКСПОРТ
--------------------------------------------------------------------------------

function p.main(frame)
	local args = getArgs(frame, {
		--trim = false,
		removeBlanks = false,
		parentOnly = true,
		wrappers = {
			'Шаблон:Шаблон №1',
			'Шаблон:Шаблон №2'
		}
	})
	return p._main(args)
end

return p