Jump to content

Module:Marriage

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pedantical (talk | contribs) at 03:20, 15 January 2024. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

--
--
--    ! This module is currently Pre-Alpha and not ready for testing.
--
--


-- This module provides consistent formatting for common information included in
-- the spouse parameter of an Infobox_person.
-- It is intended to be used by Template:Marriage and not invoked directly within pages.

local getArgs = require('Module:Arguments').getArgs

function makeSet(items)
  local set = {}
  for _, i in ipairs(items) do 
  	set[i] = true 
  end
  return set
end

values_died = makeSet({"d", "d.", "died"})
values_divorced = makeSet({"div", "div.", "divorce", "divorced"})
values_separated = makeSet({"sep", "sep.", "separate", "separated"})
values_annulled = makeSet({"ann", "ann.", "annulment", "annulled"})


local p = {}

function p.main(frame)
	local args = getArgs(frame, {trim = true})
	return p._main(args)
end

function p._main(args)
	local return_value = ''
	
	local abbr_married = "{{abbr|m.|married}}"
	local abbr_divorced = "{{abbr|div.|divorced}}"
	local abbr_separated = "{{abbr|sep.|separated}}"
	local abbr_annulled = "{{abbr|ann.|annulled}}"
	
	local spouse_name = args[1]
	local date_start = args[2] or 'NO_STARTDATE'
	local reason_abbr = 'NO_REASON_ABBR'
	local date_end = args[3] or 'NO_ENDDATE'
	local end_reason = args["end"] or 'NO_ENDREASON'
	
	if values_died[end_reason] then
		reason_abbr = "died"
	elseif values_divorced[end_reason] then
		reason_abbr = abbr_divorced
	elseif values_separated[end_reason] then
		reason_abbr = abbr_separated
	elseif values_annulled[end_reason] then
		reason_abbr = abbr_annulled
	end
	
	if spouse_name then
		return_value = spouse_name,' (',abbr_married,' ',date_start,', ',reason_abbr,' ',date_end,')'
	else
		return_value = '(',abbr_married,' ',date_start,', ',reason_abbr,' ',date_end,')'
	end
	
	return return_value
end

return p