Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Documentation for this module may be created at Module:Appellation/doc

-- Appellation pages are titled "<Name> (appellation)" (Naming Convention Reference §3.2),
-- while accession records enter the bare name. These two functions map between the forms.
--   {{#invoke:Appellation|title|Grahan}}               -> Grahan (appellation)
--   {{#invoke:Appellation|name|Grahan (appellation)}}  -> Grahan
-- Both trim whitespace, leave an empty value empty, and never add the suffix twice.
-- Used by Template:Accession (the Has appellation value), Template:Infobox accession (the
-- link) and the Browse/Appellation templates (the display name).
local p = {}

local SUFFIX = ' (appellation)'

local function hasSuffix(s)
	return #s > #SUFFIX and s:sub(-#SUFFIX) == SUFFIX
end

local function arg(frame)
	return mw.text.trim(frame.args[1] or '')
end

function p.title(frame)
	local s = arg(frame)
	if s == '' or hasSuffix(s) then
		return s
	end
	return s .. SUFFIX
end

function p.name(frame)
	local s = arg(frame)
	if hasSuffix(s) then
		return mw.text.trim(s:sub(1, -#SUFFIX - 1))
	end
	return s
end

return p