Модуль:Infobox

ХӀокху модулах лаьцна хааман Модуль:Infobox/doc агӀо кхолла мега

local p = {};

local yesno = require('Module:Yesno')

local function _renderLine( frame, args, i )
	if args[ 'корта' .. i ] and args[ 'корта' .. i ] == '-' then
		return ''
	elseif args[ 'корта' .. i ] and args[ 'корта' .. i ] ~= '' then
		local style = ( args[ 'коьртанийн_хатӀ' ] or '' ) .. ( args[ 'коьртан_хатӀ' .. i ] or '' );
		local class = ( args[ 'тоба' .. i ] or '' );
		return '\n<tr>\n<th colspan="2" scope="colgroup" class="infobox-header ' .. class .. '" style="' .. style .. '">' ..
			args[ 'корта' .. i ] ..
			'</th>\n</tr>';
	end
	
	if args[ 'блок' .. i ] and args[ 'блок' .. i ] ~= '' then
		return args[ 'блок' .. i ];
	end

	local text = args[ 'йоза' .. i ] or '';
	if args[ 'викихаамаш' .. i ] and args[ 'викихаамаш' .. i ] ~= '' then
		text = frame:expandTemplate{ title = 'Wikidata', args = {
			args[ 'викихаамаш' .. i ],
			text,
			from = args[ 'from' ] or ''
		} };
	end

    if text ~= '' then
		local label = args[ 'билгало' .. i ] or '';

    	local class = args[ 'тоба' .. i ] or '';
    	if string.find(class, 'noplainlist') == nil and string.find(class, 'nofirstlevel') == nil then
    		class = class .. ' plainlist';
    	end
    	if class ~= '' then
			class = ' class="' .. class .. '"';
    	end

    	local style = ( args[ 'йозанийн_хатӀ' ] or '' ) .. ( args[ 'йозанан_хатӀ' ] or '' ) .. ( args[ 'йозанан_хатӀ' .. i ] or '' );
		if label == '' then
			style = 'text-align:center;' .. style;
		end
    	if style ~= '' then
    		style = ' style="' .. style .. '"';
		end

		if label ~= '' then
	    	local labelClass = args[ 'билгалонийн_тоба' ] or '';
	    	if string.find(labelClass, 'noplainlist') == nil and string.find(labelClass, 'nofirstlevel') == nil then
    			labelClass = labelClass .. ' plainlist';
			end
	    	if labelClass ~= '' then
	    		labelClass = ' class="' .. labelClass .. '"';
			end
	
	    	local labelStyle = ( args[ 'билгалонийн_хатӀ' ] or '' ) .. ( args[ 'билгалонан_хатӀ' .. i ] or '' );
	    	if labelStyle ~= '' then
	    		labelStyle = ' style="' .. labelStyle .. '"';
			end

			return '\n<tr>\n<th scope="row"' .. labelClass .. labelStyle .. '>' .. label .. '</th>' ..
	    		'\n<td' .. class .. style .. '>\n' .. text .. '</td>\n</tr>';
		end
		
	    return '\n<tr>\n<td colspan="2"' .. class .. style .. '>\n' .. text .. '</td>\n</tr>';
	end	    
    
	return '';
end

local function maxNumber ( args )
	local maxNumber = 0
	for argName, _ in pairs(args) do
		local argNumber = mw.ustring.match(argName, '^[^0-9]+([0-9]+)$')
		if argNumber and tonumber(argNumber) > maxNumber then
			maxNumber = tonumber(argNumber)
		end
	end
	return maxNumber
end

function p.renderLine( frame )
	local args = frame:getParent().args;
	return _renderLine(frame, args, '')
end

function p.renderLines( frame )
	local args = frame:getParent().args;
	
	local res = ''
	local header, text = '', ''
	
	local autoHeaders = yesno(args [ 'автокортош' ] or 'false', false)
	
	for i = 1, maxNumber(args) do
		if args[ 'корта' .. i ] and args[ 'корта' .. i ] ~= '' then
			if text ~= '' or not autoHeaders then
				res = res .. header .. text
			end
			header, text = _renderLine(frame, args, i), ''
		else
			text = text .. _renderLine(frame, args, i)
		end
	end
	if text ~= '' or not autoHeaders then
		res = res .. header .. text
	end
	
	return res
end

return p;