Модуль:CTD: различия между версиями

<div style="color: #555555; font-size: 80%; font-style: italic; font-family: serif; text-align: center;">Материал из '''Библиотеки Теопедии''', http://ru.teopedia.org/lib</div>
Перейти к навигации Перейти к поиску
м
м
Строка 7: Строка 7:
 
function ctd.test( frame )
 
function ctd.test( frame )
 
local i, j = string.find(frame.args['userparam'],'@',1,true)
 
local i, j = string.find(frame.args['userparam'],'@',1,true)
local sub1 =  string.sub( string.lower(frame.args['userparam']), i )
+
local sub1 =  string.sub( string.lower(frame.args['userparam']), 1, i-1 )
local sub2 =  string.sub( string.lower(frame.args['userparam']), j )
+
local sub2 =  string.sub( string.lower(frame.args['userparam']), j+1 )
 
 
   return 'i=' .. i .. 'j=' .. 'sub1=' .. sub1 .. 'sub2=' .. sub2
+
   return 'i=' .. i .. '; j=' .. '; sub1=' .. sub1 .. '; sub2=' .. sub2
 
end
 
end
  

Версия 06:51, 5 февраля 2023

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

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

{{ТД источник}}{{ЕПБ.Источник}}{{Кратко из БТС}}{{Кратко из БТС (оформление)}}Модуль: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

function ctd.test( frame )
	local i, j = string.find(frame.args['userparam'],'@',1,true)
	local sub1 =  string.sub( string.lower(frame.args['userparam']), 1, i-1 )
	local sub2 =  string.sub( string.lower(frame.args['userparam']), j+1 )
	
  return 'i=' .. i .. '; j=' .. '; sub1=' .. sub1 .. '; sub2=' .. sub2
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 Шаблон:Кратко из БТС (оформление)
-- Call example: {{#invoke: CTD | info | term=Term | term_to_show=Term with accent or diacritic marks | shortly=Short description | description=Full description | origin = Origin | userparam=text@view }}
-- 'view' is a language dependent parameter, consider changes in code
function ctd.info( frame )
	local term = ''
	local reference = ''
	local description = ''
	local origin = ''
	local wiki_page = frame.args['wiki_page']
	
	-- 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 )

	-- check if 'term' or 'term to show' are specified
	if not isempty(frame.args['term_to_show']) then
		term = frame.args['term_to_show']
	elseif 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 specified
	if not isempty(frame.args['origin']) then
		origin = ' ' .. frame.args['origin']
	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 == 'сноска и подсказка' then
		reference = '{{#tag:ref|' .. term .. origin .. ' – ' .. description .. ' (БТС, [['.. wiki_page .. '|' .. term .. ']])}}'
	end
	if view == 'скобки' then
		text = text .. ' [' .. description .. ']'
	end

	-- add debug information
	text = '<p>DEBUG: view: ' .. view .. "; term: " .. term .. "; description: " .. description .. "; origin: " .. origin .. '</p>' .. text
	
    return text .. reference 
end

return ctd