Модуль:Military: различия между версиями
Перейти к навигации
Перейти к поиску
StasR (обсуждение | вклад) Нет описания правки |
StasR (обсуждение | вклад) Нет описания правки |
||
Строка 35: | Строка 35: | ||
function processUnit( unit ) | function processUnit( unit ) | ||
if mode == 'номерМС' then | if mode == 'номерМС' then | ||
local label = text or unit | |||
if comment then | if comment then | ||
label = '<abbr title="' .. comment .. '">' .. label .. '</abbr>' | |||
end | end | ||
if unit == '' then | if unit == '' then | ||
return '<td class="military-number ' .. class .. '" ' .. attr ..'>' .. | return '<td class="military-number ' .. class .. '" ' .. attr ..'>' .. label .. '</td>' | ||
end | end | ||
return '<td class="military-number ' .. class .. '" ' .. attr ..'>[' | return '<td class="military-number ' .. class .. '" ' .. attr ..'>[' | ||
.. tostring( mw.uri.fullUrl( 'НКВД:Выборка', { class = 'segment', value = prefix .. unit .. postfix } ) ) | .. tostring( mw.uri.fullUrl( 'НКВД:Выборка', { class = 'segment', value = prefix .. unit .. postfix } ) ) | ||
.. ' <span class=military-number>' .. | .. ' <span class=military-number>' .. label .. '</span>]</td>\n' | ||
elseif mode == 'числоМС' then | elseif mode == 'числоМС' then | ||
if unit == '' then | if unit == '' then |
Версия от 10:33, 24 июля 2017
Для документации этого модуля может быть создана страница Модуль:Military/doc
local p = {}
function p.loop( frame )
local args = frame:getParent().args
return p._loop( args )
end
function p.Loop( frame )
local args = frame.args
return p._loop( args )
end
function p._loop( args )
local start, finish, text, comment = tonumber( args[2] ), tonumber( args[3] )
if not finish then
start = mw.text.trim( args[2] )
text = args['текст']
comment = args['подсказка']
end
local prefix, postfix = mw.text.trim( args[1] or '' ), mw.text.trim( args[4] or '' )
if prefix ~= '' then
prefix = prefix .. ' '
end
if postfix ~= '' then
postfix = ' ' .. postfix
end
local prefixURL, postfixURL = mw.uri.encode( prefix ), mw.uri.encode( postfix )
local mode = mw.text.trim( args['формат'] or 'номерМС' )
local class = mw.text.trim( args['class'] or '' )
if class == '' then
class = 'military-main'
end
local attr = mw.text.trim( args['attr'] or '' )
local tablo = mw.loadData( 'Module:CatNav/segment' )
function processUnit( unit )
if mode == 'номерМС' then
local label = text or unit
if comment then
label = '<abbr title="' .. comment .. '">' .. label .. '</abbr>'
end
if unit == '' then
return '<td class="military-number ' .. class .. '" ' .. attr ..'>' .. label .. '</td>'
end
return '<td class="military-number ' .. class .. '" ' .. attr ..'>['
.. tostring( mw.uri.fullUrl( 'НКВД:Выборка', { class = 'segment', value = prefix .. unit .. postfix } ) )
.. ' <span class=military-number>' .. label .. '</span>]</td>\n'
elseif mode == 'числоМС' then
if unit == '' then
return '<td class="military-quantity ' .. class .. '" ' .. attr ..'>' .. ( text or '' ) .. '</td>'
end
local z = tablo[prefix .. unit .. postfix]
if z then
mw.ext.luaglobal.add( 'CatClassValue', prefix .. unit .. postfix )
end
return '<td class="military-quantity ' .. class .. '" ' .. attr ..'>['
.. tostring( mw.uri.fullUrl( 'НКВД:Выборка', { class = 'segment', value = prefix .. unit .. postfix } ) )
.. ' <span class="military-quantity>' .. ( z or '<span style="color:red">0</span>' ) .. '</span>]</td>\n'
end
end
local out = ''
if finish then
for unit = start, finish do
out = out .. processUnit( unit )
end
else
out = processUnit( start )
end
return out
end
return p