В этом модуле хранятся функции для Большого теософского словаря.

Одна из веток использования:

{{ТД источник}}{{ЕПБ.Источник}}{{Кратко из БТС}}{{Кратко из БТС (оформление)}}Модуль:CTD.info()

Для отладки:

=p.info{ args={
["type"]  = "личность",
["term"]  = "Понятие",
["term_to_show"] = "Поня́тие для показа",
["description"]   = "Полное описание.",
["shortly"]   = "Краткое описание.",
["origin"]    = "происхождение",
["lifetime"]    = "1831-1891",
["wiki_page"]   = "Вики страница",
["userparam"]   = "текст@сноска@личность@серый"
}}

local ctd = {} -- функции для Большого теософского словаря; copied from https://ru.teopedia.org/lib/Module:CTD

local function isempty(s)
  return s == nil or s == ''
end


-- Convert local links [[link|text]] and URL [link text] to plain text.
-- See original function in module PM.
local function remove_links( wiki_str )
	local str = wiki_str

	-- remove local links
	i = mw.ustring.find(str,'[[',1,true)
	j = mw.ustring.find(str,']]',i,true)
	while i ~= nil do
		local link_text = mw.ustring.sub(str, i+2, j-1)
		local k = mw.ustring.find(link_text, '|', 1, true) 
		if k ~= nil then
			link_text = mw.ustring.sub(link_text, k+1)
		end
		str = mw.ustring.sub(str, 1, i-1) .. link_text .. mw.ustring.sub(str, j+2, -1)
		i = mw.ustring.find(str,'[[',1,true)
		j = mw.ustring.find(str,']]',i,true)
	end	
	
	-- remove URL
	i = mw.ustring.find(str,'[http',1,true)
	j = mw.ustring.find(str,']',i,true)
	while i ~= nil do
		local link_text = mw.ustring.sub(str, i+1, j-1)
		local k = mw.ustring.find(link_text, ' ', 1, true) 
		if k ~= nil then
			link_text = mw.ustring.sub(link_text, k+1)
		end
		str = mw.ustring.sub(str, 1, i-1) .. link_text .. mw.ustring.sub(str, j+1, -1)
		i = mw.ustring.find(str,'[http',1,true)
		j = mw.ustring.find(str,']',i,true)
	end	
	
	return str
end


-- NOT FINISHED
-- Add a point at the end of text, check for ".." and "...."
local function point_at_end( text )
	local str = text .. '.'
	
	-- check for 2 or 4 points at ending restrict to 1 or 3.
	
	return str
end

-- Create short description without hyper links
-- Used in : Шаблон:Понятие БТС
-- Call example: 
-- {{#invoke: CTD | shortly 
--  | short_text = Short description, if exist 
--  | long_text  = Long description
-- }}
function ctd.shortly( frame )
	local result = ''

	-- check if sort description specified
	if not isempty(frame.args['short_text']) then
		result = frame.args['short_text']
	else 
		result = frame.args['long_text']
		-- keep only text before Category
		local i = mw.ustring.find(result,'[[Категория',1,true)
		if i ~= nil then
			result = mw.ustring.sub(result, 1, i-1)
		end
		-- convert all links to plain text
		result = remove_links(result)
		-- take only first 100 characters; string.sub() uses bytes instead of chars
		if mw.ustring.len(result) > 100 then
			result = mw.ustring.sub( result, 1, 100) .. '...'
		end
	end
	
	-- Use function point_at_end() when finished
	-- return point_at_end(result)
	return result
end


