Модуль:Infobox/bulleted block

Wikipedia-с

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

local p = {}

-- takes strings or nils; returns a string
function makeText(frame, text, wikidata, from)
	if wikidata and wikidata ~= ''then
		return frame:expandTemplate{title='Wikidata', args={wikidata, text or '', from=from or ''}}
	else
		return text or ''
	end
end

-- from [[ru:Модуль:Infobox]]
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.main(frame)
	local args = frame:getParent().args
	local maxNumberArgs = maxNumber(args)
	
	local texts = {}
	for i = 1, maxNumberArgs do
		if args['текст' .. i] then
			texts[i] = makeText(frame, args['текст' .. i], args['викиданные' .. i], args['from'])
		end
	end
	
	local textsAreEmpty = true
	for i = 1, maxNumberArgs do
		if texts[i] and texts[i] ~= '' then
			textsAreEmpty = false
		end
	end
	
	local results = {}
	if not textsAreEmpty and args['подзаголовок'] and args['подзаголовок'] ~= '' then
		results['текст1'] = args['подзаголовок']
		results['стиль_текста1'] = 'padding-bottom:0; border-bottom:0; text-align:left; font-weight:bold;'
	end
	
	local mainText = makeText(frame, args['текст'], args['викиданные'], args['from'])
	if mainText == '' and args['метка'] and args['метка'] ~= '' and not textsAreEmpty then
		mainText = ' '
	end
	
	if mainText and mainText ~= '' then
		results['метка2'] = args['метка']
		results['стиль_метки2'] = 'padding-bottom:0; border-bottom:0;'
		results['текст2'] = mainText
		results['стиль_текста2'] = 'padding-bottom:0; border-bottom:0;'
	end
	
	for i = 1, maxNumberArgs do
		if texts[i] and texts[i] ~= '' then
			results['метка' .. (i+2)] = ' • ' .. (args['метка' .. i] or '')
			results['текст' .. (i+2)] = texts[i]
			
			local last = true
			for j = i+1, maxNumberArgs do
				if texts[j] and texts[j] ~= '' then
					last = false
				end
			end
			
			if last then
				results['стиль_метки' .. (i+2)] = 'font-weight:normal; padding-top:0; border-top:0;'
				results['стиль_текста' .. (i+2)] = 'padding-top:0; border-top:0;'
			else
				results['стиль_метки' .. (i+2)] = 'font-weight:normal; padding-bottom:0; border-bottom:0; padding-top:0; border-top:0;'
				results['стиль_текста' .. (i+2)] = 'padding-bottom:0; border-bottom:0; padding-top:0; border-top:0;'
			end
		end
	end

	return frame:expandTemplate{title='Карточка/блок', args=results}
end

return p