Модуль:CTD: различия между версиями
Перейти к навигации
Перейти к поиску
(Новая страница: «local ctd = {} -- функции для Большого теософского словаря; copied from https://ru.teopedia.org/lib/Module:CTD function ctd.i...») |
м |
||
Строка 1: | Строка 1: | ||
local ctd = {} -- функции для Большого теософского словаря; copied from https://ru.teopedia.org/lib/Module:CTD | local ctd = {} -- функции для Большого теософского словаря; copied from https://ru.teopedia.org/lib/Module:CTD | ||
+ | local function isempty(s) | ||
+ | return s == nil or s == '' | ||
+ | end | ||
+ | |||
+ | -- | ||
+ | -- Call example: {{#invoke: CTD | info | text=1 | page=17 | item=3 }} | ||
function ctd.info( frame ) | function ctd.info( frame ) | ||
− | local | + | local term = '' |
+ | local reference = '' | ||
+ | local description = '' | ||
+ | local origin = '' | ||
+ | local wiki_page = frame.args['wiki_page'] | ||
− | return | + | -- 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) | ||
+ | local view string.sub( string.lower(frame.args['userparam']), j, -1 ) | ||
+ | |||
+ | -- check if 'term' or 'term to show' are specified | ||
+ | if not isempty(frame.args['понятие для показа']) then | ||
+ | term = frame.args['понятие для показа'] | ||
+ | elseif not isempty(frame.args['понятие']) then | ||
+ | term = frame.args['понятие'] | ||
+ | else | ||
+ | term = text | ||
+ | end | ||
+ | |||
+ | -- check if short description is specified | ||
+ | if not isempty(frame.args['кратко']) then | ||
+ | description = frame.args['кратко'] | ||
+ | else | ||
+ | description = frame.args['описание'] | ||
+ | end | ||
+ | |||
+ | -- check if origin specified | ||
+ | if not isempty(frame.args['происхождение']) then | ||
+ | origin = ' ' .. frame.args['происхождение'] | ||
+ | end | ||
+ | |||
+ | -- considering type of view | ||
+ | if 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 = '<ref>' .. term .. origin .. ' – ' .. description .. ' (БТС, [['.. wiki_page .. '|' .. term .. ']])</ref>' | ||
+ | end | ||
+ | if view == 'скобки' then | ||
+ | text = text .. ' [' .. description .. ']' | ||
+ | end | ||
+ | |||
+ | return text .. reference | ||
end | end |
Версия 05:49, 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
--
-- Call example: {{#invoke: CTD | info | text=1 | page=17 | item=3 }}
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)
local view string.sub( string.lower(frame.args['userparam']), j, -1 )
-- check if 'term' or 'term to show' are specified
if not isempty(frame.args['понятие для показа']) then
term = frame.args['понятие для показа']
elseif not isempty(frame.args['понятие']) then
term = frame.args['понятие']
else
term = text
end
-- check if short description is specified
if not isempty(frame.args['кратко']) then
description = frame.args['кратко']
else
description = frame.args['описание']
end
-- check if origin specified
if not isempty(frame.args['происхождение']) then
origin = ' ' .. frame.args['происхождение']
end
-- considering type of view
if 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 = '<ref>' .. term .. origin .. ' – ' .. description .. ' (БТС, [['.. wiki_page .. '|' .. term .. ']])</ref>'
end
if view == 'скобки' then
text = text .. ' [' .. description .. ']'
end
return text .. reference
end