Module:Marriage
--
--
-- ! This module is currently in its alpha stage and not ready for regular use.
-- Please feel free to discuss improvements and propose modifications.
--
--
-- Notes and TODOs:
-- - Currently this module is not modifying styles like Template:Marriage.
-- - Date formatting logic is still needed to parse out the year.
-- - Test cases are not robust.
-- - Missing logic found in Template:Marriage that queries Wikidata.
--
-- 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
-- Define sets of accepted end-reasons for standard abbreviations.
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"})
-- Set standard abbreviation text to be used.
abbr_married = '<abbr title="married">m.</abbr>'
abbr_divorced = '<abbr title="divorced">div.</abbr>'
abbr_separated = '<abbr title="separated">sep.</abbr>'
abbr_annulled = '<abbr title="annulled">ann.</abbr>'
local p = {}
function p.main(frame)
local args = getArgs(frame, {trim = true})
return mw.html.create():wikitext(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_raw = args["end"] or args["reason"] or ""
if end_reason_raw == nil then
end_reason = ""
else
if values_died[end_reason_raw] then
end_reason = "died"
elseif values_divorced[end_reason_raw] then
end_reason = abbr_divorced
elseif values_separated[end_reason_raw] then
end_reason = abbr_separated
elseif values_annulled[end_reason_raw] then
end_reason = abbr_annulled
else
end_reason = end_reason_raw
end
end
-- Prepare final structure and placement of marriage info (dates, end-reason)
if date_start == "" and date_end == "" and end_reason == "" then
-- If no dates or reason provided, the template is not useful, return nothing.
-- (nothing for now, but we'll add a warning message later on to be shown in preview)
return ""
elseif date_start == "" and date_end == "" then
marriage_info = "(" .. end_reason .. ")"
elseif date_start == "" then
marriage_info = "(" .. end_reason .. " " .. date_end .. ")"
elseif date_end == "" and end_reason == "" then
marriage_info = "(" .. abbr_married .. " " .. date_start .. ")"
elseif date_end == "" then
marriage_info = "(" .. abbr_married .. " " .. date_start .. "; " .. end_reason .. ")"
elseif end_reason == "" then
marriage_info = "(" .. abbr_married .. " " .. date_start .. "–" .. date_end .. ")"
else
marriage_info = "(" .. abbr_married .. " " .. date_start .. "; " .. end_reason .. " " .. date_end .. ")"
end
if spouse_name == "" then
-- When there is no spouse name, return only marriage info.
return_value = marriage_info
else
return_value = spouse_name .. " " .. marriage_info
end
return return_value
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.
- 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:
- 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.
- 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.
- 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.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.