Here naverokê

Modul:Infobox komên etnîkî

Ji Wîkîpediya, ensîklopediya azad.
Belgekirina modulê[biafirîne]
local infoboxStyle = mw.loadData('Module:WPMILHIST Teşeyê Infoboxê')

local IMC = {}
IMC.__index = IMC



function IMC:renderPerCombatant(builder, headerText, prefix, suffix)
	prefix = prefix or ''
	suffix = suffix or ''
	local colspans = {}
	
	-- This may result in colspans[1] getting set twice, but
	-- this is no big deal. The second set will be correct.
	local lastCombatant = 1
	
	for i = 1,self.combatants do
		if self.args[prefix .. i .. suffix] then
			colspans[lastCombatant] = i - lastCombatant
			lastCombatant = i
		end
	end

	local jointText = self.args[prefix .. (self.combatants + 1) .. suffix]
	
	if headerText and (colspans[1] or jointText) then
		builder:tag('tr')
			:tag('th')
				:attr('colspan', self.combatants)
				:cssText(infoboxStyle.header_raw)
				:wikitext(headerText)
	end

	-- The only time colspans[1] wouldn't be set is if no
	-- combatant has a field with the given prefix and suffix.
	if colspans[1] then
		-- Since each found argument set the colspan for the previous
		-- one, the final one wasn't set above, so set it now.
		colspans[lastCombatant] = self.combatants - lastCombatant + 1
		builder = builder:tag('tr')
		for i = 1,self.combatants do
			-- At this point, colspans[i] will be set for i=1 unconditionally, and for
			-- any other value of i where self.args[prefix .. i .. suffix] is set.
			if colspans[i] then
				builder:tag('td')
					-- don't bother emitting colspan="1"
					:attr('colspan', colspans[i] ~= 1 and colspans[i] or nil)
					:css('width', math.floor(100 / self.combatants * colspans[i] + 0.5) .. '%')
					-- no border on the right of the rightmost column
					:css('border-right', i ~= lastCombatant and infoboxStyle.internal_border or nil)
					-- no padding on the left of the leftmost column
					:css('padding-left', i ~= 1 and '0.25em' or nil)
					-- don't show the border if we're directly under a header
					:css('border-top', not headerText and infoboxStyle.internal_border or nil)
					:newline()
					:wikitext(self.args[prefix .. i .. suffix])
			end
		end
	end

	if jointText then
		builder:tag('tr')
			:tag('td')
				:attr('colspan', self.combatants)
				:css('text-align', 'center')
				-- don't show the border if we're directly under a header
				:css('border-top', (not headerText or colspans[1]) and infoboxStyle.internal_border or nil)
				:newline()
				:wikitext(jointText)
	end
end
	
	if self.args['herêm'] or self.args['cih'] then
		builder:tag('tr')
			:tag('th')
				:css('padding-right', '1em')
				:wikitext('Herêm')
			:done()
			:tag('td')
			:tag('span')
				:addClass('location')
				:wikitext((self.args['cih'] or '') .. (self.args['cih'] and self.args['herêm'] and ', ' or '') .. (self.args['herêm'] or ''))
	end
	
	if self.args['sedem'] then
		builder:tag('tr')
			:tag('th')
				:css('padding-right', '1em')
				:wikitext(self.args['sedem'] and 'Sedem')
			:done()
			:tag('td')
				:wikitext(self.args['sedem'])
	end

	if self.args['rewş'] or self.args['encam'] then
		builder:tag('tr')
			:tag('th')
				:css('padding-right', '1em')
				:wikitext(self.args['rewş'] and 'Rewş' or 'Encam')
			:done()
			:tag('td')
				:wikitext(self.args['rewş'] or self.args['encam'])
	end

	if self.args['guherandinên erdnîgarî'] then
		builder:tag('tr')
			:tag('th')
				:css('padding-right', '1em')
				:wikitext('Guherandinên<br>Erdnîgarî')
			:done()
			:tag('td')
				:newline()
				:wikitext(self.args['guherandinên erdnîgarî'])
	end

function IMC:render()
	local builder = mw.html.create()
	if self.args['cephekutusu'] then
		builder = builder:tag('table')
			:css('float', 'right')
			:css('clear', 'right')
			:css('background', 'transparent')
			:css('margin', 0)
			:css('padding', 0)
			:tag('tr'):tag('td')
	end
	builder = builder:tag('table')
		:addClass('infobox vevent')
		:cssText(infoboxStyle.main_box_raw_auto_width)
		:css('width', self.args['firehî'] or '315px')

	builder:tag('tr')
		:tag('th')
			:addClass('summary')
			:attr('colspan', self.combatants)
			:cssText(infoboxStyle.header_raw)
			:wikitext(self.args['nav'] or mw.title.getCurrentTitle().text)
	if self.args['kom'] then
		builder:tag('tr')
			:tag('td')
				:attr('colspan', self.combatants)
				:cssText(infoboxStyle.sub_header_raw)
				:wikitext(self.args['kom'])
	end
	if self.args['wêne'] then
		builder:tag('tr')
			:tag('td')
				:attr('colspan', self.combatants)
				:cssText(infoboxStyle.image_box_raw)
				:wikitext(string.format('%s%s%s',
					require('Module:InfoboxImage').InfoboxImage{args = {
						image = self.args['wêne'],
						size = self.args['wêne mezinî'],
						sizedefault = 'frameless',
						upright = 1,
						alt = self.args['wêne sernûçe']
					}},
					self.args['sernav'] and '<br />' or '',
					self.args['sernav'] or ''
				))
	end
	
	self:renderPerCombatant(builder, 'Gelhe kom', 'gelhe kom')
	self:renderPerCombatant(builder, 'Şêniyên', 'herêm', 'gelhe', 'çavk')
	self:renderPerCombatant(builder, 'Hêz', 'hêz')
	self:renderPerCombatant(builder, 'Piştgiriya siyasî', 'piştgiriya siyasî')
	self:renderPerCombatant(builder, 'Piştgiriya leşkerî', 'piştgiriya leşkerî')
	self:renderPerCombatant(builder, 'Winda', 'winda')

	if self.args['nîşe'] then
		builder:tag('tr')
			:tag('td')
				:attr('colspan', self.combatants)
				:css('font-size', '90%')
				:css('border-top', infoboxStyle.section_border)
				:newline()
				:wikitext(self.args['nîşe'])
	end
	builder = builder:done()
	if self.args['cephekutusu'] then
		builder = builder:done():done():tag('tr')
			:tag('td')
				:wikitext(self.args['cephekutusu'])
			:done()
		:done()
	end
	return builder
end

function IMC.new(frame, args)
	if not args then
		args = require('Module:Arguments').getArgs(frame, {wrappers = 'Şablon:Infobox pevçûnên leşkerî'})
	end
	local obj = {
		frame = frame,
		args = args
	}

	-- until gerrit:165108 is merged, there's still a cap on combatants, but as soon as it merges, we can update this little bit of code to uncap it
	-- also, don't try to make this more efficient, or references could be in the wrong order
	obj.combatants = 2
	for _,v in ipairs{'', 'a', 'b', 'c', 'd'} do
		for i = 1,5 do
			if args['şervan' .. i .. v] then
				obj.combatants = math.max(obj.combatants, i)
			end
		end
	end

	return setmetatable(obj, IMC)
end

local p = {}

function p.main(frame)
	return IMC.new(frame):render()
end

return p