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

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

м
нет описания правки
мНет описания правки
мНет описания правки
Строка 3: Строка 3:
local function isempty(s)
local function isempty(s)
   return s == nil or s == ''
   return s == nil or s == ''
end
-- Split string 'inputstr' by separator 'sep' and return values in table
local function split_string(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={}
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        table.insert(t, str)
    end
    return t
end
end


Строка 92: Строка 104:
-- Call example:  
-- Call example:  
-- {{#invoke: CTD | info  
-- {{#invoke: CTD | info  
--  | type        = Type of term: понятие (по умолчанию), личность, выражение, литература, периодика / conception, person, expression, literature, periodical
--  | style        = серый / gray 
--  | term        = Term, that is word or phrase  
--  | term        = Term, that is word or phrase  
--  | term_to_show = Term with accent or diacritic marks  
--  | term_to_show = Term with accent or diacritic marks  
Строка 101: Строка 111:
--  | origin      = Origin  
--  | origin      = Origin  
--  | wiki_page    = Wiki page title  
--  | wiki_page    = Wiki page title  
--  | userparam    = text@view  
--  | userparam    = text@view@type@style
-- }}
-- }}
-- Where 'userparam' consist of:
-- Where 'userparam' consist of all the parameters that can not be fetched by symantic property:
-- text = text to show; generally it is the original text of request
-- * 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)
-- * view = style of displaying information
-- * type = type of term: понятие (по умолчанию), личность, выражение, литература, периодика / conception, person, expression, literature, periodical
-- * style= серый / gray
-- View, type and style are language dependent parameters, consider changes in code below.
function ctd.info( frame )
function ctd.info( frame )
local term = ''
local term = ''
Строка 116: Строка 129:
-- split 'text@view' value of parameter 'userparam' in two variables
-- split 'text@view' value of parameter 'userparam' in two variables
local i, j = string.find(frame.args['userparam'],'@',1,true)
--local i, j = string.find(frame.args['userparam'],'@',1,true)
local text = string.sub(frame.args['userparam'], 1, i-1)
--local text = string.sub(frame.args['userparam'], 1, i-1)
local view = string.sub( string.lower(frame.args['userparam']), j+1 )
--local view = string.sub( string.lower(frame.args['userparam']), j+1 )
-- split 'userparam' in variables
local t = split_string(frame.args['userparam'],'@')
local text, view, term_type, style = t[1], t[2], t[3], t[4]
if isempty(view) then view = 'подсказка' end
if isempty(term_type) then term_type = 'понятие' end
if isempty(style) then style = 'серый' end


-- define term to show, i.e. with accent and diacritic
-- define term to show, i.e. with accent and diacritic
Строка 145: Строка 164:
end
end
-- check if origin or lifetime specified
-- construct origin string
-- style for expression: (lang. origin)
-- all other types: (origin, lifetime)
if not isempty(frame.args['origin']) or not isempty(frame.args['lifetime']) then
if not isempty(frame.args['origin']) or not isempty(frame.args['lifetime']) then
origin = ' ('
origin = ' ('
if not isempty(frame.args['language']) then
origin = origin ..frame.args['language'] .. '. '
end
if not isempty(frame.args['origin']) then
if not isempty(frame.args['origin']) then
origin = origin .. frame.args['origin']
origin = origin .. frame.args['origin']
Строка 182: Строка 206:
-- DEBUG
-- DEBUG
--text = '<p>DEBUG: view: '.. view .."; term: ".. term .."; term to show: ".. term_to_show .."; description: ".. description .."; origin: ".. origin ..'</p>'.. text
--text = '<p>DEBUG: view: '.. view .."; term: ".. term .."; term to show: ".. term_to_show .."; description: ".. description .."; origin: ".. origin ..'</p>'.. text
--text = 'text='.. text ..'; view='.. view ..'; type='.. term_type ..'; style='.. style
--return  text .. reference  
--return  text .. reference