Перейти к содержанию

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

м
-output design in literature_origin()
мНет описания правки
м (-output design in literature_origin())
 
(не показано 27 промежуточных версий этого же участника)
Строка 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 FUNCTIONS ========================================================


local function isempty(s)
local function isempty(s)
Строка 17: Строка 19:
     return t
     return t
end
end


-- Convert local links [[link|text]] and URL [link text] to plain text.
-- Convert local links [[link|text]] and URL [link text] to plain text.
Строка 65: Строка 66:
return str
return str
end
end
-- === FUNCTIONS FOR EXTERNAL USAGE ===========================================
-- Create origin string for literature
-- Used in : Шаблон:Литература БТС
-- Call example:
-- {{#invoke: CTD | literature_origin
--  | origin =
--  | language =
--  | author  =
--  | title    =
-- }}
function ctd.literature_origin( frame )
local result = ''
-- if 'origin' set, use it and skip other parameters
if not isempty(frame.args['origin']) then
result = frame.args['origin']
else -- check every other parameter for existance
if not isempty(frame.args['language']) then
result = frame.args['language']
if not isempty(frame.args['author']) or not isempty(frame.args['title']) then
result = result .. ': '
end
end
if not isempty(frame.args['author']) then
result = result .. frame.args['author']
if not isempty(frame.args['title']) then
result = result .. ', '
end
end
if not isempty(frame.args['title']) then
result = result .. '<i>' .. frame.args['title'] .. '</i>'
end
end
return result
end


-- Create short description without hyper links
-- Create short description without hyper links
Строка 132: Строка 173:
local description = ''
local description = ''
local origin = ''
local origin = ''
local lifetime = '' -- date with title
local lifetime_str = '' -- date with title
local lifetime_short = ''   -- just date
local lifetime = '' -- just date
local term_link = ''
local term_link = ''
local ctd_title = '<span style="border-bottom: 1px dotted gray; cursor:help;" title="Большой теософский словарь">БТС</span>'
local ctd_title = '<span style="border-bottom: 1px dotted gray; cursor:help;" title="Большой теософский словарь">БТС</span>'
local output_str = '' -- result string to show
local output_str = '' -- result string to show
-- variables for 'view' parameter
-- variables for 'view' parameter
local view_popup, view_footnote, view_brackets = false
local view_popup, view_footnote, view_brackets, view_link = false
-- variables for 'style' parameter
-- variables for 'style' parameter
local font_grey      = false  -- make font grey
local font_grey      = false  -- make font grey
local add_origin      = false  -- add information on origin
local add_origin      = false  -- add information on origin
local add_description = false  -- add short description
local add_description = false  -- add short description
local add_link        = false  -- add hyperlink to wiki page


-- split 'userparam' in variables
-- split 'userparam' in variables
Строка 155: Строка 197:
if mw.ustring.find(view,'сноска',1,true)    ~= nil then view_footnote = true end
if mw.ustring.find(view,'сноска',1,true)    ~= nil then view_footnote = true end
if mw.ustring.find(view,'скобки',1,true)    ~= nil then view_brackets = true end
if mw.ustring.find(view,'скобки',1,true)    ~= nil then view_brackets = true end
if mw.ustring.find(view,'ссылка',1,true)    ~= nil then view_link    = true end
-- parse 'style' for values
-- parse 'style' for values
if mw.ustring.find(style,'серый',1,true)    ~= nil then font_grey      = true end
if mw.ustring.find(style,'серый',1,true)    ~= nil then font_grey      = true end
if mw.ustring.find(style,'оригинал',1,true) ~= nil then add_origin    = true end
if mw.ustring.find(style,'оригинал',1,true) ~= nil then add_origin    = true end
if mw.ustring.find(style,'описание',1,true) ~= nil then add_description= true end
if mw.ustring.find(style,'описание',1,true) ~= nil then add_description= true end
if mw.ustring.find(style,'ссылка',1,true)  ~= nil then add_link      = true end


-- define term to show, i.e. with accent and diacritic
-- define term to show, i.e. with accent and diacritic
Строка 213: Строка 257:
if not isempty(frame.args['lifetime']) then
if not isempty(frame.args['lifetime']) then
if term_type == 'личность' then
if term_type == 'личность' then
lifetime = ' Время жизни: '.. frame.args['lifetime']
lifetime_str = ' Время жизни: '.. frame.args['lifetime']
elseif term_type == 'выражение' then
elseif term_type == 'выражение' then
lifetime = ' Время применения: '.. frame.args['lifetime']
lifetime_str = ' Время применения: '.. frame.args['lifetime']
else
else
lifetime = ' Время существования: '.. frame.args['lifetime']
lifetime_str = ' Время существования: '.. frame.args['lifetime']
end
end
lifetime_short = frame.args['lifetime']
lifetime = frame.args['lifetime']
end
end
if not isempty(frame.args['published']) then
if not isempty(frame.args['published']) then
lifetime = ' Время публикации: '.. frame.args['published']
lifetime_str = ' Время публикации: '.. frame.args['published']
lifetime_short = frame.args['published']
lifetime = frame.args['published']
end
end
if    not isempty(frame.args['lifetime'])  
if    not isempty(frame.args['lifetime'])  
  or not isempty(frame.args['published']) then
  or not isempty(frame.args['published']) then
