Modul:Infobox/bulleted block

Vikipediya, azad ensiklopediya
Naviqasiyaya keçin Axtarışa keçin

Bu modulun sənədləşdirmə səhifəsi Modul:Infobox/bulleted block/doc səhifəsində yaradıla bilər

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

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['mətn' .. i] then
			texts[i] = makeText(frame, args['mətn' .. i], args['vikiverilənlər' .. 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['yarımbaşlıq'] and args['yarımbaşlıq'] ~= '' then
		results['mətn1'] = args['yarımbaşlıq']
		results['mətnin stili1'] = 'padding-bottom:0; border-bottom:0; text-align:left; font-weight:bold;'
	end
	
	local mainText = makeText(frame, args['mətn'], args['vikiverilənlər'], args['from'])
	if mainText == '' and args['nişan'] and args['nişan'] ~= '' and not textsAreEmpty then
		mainText = ' '
	end
	
	if mainText and mainText ~= '' then
		results['nişan2'] = args['nişan']
		results['nişan stili2'] = 'padding-bottom:0; border-bottom:0;'
		results['mətn2'] = mainText
		results['mətnin stili2'] = 'padding-bottom:0; border-bottom:0;'
	end
	
	for i = 1, maxNumberArgs do
		if texts[i] and texts[i] ~= '' then
			results['nişan' .. (i+2)] = ' • ' .. (args['nişan' .. i] or '')
			results['mətn' .. (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['nişanlar stili' .. (i+2)] = 'font-weight:normal; padding-top:0; border-top:0;'
				results['mətnin stili' .. (i+2)] = 'padding-top:0; border-top:0;'
			else
				results['nişanlar stili' .. (i+2)] = 'font-weight:normal; padding-bottom:0; border-bottom:0; padding-top:0; border-top:0;'
				results['mətnin stili' .. (i+2)] = 'padding-bottom:0; border-bottom:0; padding-top:0; border-top:0;'
			end
		end
	end

	return frame:expandTemplate{title='Məlumat qutusu/blok', args=results}
end

return p