Модуль:Military: различия между версиями
Перейти к навигации
Перейти к поиску
StasR (обсуждение | вклад) Нет описания правки |
StasR (обсуждение | вклад) Нет описания правки |
||
Строка 143: | Строка 143: | ||
end | end | ||
if unit == '' then | if unit == '' then | ||
return '<div class="mil-div ' .. mode .. '" style="width: ' .. width .. 'px;"><div class="mil-number">' .. label .. '</div></div>' | return '<div class="mil-div ' .. mode .. '" style="width: ' .. width .. 'px;' .. (args[divcss] or '') .. '"><div class="mil-number">' .. label .. '</div></div>' | ||
end | end | ||
local z = tablo[prefix .. unit .. postfix] | local z = tablo[prefix .. unit .. postfix] |
Версия от 19:59, 6 августа 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' -- '</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
--[===[
prev | start | stop | post
могут использоваться при единственном элементе (если отсутствует stop)
* текст = показываемый текст
* подсказка = подсказка к тексту
цвет = 0 (по умолчанию), 1, 2, г
формат = стандарт (по умолчанию), заголовок (узкая полоска), раздел (стандартная высота, сдвиг вправо)
шрифт = стандарт (по умолчанию), мелко (80%), хх%
размер = число колонок
--]===]
local function parseList( list )
local out = {}
for x in mw.text.gsplit( list, ',', true ) do
local start,finish = string.match(x,'^%s*(%d+)%s*%-%s*(%d+)%s*$')
if start then
start, finish = tonumber( start ), tonumber( finish )
for u = start, finish do
out[#out+1] = u
end
else
x = mw.text.trim( x )
if x ~= '' then
out[#out+1] = x
end
end
end
return out
end
function p.Unit( frame )
local args = frame.args
return p._unit( args )
end
function p._unit( args )
local modeClasses = {
['стандарт'] = '',
['заголовок'] = 'mil-header',
['раздел'] = 'mil-chapter',
}
local tablo = mw.loadData( 'Module:CatNav/segment' )
local prefix, units, postfix
= mw.text.trim( args[1] or '' ), parseList( args[2] ), mw.text.trim( args[3] or '' )
local text, comment
if #units <= 1 then
text = args['текст']
comment = args['подсказка']
end
if prefix ~= '' then
prefix = prefix .. ' '
end
if postfix ~= '' then
postfix = ' ' .. postfix
end
local width = ( args['размер'] or 1 ) * 29 - 1
local mode = mw.text.trim( args['формат'] or '' )
mode = modeClasses[mode] or 'mil-error'
local function processUnit( unit )
local label = text or unit
if comment then
label = '<abbr title="' .. comment .. '">' .. label .. '</abbr>'
end
if unit == '' then
return '<div class="mil-div ' .. mode .. '" style="width: ' .. width .. 'px;' .. (args[divcss] or '') .. '"><div class="mil-number">' .. label .. '</div></div>'
end
local z = tablo[prefix .. unit .. postfix]
if z then
mw.ext.luaglobal.add( 'CatClassValue', prefix .. unit .. postfix )
end
return '<div class="mil-div" style="width: ' .. width .. 'px;"><div class="mil-number">['
.. tostring( mw.uri.fullUrl( 'НКВД:Выборка', { class = 'segment', value = prefix .. unit .. postfix } ) )
.. ' ' .. label .. ']</div><div class="mil-quantity">' .. ( z or '<span style="color:red">0</span>' ) .. '</div></div>'
end
local out = {}
if #units > 0 then
for _, unit in ipairs( units ) do
out[#out+1] = processUnit( unit )
end
out = table.concat( out )
else
out = processUnit( '' )
end
return out
end
return p