Модуль:Timeline
Материал из Справочника наблюдателя
Описание модуля[]
Документация отсутствует!
Вы можете создать документацию ( создать ).
Задавайте категории на странице документации, а не здесь! Показать подстраницы
Задавайте категории на странице документации, а не здесь! Показать подстраницы
local p = {}
tab = mw.loadData( 'Модуль:Timeline/Parameters')
tabtranslit = {
['А'] = 'a',
['Б'] = 'b',
['В'] = 'v',
['Г'] = 'g',
['Д'] = 'd',
['Е'] = 'e',
['Ё'] = 'e',
['Ж'] = 'j',
['З'] = 'z',
['И'] = 'i',
['Й'] = 'y',
['К'] = 'k',
['Л'] = 'l',
['М'] = 'm',
['Н'] = 'n',
['О'] = 'o',
['П'] = 'p',
['Р'] = 'r',
['С'] = 's',
['Т'] = 't',
['У'] = 'u',
['Ф'] = 'f',
['Х'] = 'h',
['Ц'] = 'ts',
['Ч'] = 'ch',
['Ш'] = 'sh',
['Щ'] = 'sch',
['Ъ'] = '',
['Ы'] = 'y',
['Ь'] = '',
['Э'] = 'e',
['Ю'] = 'yu',
['Я'] = 'ya',
['а'] = 'a',
['б'] = 'b',
['в'] = 'v',
['г'] = 'g',
['д'] = 'd',
['е'] = 'e',
['ё'] = 'e',
['ж'] = 'j',
['з'] = 'z',
['и'] = 'i',
['й'] = 'y',
['к'] = 'k',
['л'] = 'l',
['м'] = 'm',
['н'] = 'n',
['о'] = 'o',
['п'] = 'p',
['р'] = 'r',
['с'] = 's',
['т'] = 't',
['у'] = 'u',
['ф'] = 'f',
['х'] = 'h',
['ц'] = 'ts',
['ч'] = 'ch',
['ш'] = 'sh',
['щ'] = 'sch',
['ъ'] = 'y',
['ы'] = 'y',
['ь'] = '',
['э'] = 'e',
['ю'] = 'yu',
['я'] = 'ya',
}
function translit (CTPOKA)
local stroka = ''
local v
for k = 1, mw.ustring.len (CTPOKA) do
v = mw.ustring.sub (CTPOKA,k,k)
if tabtranslit [v] then
stroka = stroka .. tabtranslit [v]
else
stroka = stroka .. v
end
end
return stroka
end
--]=]
function p.Section (frame)
local ownArgs = frame.args
return ('<tr><th colspan=6><big>' .. ownArgs['текст'] .. '</big></th></tr>')
end
function p.Subsection (frame)
local ownArgs = frame.args
return ('<tr><th colspan=6><i>' .. ownArgs['текст'] .. '</i></th></tr>')
end
function p.Event (frame)
local extArgs = frame:getParent().args
local ownArgs = frame.args
local function checkBill ( condition )
local bi = ownArgs [condition] or ''
if bi ~= '' then
local link = tab.tableDoc [condition]
local code = link.code
local part = link.part or 'ст.'
link = link.link
bi = mw.ustring.gsub (bi, '<_([^#][^:]-)_>', '[[' .. link .. ' %1|' .. part .. ' %1]]')
bi = mw.ustring.gsub (bi, '<_([^#][^:]-):(.-)_>', '[['..link..'%1|<span style="white-space: nowrap;">%2 ' .. part .. ' %1</span>]]')
return "'''" .. code .. "''' " .. bi
end
return nil
end
-- неименованные параметры в extArgs — это заданные признаки
-- неименованные параметры в ownArgs — это признаки, для которых применимо правило
local inCond = {}
for i, co in ipairs (extArgs) do
inCond [mw.text.trim(co)] = true
end
-- Проверка применимости правила
local krome
local positive = ownArgs [1] == 'кроме'
for i, co in ipairs (ownArgs) do
co = mw.text.trim(co)
if co == 'кроме' then
if krome then
return 'ERROR\n\n'
end
if not positive then -- не выполнилось ни одно условие «для»
return nil
end
krome = i
elseif inCond [co] then
if krome then
return nil
end
positive = true
end
end
if not positive and ownArgs [1] then
return nil
end
local res = {}
local who = ownArgs['кто'] or ''
table.insert (res, ' <td class="nwtl-who">' .. who .. '</td>')
local id,idR = ownArgs['метка'], ownArgs['дляметки']
if id then
table.insert (res, ' <td class="nwtl-text" id="nwtl-text-' .. id .. '">' .. ownArgs['текст'] .. '</td>')
else
table.insert (res, ' <td class="nwtl-text">' .. ownArgs['текст'] .. '</td>')
end
local nocut = ownArgs['сокр'] or ''
if id then
local classes = {'nwtl-val'}
local content = extArgs[id] or ''
if content ~= '' then
table.insert (classes, 'nwtl-fix')
end
-- if nocut ~= '' then
-- table.insert (classes, 'nwtl-no-k')
-- end
local alt = ownArgs['вместо'] or ''
if alt ~= '' then
alt = mw.text.split (alt,',')
for i, v in ipairs (alt) do
table.insert (classes, 'nwtl-alt-' .. mw.text.trim(v))
end
end
table.insert (res, ' <td class="' .. table.concat(classes,' ') .. '" id="nwtl-val-' .. id .. '">' .. content .. '</td>')
elseif idR then
table.insert (res, ' <td class="nwtl-coval nwtl-copy-' .. idR .. '"></td>')
end
local bills = {}
local bill = checkBill ('все')
if bill then
table.insert (bills, bill)
end
for v, i in pairs (inCond) do
bill = checkBill (v)
if bill then
table.insert (bills, bill)
end
bill = checkBill (v .. '+')
if bill then
table.insert (bills, bill)
end
end
if #bills ~= 0 then
table.insert (res, ' <td class="nwtl-doc">' .. table.concat (bills, '; ') .. '</td>')
else
table.insert (res, ' <td> </td>')
end
idR = id or idR
local function testField (fieldName, class) -- (начало, min) или (конец, max)
local param = ownArgs [fieldName] or ''
param = mw.text.split (param, ';')
if #param == 3 then
if inCond ['М'] then
param = param [3]
elseif inCond ['Р'] then
param = param [2]
elseif inCond ['Ф'] then
param = param [1]
else
param = ''
end
elseif #param == 1 then
param = param [1]
end
param = tonumber (mw.text.trim (param)) or ''
if param == '' then
table.insert (res, ' <td class="nwtl-rel-empty"></td>')
return nil -- нет значения — нет проверки
end
local first = mw.ustring.sub (fieldName,1,1)
local calc = ownArgs [first..'-тип'] or ''
if calc == '' then
calc = ownArgs ['тип'] or ''
end
if calc == '' then
calc = 'за'
end
--[[
calc = tab.intervals [calc]
--]] calc = tab.intervalCode [calc]
if calc == nil then
table.insert (res, ' <td class="nwtl-rel-syntax">' .. class .. '</td>')
return nil
end
local base = ownArgs [first..'-база'] or ''
if base == '' then
base = ownArgs ['база'] or ''
end
if base == '' then
base = 'vote'
end
base = mw.text.split (base, ',')
local bases = {}
for i, v in ipairs (base) do
v = mw.text.trim (v)
if v ~= '' then
if mw.ustring.sub(v,1,4) == 'min.' then
v = 'nwtl-basemin-' .. mw.ustring.sub(v,5)
elseif mw.ustring.sub(v,1,4) == 'max.' then
v = 'nwtl-basemax-' .. mw.ustring.sub(v,5)
else
v = 'nwtl-base-' .. v
end
table.insert (bases, v)
end
end
if nocut ~= '' then
table.insert (bases, 'nwtl-no-k')
end
--[[
table.insert (res, ' <td class="nwtl-rel nwtl-' .. class .. '-' .. id .. ' ' .. table.concat (bases, ' ')
.. ' nwtl-calc-' .. calc[3] .. ' nwtl-param-' .. (param*calc[1] + calc [2]) .. '"></td>')
--]]
local idVa = ''
if id then
idVa = 'id="nwtl-' .. class .. '-' .. id .. '" '
end
table.insert (res, ' <td ' .. idVa .. 'class="nwtl-rel nwtl-' .. class .. '-' .. idR .. ' ' .. table.concat (bases, ' ')
.. ' nwtl-calc-' .. calc .. ' nwtl-param-' .. param .. '"></td>')
return nil
end
testField ('начало', 'min')
testField ('конец', 'max')
if #res == 0 then
return nil
else
return ('\n<tr>\n' .. table.concat (res,'\n') .. '\n</tr>')
end
end
return p