Modulis:Personas infokaste

Dokumentācijas ikona Moduļa dokumentācija[izveidot]
local p = { }

local vs = require('Module:Vīrsiev')
local yesno = require('Module:Yesno')
local infoboxImage = require('Module:InfoboxImage').InfoboxImage
local getArgs = require('Module:Arguments').getArgs

function p._main(args)
	local currentpage = mw.title.getCurrentTitle()
	local disambigname = string.gsub(args['vārds'] or currentpage.text, "%s+%b()$", "")
	local fons = args['krāsa']-- or '#C0C0C0'
	local dzimums = args.dzimums
	
		createTable()
    	renderAboveRow(disambigname,args['vārds_orig'])
    	--renderImage(args['attēls'],args['att_izmērs'],args['att_nosaukums'])
    	renderImage(infoboxImage{args={image = args['attēls']}},args['att_izmērs'],args['att_nosaukums'])
    	createHeader('Personīgā informācija',fons)
    	createRow(vs(dzimums,"Dzimis","Dzimusi"),dz(args.dz_dat_alt,args.dz_gads,args['dz_mēnesis'],args.dz_diena,args.dz_vieta,args.m_dat_alt,
args.m_gads,args['m_mēnesis'],args.m_diena,args.m_vieta,args.note))
    	createRow(vs(dzimums,"Miris","Mirusi"),mir(args.m_dat_alt,
args.m_gads,args['m_mēnesis'],args.m_diena,args.m_vieta,args.dz_dat_alt,args.dz_gads,args['dz_mēnesis'],args.dz_diena,args.dz_vieta,args.note))
    	createRow("Dzīves vieta",args['dzīves_vieta'])
    	createRow("Pilsonība",args['pilsonība'])
    	createRow("Tautība",args['tautība'])
    	createRow("Nodarbošanās",args['nodarbošanās'])
    	createRow("Ienākumi",args['ienākumi'])
    	createRow("Darbības gadi",args['darbības_gadi'])
    	createRow("Vecāki",args['vecāki'])
    	createRow("Brāļi",args['brāļi'])
    	createRow("Māsas",args['māsas'])
    	createRow(vs(dzimums,"Dzīvesbiedre","Dzīvesbiedrs"),args['dzīvesbiedrs'])--kā trešo argumentu vs - label nosaukumu?
    	createRow("Bērni",args['bērni'])
    	createRow("Augstskola",args.alma_mater)
    	--createRow("",args[''])
   		
		return tostring(root)
end

function createTable(child)
    if child ~= 'yes' then
        root = mw.html.create('table')
        
        root
            :addClass('infobox vcard plainlist')
            if subbox == 'yes' then
                root
                    :css('padding', '0')
                    :css('border', 'none')
                    :css('margin', '-3px')
                    :css('width', 'auto')
                    :css('min-width', '100%')
                    :css('font-size', '100%')
                    :css('clear', 'none')
                    :css('float', 'none')
                    :css('background-color', 'transparent')
            else
                root
                    :css('width', '22em')
            end
        end
end

function renderAboveRow(name, subname)
    root
        :tag('tr')
            :tag('th')
                :attr('colspan', 2)
                :css('text-align', 'center')
                :css('font-size', '125%')
                :css('font-weight', 'bold')
                :wikitext(name)
            if subname then
				 root
    			    :tag('tr')
    			       :tag('th')
    			          :attr('colspan', 2)
    			          :css('font-weight', 'normal')
                          :css('font-size', '105%')
                          :wikitext(subname)
                      end
                      
            	
end

function createHeader(header,background)
    root
        :tag('tr')
            :tag('th')
            
                :attr('colspan', 2)
                :css('text-align', 'center')
                :css('font-weight', 'bold')
                :css('background-color', background)
                :wikitext(header)
end