lifetime = lifetime .. '.'
lifetime_str = lifetime_str .. '.'
end
end
Строка 244: Строка 288:
term_with_link    = frame.args['author'] ..', «'.. term_with_link ..'»'
term_with_link    = frame.args['author'] ..', «'.. term_with_link ..'»'
term_without_link = frame.args['author'] ..', «'.. term_without_link ..'»'
term_without_link = frame.args['author'] ..', «'.. term_without_link ..'»'
end
-- add publishing date
if term_type == 'литература' then
term_without_link = term_without_link ..', '.. lifetime_short
end
end
-- add volume, chapter, page and so on
-- add volume, chapter, page and so on
Строка 253: Строка 293:
term_with_link    = term_with_link    ..', '.. specification
term_with_link    = term_with_link    ..', '.. specification
term_without_link = term_without_link ..', '.. specification
term_without_link = term_without_link ..', '.. specification
end
-- add LINK to original text
if view_link then
if not isempty(frame.args['wiki_page']) then
text = '[['.. frame.args['wiki_page'] ..'|'.. text ..']]'
end
end
end
Строка 258: Строка 305:
if view_popup then
if view_popup then
if term_type == 'литература' or term_type == 'личность' then
if term_type == 'литература' or term_type == 'личность' then
output_str = term_without_link ..', '.. lifetime_short
output_str = term_without_link  
if add_origin then
output_str = output_str ..' '.. origin
elseif not isempty(lifetime) then
output_str = output_str .. ' ('.. lifetime ..')'
end
if add_description then output_str = output_str ..'. – '.. description end
else -- для 'понятие' и 'выражение'
else -- для 'понятие' и 'выражение'
output_str = description
output_str = term_without_link ..'. '.. description
if add_origin then output_str = output_str ..' '.. origin end
end
end
if add_origin   then output_str = output_str ..' '.. origin end
text = '<span style="border-bottom: 1px dotted gray; cursor: help;" title="' .. output_str .. ' (БТС).">' .. text .. '</span>'   
if add_description then output_str = output_str ..'. – '.. description end
text = '<span style="border-bottom: 1px dotted gray; cursor: help;" title="' .. output_str .. ' (БТС, ' .. term .. ').">' .. text .. '</span>'   
end
end
 
-- FOOTNOTE should be added
-- FOOTNOTE should be added
if view_footnote then
if view_footnote then
output_str = term_with_link
-- всегда добавлять ссылку в сноске
if add_origin then output_str = output_str ..' '.. origin end
output_str = term_with_link
if add_origin then
output_str = output_str ..' '.. origin
else
if term_type == 'личность' then
output_str = output_str .. ' ('.. lifetime ..')'
end
end
if add_description then output_str = output_str ..'. – '.. description end
if add_description then output_str = output_str ..'. – '.. description end
if font_grey then output_str = '<span style="color: gray;">' .. output_str ..'</span>' end
if font_grey then output_str = '<span style="color: gray;">' .. output_str..' ('.. ctd_title ..')</span>' end
text = text ..'<ref>' .. output_str ..' ('.. ctd_title ..').</ref>'
text = text ..'<ref>' .. output_str ..'.</ref>'
end
end
Строка 279: Строка 339:
if view_brackets then
if view_brackets then
if term_type == 'литература' or term_type == 'личность' then
if term_type == 'литература' or term_type == 'личность' then
output_str = term_without_link ..', '.. lifetime_short
if add_link then
output_str = term_with_link
else
output_str = term_without_link  
end
if add_origin then
output_str = output_str ..' '.. origin
else
output_str = output_str .. ' ('.. lifetime ..')'
end
if add_description then output_str = output_str ..'. – '.. description end
else -- для 'понятие' и 'выражение'
else -- для 'понятие' и 'выражение'
output_str = description
output_str = description
if add_origin then output_str = output_str ..' '.. origin end
end
end


if add_origin then output_str = output_str ..' '.. origin end
output_str = ' <nowiki>[</nowiki>' .. output_str .. ']'
if add_description then output_str = output_str ..'. – '.. description end
if font_grey then output_str = '<span style="color: gray;">' .. output_str ..'</span>' end
output_str = ' [' .. output_str .. '.]'
if font_grey then output_str = '<span style="color: gray;">' .. output_str ..'</span>' end
text = text .. output_str
text = text .. output_str
end
end
-- DEBUG
-- DEBUG
text = 'userparam: '.. frame.args['userparam'] ..'\n- text ='.. text_original ..'\n- view ='.. view ..'\n- type ='.. term_type ..'\n- style ='.. tostring(style) ..' ⇒ font_grey ='.. tostring(font_grey) ..'; add_origin ='.. tostring(add_origin) ..'; add_description ='.. tostring(add_description) ..'\n- specification ='.. specification ..'\nOUTPUT: '.. text
--text = 'userparam: '.. frame.args['userparam'] ..'\n- text ='.. text_original ..'\n- view ='.. view ..'\n- type ='.. term_type ..'\n- style ='.. tostring(style) ..' ⇒ font_grey ='.. tostring(font_grey) ..'; add_origin ='.. tostring(add_origin) ..'; add_description ='.. tostring(add_description) ..'; add_link ='.. tostring(add_link) ..'\n- specification ='.. specification ..'\nOUTPUT: '.. text
return  text  
--return  text  


     --return frame:preprocess( text )
     return frame:preprocess( text )
end
end


return ctd
return ctd