Module:Sandbox/AlphaZeta/test4

--[[ 
 Infobox biography
 1. Sets default colors and styles
 2. Finds any input fields for death and birth dates 
 	and formats the date according to Swedish standard
 	and calculates and displays age or age at death

]]
local p = {};

-- Default style -------------
local default_bodystyle='border-spacing:3px;width:22em;border:1px solid #AAAAAA; border-top:0px;'
local default_titlestyle='border:1px solid #AAAAAA; border-bottom:0px;background:#ccd9e8;padding-top:5px;padding-bottom:5px;'
local default_labelstyle='' 
local default_headerstyle='background:#BFD2EB;'
local default_belowstyle='background:#BFD2EB;'
------------------------------

local Infobox = require('Module:Infobox')
local DateHelper = require('Module:Sandbox/AlphaZeta/test3')

function p.infobox(frame) 
    -- If called via #invoke, use the args passed into the invoking template.
    -- Otherwise, for testing purposes, assume args are being passed directly in.
    if frame == mw.getCurrentFrame() then
        inputargs = frame:getParent().args
    else
        inputargs = frame
    end
    
    -- Set default style
    if inputargs.bodystyle ~= nil then 
    	default_bodystyle = default_bodystyle..inputargs.bodystyle
    end
    inputargs.bodystyle=default_bodystyle
    
    if inputargs.titlestyle ~= nil then 
    	default_titlestyle = default_titlestyle..inputargs.titlestyle
    end
    inputargs.titlestyle=default_titlestyle
    
    if inputargs.labelstyle ~= nil then 
    	default_labelstyle = default_labelstyle..inputargs.labelstyle
    end
   	inputargs.labelstyle=default_labelstyle
   	
    if inputargs.headerstyle ~= nil then 
    	default_headerstyle = default_headerstyle..inputargs.headerstyle
    end
   	inputargs.headerstyle=default_headerstyle
   	
     if inputargs.belowstyle ~= nil then 
    	default_belowstyle = default_belowstyle..inputargs.belowstyle
    end  
	inputargs.belowstyle=default_belowstyle

	-- Check all data fields to find and format
	-- Birthdate (marked with @birth@)
	-- Death date (marked with @death@)
	-- Other dates (marked with @date@)
	local birthDateField
	local deathDateField
	local birth_date=''
	local death_date=''
	for name, value in pairs(inputargs) do
		if (name:sub(1,4)=='data') then
			if value:sub(1,7)=='@birth@' then
				birthDateField=name
				birth_date=value:sub(8)
				inputargs[name]=DateHelper.format(birth_date,'link',true)
			elseif value:sub(1,7)=='@death@' then
				deathDateField=name
				death_date=value:sub(8)	
				inputargs[name]=DateHelper.format(death_date,'link',true)	
			elseif value:sub(1,6)=='@date@' then
				inputargs[name]=DateHelper.format(value:sub(7),'',true)		
			elseif value:sub(1,10)=='@datelink@' then
				inputargs[name]=DateHelper.format(value:sub(11),'link',true)		
			end
		end
	end	
	

	-- calcuate age, either alive or dead
	local ageAlive=''
	local ageDeath=''
	if birth_date~=nil and birth_date~='' then
		if death_date==nil or death_date=='' then
			ageAlive=DateHelper.yearsBetween(birth_date)
			if ageAlive~='' then
				ageAlive=' ('..ageAlive..')'
			end
		else
			ageDeath=DateHelper.yearsBetween(birth_date,death_date)
			if ageDeath~='' then
				ageDeath=' ('..ageDeath..')'
			end
		end
	end
	
	-- add age to date fields
	if birthDateField~=nil then
		inputargs[birthDateField]=inputargs[birthDateField]..ageAlive
	end
	if deathDateField~=nil then
		inputargs[deathDateField]=inputargs[deathDateField]..ageDeath
	end
	return Infobox.infobox(inputargs)
end	
return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.