Модуль: al_version[править введение]

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

Этот модуль реализует работу шаблонов {{al_version}} и {{al_version/Таблица}}.

Актуальные данные, используемые этим модулем, содержатся в подмодуле al_version/Версии.

См. также[править код]

local p = {}

-- Отображение версии ({{al_version}})
function p.al_version(f)
	local args = f
	if f == mw.getCurrentFrame() then
		args = require('Модуль:ProcessArgs').merge(true)
	end
	local version = mw.text.trim( args[1] or '' )
	
	-- загрузка данных из подмодуля
	local version_data = mw.loadData('Модуль:al_version/Версии')['версии'][version]
	
	local category = ''
	local value
	local title = mw.title.getCurrentTitle()
	
	if version_data then
		if version_data.ver then
			if version_data.ver == 'Неизвестно' then
				value = 'Неизвестно'
				if not args['некат'] and title.namespace == 0 and not title.isSubpage then
					category = '[[Категория:Неизвестное значение al_version]]'
				end
			else
				value = version_data.ver
			end
		else
			value = 'Н/Д'
		end
	else
		value = 'Не определено'
		if not args['некат'] and title.namespace == 0 and not title.isSubpage then
			category = '[[Категория:Ожидание значения al_version]]'
		end
	end
	return value .. category
end

-- Таблица с версиями ({{al_version/Таблица}})
function p.table(f)
	local args = f
	if f == mw.getCurrentFrame() then
		args = require('Модуль:ProcessArgs').merge(true)
	end
	
	local html = {}
	local values = mw.loadData('Модуль:al_version/Версии')['список']
	
	function table_header()
		table.insert(html, '<table class="wikitable sortable jquery-tablesorter">\n')
		table.insert(html, '<tr>\n')
		table.insert(html, ' <th>Версия игры</th>\n')
		table.insert(html, ' <th>al_version</th>\n')
		table.insert(html, '</tr>')
	end
	
	table.insert(html, '\n=== Classic ===\n')
	table_header()
	for _, version in ipairs(values) do
		if version.reset ~= nil then
			table.insert(html, '</table>')
			table.insert(html, '\n=== Indev и Infdev ===\n')
			table_header()
		end
		table.insert(html, '<tr>\n')
		table.insert(html, ' <td>[[' .. version.name .. ' (Java Edition)|' .. version.name .. ']]</td>')
		table.insert(html, ' <td style="text-align:center;">' .. version.ver .. '</td>')
		table.insert(html, '</tr>')
	end
	table.insert(html, '</table>')
	
	return table.concat(html)
end

return p