function createRow(label, data)
    if data then
        local row = root:tag('tr')
        row:addClass(rowclass)
        row:cssText(rowstyle)
        row:attr('id', rowid)
        if label then
            row
                :tag('th')
                    :attr('scope', 'row')
                    :attr('id', labelid)
                    :css('text-align', 'left')
                    --:cssText(labelstyle)
                    :wikitext(label)
                    :done()
        end
        
        local dataCell = row:tag('td')
        if not label then 
            dataCell
                :attr('colspan', 2)
                :css('text-align', 'center') 
        end
        dataCell
            :attr('id', dataid)
            :addClass(class)
            :cssText(datastyle)
            :newline()
            :wikitext(data)
    end
end

function renderImage(image, size, caption)
	--local formatimage
		
	--formatimage = '[[File:' .. image .. '|220px]]'

	root
			:tag('tr')
        	:tag('td')
   		:attr('colspan', 4)
            	:css('text-align', 'center')
            	:wikitext(image)
        if caption then
	root
			:tag('tr')
        	:tag('td')
   		:attr('colspan', 4)
            	:css('text-align', 'center')
                :wikitext(caption)
        end
end

function dz(da,dg,dm,dd,dv,ma,mg,mm,md,mv,note)
	local result
	local outputres = {}
	local da,dg,dm,dd,dv,ma,mg,mm,md,mv,note = da,dg,dm,dd,dv,ma,mg,mm,md,mv,note
	
		if da then
			result=da
				elseif ma or mg or mm or md or mv then
					if dg and dm and dd then
						result=mw.getCurrentFrame():expandTemplate{ title = 'dat', args = {dg, dm, dd} }
					elseif dg and (not dm or not dd) then
						result=mw.getCurrentFrame():expandTemplate{ title = 'dat', args = {dg} }
					end

			elseif dg and dm and dd then
				result=mw.getCurrentFrame():expandTemplate{ title = "dzimšanas datums un vecums", args = {dg, dm, dd} }
			elseif dg and not dm and not dd then
				result=mw.getCurrentFrame():expandTemplate{ title = "dzimšanas gads un vecums", args = {dg} }
			elseif dg and (not dm or not dd) then
				result="<strong class=\"error\">Jānorāda gan mēnesis, gan datums</strong>"
			end

	table.insert( outputres, result )
	table.insert( outputres, dv )
	outputres = table.concat(outputres,'\n')


return (outputres or '') .. (note or '')
end

function mir(ma,mg,mm,md,mv,da,dg,dm,dd,dv,note)
	local result
	local outputres = {}
	local da,dg,dm,dd,dv,ma,mg,mm,md,mv,note = da,dg,dm,dd,dv,ma,mg,mm,md,mv,note
	
		if ma then
			result=ma
				elseif da or dg or dm or dd or dv then
					if mg and mm and md and (da or not dg) then
						result=mw.getCurrentFrame():expandTemplate{ title = "dat", args = {mg, mm, md} }
					elseif mg and mm and md and dg and not dm and not dd then
						result=mw.getCurrentFrame():expandTemplate{ title = "Miršanas datums un vecums2", args = {mg, mm, md, dg} }
					elseif mg and mm and md then
						result=mw.getCurrentFrame():expandTemplate{ title = "miršanas datums un vecums", args = {mg, mm, md, dg, dm, dd} }
					elseif mg and (not mm or not md) then
						result=mw.getCurrentFrame():expandTemplate{ title = 'mgv', args = {mg, dg} }
					end

			elseif mg and mm and md then
				result=mw.getCurrentFrame():expandTemplate{ title = 'dat', args = {mg, mm, md} }
			elseif mg and not mm and not md then
				result=mw.getCurrentFrame():expandTemplate{ title = "dat", args = {mg} }
			elseif mg and (not mm or not md) then
				result="<strong class=\"error\">Jānorāda gan mēnesis, gan datums</strong>"
			end

	table.insert( outputres, result )
	table.insert( outputres, mv )
	outputres = table.concat(outputres,'\n')


return (outputres or '') .. (note or '')--note jābūt pie informācijas par datumu, nevis vietu!
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

return p