Modül:çekim/fonksiyonlar

Modül belgelemesi [Oluştur]


--[=[
GORUNTU_HALLEDİCİLERİ is a list of one or more functions that provide special
handling for multipart tags. Each function takes formerly a single argument
(the multipart tag), now temporarily two arguments (the multipart tag and
the join strategy, which can be nil to use the default), and should either
return the formatted display text or nil to check the next handler. If no
handlers apply, there is a default handler that appropriately formats most
multipart tags.

KAT_FONKSİYONLARI is a map from function names to functions of a single argument,
as described in [[Module:form of/cats]]. There are two types of functions:
condition handlers (which return true or false) and spec handlers (which
return a specification, as described in [[Module:form of/cats]]). We need to
put the functions here rather than in [[Module:form of/cats]] because that
module is loaded using mw.loadData(), which can't directly handle functions.
]=]

local cikart = {}

function cikart.cokparcali_birlestirme_stratejisi()
	-- Recognized values:
	-- "and": Join with "and", using commas for 3 or more items
	-- "en-dash": Join with – (en-dash)
	-- "slash": Join with / (slash)
	return "slash"
end

local function sar_cekim_ayirici_ile(text)
	return '<span class="cekim_ayirici">' .. text .. '</span>'
end
	
-- This is a local version of serialCommaJoin from [[Module:table]] that
-- implements it a bit differently.
local function birlestir_cokparcali_sirali_virgulle(seq)
	local length = #seq

	if length == 0 then
		return ""
	elseif length == 1 then
		return seq[1] -- nothing to join
	elseif length == 2 then
		return seq[1] .. sar_cekim_ayirici_ile("&#32;and&#32;") .. seq[2]
	else
		local comma = '<span class="serial-comma">,</span>'
		local conj = '<span class="serial-and">&#32;and&#32;</span>'
		return table.concat(seq, sar_cekim_ayirici_ile(",&#32;"), 1, length - 1) ..
			sar_cekim_ayirici_ile(comma .. conj) .. seq[length]
	end
end

function cikart.birlestir_cokparcali(parts, joiner)
	-- Display the elements of a multipart tag. Currently we use "and",
	-- with commas when then are three or more elements, of the form
	-- "foo, bar, baz and bat"; but we are seriously considering switching
	-- to en-dash, e.g. "foo–bar–baz–bat". Arguably,
	--   dative–ablative masculine–feminine–neuter plural
	-- looks better then
	--   dative and ablative masculine, feminine and neuter plural
	-- and
	--   first–second–third-person singular present subjunctive
	-- looks better than
	--   first-, second- and third-person singular present subjunctive
	local strategy = joiner or cikart.cokparcali_birlestirme_stratejisi()
	local retval
	if strategy == "and" then
		retval = birlestir_cokparcali_sirali_virgulle(parts)
	elseif strategy == "en-dash" then
		retval = table.concat(parts, sar_cekim_ayirici_ile("–"))
	elseif strategy == "slash" then
		retval = table.concat(parts, sar_cekim_ayirici_ile("/"))
	else
		error("Unrecognized multipart join strategy: " .. strategy)
	end
	return '<span class="inflection-of-conjoined">' .. retval .. '</span>'
end

cikart.kat_fonksiyonlari = {}

cikart.goruntu_halledicileri = {}

-- Display handler to clean up display of multiple persons by omitting
-- redundant "person" in all but the last element. For example, the tag
-- "123" maps to "1//2//3", which in turn gets displayed as (approximately)
-- "first-, second- and third-person" (with appropriate glossary links, and
-- appropriate spans marking the serial comma).
table.insert(cikart.goruntu_halledicileri,
	function(tags, joiner)
		local els = {}
		local numtags = #tags
		local strategy = joiner or cikart.cokparcali_birlestirme_stratejisi()
		for i, tag in ipairs(tags) do
			local suffix = i == numtags and "-person]]" or
				strategy == "and" and "-]]" or "]]"
			if tag == "first-person" then
				table.insert(els, "[[Appendix:Glossary#first person|first" .. suffix)
			elseif tag == "second-person" then
				table.insert(els, "[[Appendix:Glossary#second person|second" .. suffix)
			elseif tag == "third-person" then
				table.insert(els, "[[Appendix:Glossary#third person|third" .. suffix)
			else
				return nil
			end
		end
		return cikart.birlestir_cokparcali(els, joiner)
	end
)

return cikart

-- For Vim, so we get 4-space tabs
-- vim: set ts=4 sw=4 noet: