Module:Marriage
Appearance
![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
Usage
{{#invoke:Marriage|function_name}}
--
--
-- ! 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"})
abbr_married = "{{abbr|m.|married}}"
abbr_divorced = "{{abbr|div.|divorced}}"
abbr_separated = "{{abbr|sep.|separated}}"
abbr_annulled = "{{abbr|ann.|annulled}}"
local p = {}
function p.main(frame)
local args = getArgs(frame, {trim = true})
return p._main(args)
end
function p._main(args)
local reason_abbr = ""
local marriage_info = ""
local return_value = ""
local spouse_name = args[1] or ""
local date_start = args[2] or ""
local date_end = args[3] or ""
local end_reason = args["end"] or args["reason"] or ""
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 date_start == "" and date_end == "" and end_reason == "" then
-- If no dates or reason provided, the template is not useful, return nothing.
return ""
elseif date_start == "" and date_end == "" then
marriage_info = end_reason
end
if reason_abbr == "" then
-- If end_reason is available, include that before the date_end.
marriage_info = "(" .. abbr_married .. " " .. date_start .. "–" .. date_end .. ")"
else
marriage_info = "(" .. abbr_married .. " " .. date_start .. "; " .. reason_abbr .. " " .. date_end .. ")"
end
if spouse_name == "" then
return_value = marriage_info
else
return_value = spouse_name .. " " .. marriage_info
end
return return_value
end
return p