-- Invoke information from CTD about a TERM and shows it in footnote, pop-up or right next to term in square brackets.
-- Used in : Шаблон:Кратко из БТС (оформление)
-- Based on: Шаблон:Понятие БТС
-- Call example: 
-- {{#invoke: CTD | info 
--  | type         = Type of term: понятие (по умолчанию), личность, выражение, литература, периодика
--  | type         = Type of term: conception, person, expression, literature, periodical 
--  | term         = Term, that is word or phrase 
--  | term_to_show = Term with accent or diacritic marks 
--  | lifetime     = Lifetime (for person or conception) or day of issue (for literature and periodical)
--  | shortly      = Short description 
--  | description  = Full description 
--  | origin       = Origin 
--  | wiki_page    = Wiki page title 
--  | userparam    = text@view 
-- }}
-- Where 'userparam' consist of:
-- text = text to show; generally it is the original text of request
-- view = style of displaying information; a language dependent parameter (consider changes in code below)
function ctd.info( frame )
	local term = ''
	local term_to_show = ''
	local reference = ''
	local description = ''
	local origin = ''
	local term_link = ''
	local bts = '<span style="border-bottom: 1px dotted gray; cursor:help;" title="Большой теософский словарь">БТС</span>'
	
	-- split 'text@view' value of parameter 'userparam' in two variables
	local i, j = string.find(frame.args['userparam'],'@',1,true)
	local text = string.sub(frame.args['userparam'], 1, i-1)
	local view = string.sub( string.lower(frame.args['userparam']), j+1 )

	-- define term to show, i.e. with accent and diacritic
	if not isempty(frame.args['term_to_show']) then
		term_to_show = frame.args['term_to_show']
	elseif not isempty(frame.args['term']) then
		term_to_show = frame.args['term']
	else
		term_to_show = text
	end
	
	-- define term in a simple form as a title in dictionary
	if not isempty(frame.args['term']) then
		term = frame.args['term']
	else
		term = text
	end
	
	-- check if short description is specified
	if not isempty(frame.args['shortly']) then
		description = frame.args['shortly']
	else
		description = frame.args['description']
	end
	
	-- check if origin or lifetime specified
	if not isempty(frame.args['origin']) or not isempty(frame.args['lifetime']) then
		origin = ' (' .. frame.args['origin'] .. ')'
		if not isempty(frame.args['lifetime']) then
			origin = origin .. frame.args['lifetime']
		end
		if not isempty(frame.args['origin']) and not isempty(frame.args['lifetime']) then
			origin = origin .. ', '
		end
		if not isempty(frame.args['origin']) then
			origin = origin .. frame.args['origin']
		end
		origin = origin .. ')'
	end
	
	-- set hyperlink if there is a wiki page for a term
	if not isempty(frame.args['wiki_page']) then
		term_to_show = '[['.. frame.args['wiki_page'] ..'|'.. term_to_show ..']]'
	end
	
	-- considering type of view
	if view == 'подсказка' or view == 'сноска и подсказка' or view == 'подсказка и сноска' then
		text = '{{#tag:span|' .. text .. '|style=border-bottom:1px dotted gray; cursor:help;|title=' .. description .. ' (БТС, ' .. term .. ')|}}' 
	end
	if view == 'сноска' or view == 'сноска и подсказка' or view == 'подсказка и сноска' then
		reference = '<ref>' .. term_to_show .. origin .. ' – ' .. description .. ' ('.. bts ..').</ref>'
	end
	if view == 'скобки' then
		text = text .. ' [' .. description .. ']'
	end

	-- DEBUG
	--text = '<p>DEBUG: view: '.. view .."; term: ".. term .."; term to show: ".. term_to_show .."; description: ".. description .."; origin: ".. origin ..'</p>'.. text
	--return  text .. reference 
	
    return frame:preprocess( text .. reference )
end


-- Invoke information from CTD about a FOREIGN EXPRESSION and shows it in footnote, pop-up or right next to expression in square brackets.
-- Used in : Шаблон:О выражении (оформление)
-- Based on: Шаблон:Иноязычное выражение БТС
-- Call example: 
-- {{#invoke: CTD | expression_info 
--  | expression = Foreing expression 
--  | language   = Language of expression
--  | origin     = Origin 
--  | translation= Full translation and description 
--  | shortly    = Short description 
--  | additional = Some additional information (historical, etc.)
--  | wiki_page  = Wiki page title 
--  | userparam  = text@view 
-- }}
-- Where 'userparam' consist of:
-- text = text to show; generally it is the original text of request
-- view = style of displaying information; a language dependent parameter (consider changes in code below)
function ctd.expression_info( frame )
	local expression = '<i>' .. frame.args['expression'] .. '</i>'
	local short_translation = ''
	local reference = ''
	local language = ''
	local origin = ''
	local bts = ' (<i>[['.. frame.args['wiki_page'] ..'|БТС]]</i>)'
	
	-- split 'text@view' value of parameter 'userparam' in two variables
	local i, j = string.find(frame.args['userparam'],'@',1,true)
	local text = string.sub(frame.args['userparam'], 1, i-1)
	local view = string.sub( string.lower(frame.args['userparam']), i+1, -1 )

	-- check if short description is specified
	if not isempty(frame.args['shortly']) then
		short_translation = frame.args['shortly']
	elseif not isempty(frame.args['translation']) then
		short_translation = frame.args['translation']
	else
		short_translation = frame.args['description']
	end
	
	-- check if language specified
	if not isempty(frame.args['language']) then
		language = language..' ('.. frame.args['language'] .. '.)'
	end
	
	-- check if origin specified
	if not isempty(frame.args['origin']) then
		origin = ' (' 
		if not isempty(frame.args['language']) then
			origin = origin ..frame.args['language'] .. '. '
		end
		origin = origin .. frame.args['origin'] .. ')'
	else 
		origin = language
	end
	
	-- considering type of view
	if view == 'подсказка' or view == 'сноска и подсказка' or view == 'подсказка и сноска' then
		text = '<span style="border-bottom: 1px dotted gray; cursor: help;" title="'.. short_translation .. language ..' (БТС)">'.. text ..'</span>'
	end
	if view == 'сноска' or view == 'сноска и подсказка' or view == 'подсказка и сноска' then
		reference = '<ref><span style="color: grey;"><i><b>' .. frame.args['expression'] .. '</b></i>' .. origin .. ' – ' .. frame.args['translation'] .. bts ..'.</span></ref>'
	end
	if view == 'скобки' then
		text = text ..' ['.. short_translation .. language ..']'
	end

	-- DEBUG. 
	--text = '<p>DEBUG: view: ' .. view .. "; term: " .. term .. "; description: " .. description .. "; origin: " .. origin .. '</p>' .. text
    --return text .. reference ..'; view='.. view ..'; i='.. i 
	
    return frame:preprocess( text .. reference )
end

return ctd