Модуль:Ссылки: различия между версиями
Перейти к навигации
Перейти к поиску
StasR (обсуждение | вклад) Нет описания правки |
StasR (обсуждение | вклад) Нет описания правки |
||
(не показаны 3 промежуточные версии этого же участника) | |||
Строка 89: | Строка 89: | ||
local out = [[ | local out = [[ | ||
<div style="width: 100%; max-width: 1000px; background-color: #e8f0e6; margin-bottom: 10px; "> | <div style="width: 100%; max-width: 1000px; background-color: #e8f0e6; margin-bottom: 10px; "> | ||
<div style="display: table; "> | <div style="display: table; width: 100%; "> | ||
<div style="display: table-caption; background-color: #B9C7B7; padding: 4px; ">]] | <div style="display: table-caption; background-color: #B9C7B7; padding: 4px; ">]] | ||
.. ( Args['заголовок'] or header( Args ) ) .. [[</div> | .. ( Args['заголовок'] or header( Args ) ) .. [[</div> | ||
Строка 104: | Строка 104: | ||
local function endCite1() | local function endCite1() | ||
return [[ | return [[ | ||
<i></i> | |||
</div> | </div> | ||
<div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: bottom; "><i class="fa fa-quote-right fa-3x" style="color: #AEC8A9; "></i></div> | <div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: bottom; "><i class="fa fa-quote-right fa-3x" style="color: #AEC8A9; "></i></div> | ||
Строка 111: | Строка 112: | ||
<div style="display: table-cell; padding: 2px; "> | <div style="display: table-cell; padding: 2px; "> | ||
<hr> | <hr> | ||
<p style="text-align:right">]] .. global.get( 'Cite1' ) .. [[</p> | <p style="text-align:right; font-size:90%;">]] .. global.get( 'Cite1' ) .. [[</p> | ||
</div> | </div> | ||
<div style="display: table-cell; padding: 2px; width: 80px; "></div> | <div style="display: table-cell; padding: 2px; width: 80px; "></div> | ||
Строка 124: | Строка 125: | ||
{ true, ['заголовок'] = true, ['текст'] = true, | { true, ['заголовок'] = true, ['текст'] = true, | ||
['первоисточник'] = true, ['источник'] = true, ['архив'] = true, | ['первоисточник'] = true, ['источник'] = true, ['архив'] = true, | ||
['дополнение'] = true, ['сноска'] = true, } ) | ['дополнение'] = true, ['сноска'] = true, ['формат'] = true, } ) | ||
if not Args then | if not Args then | ||
return tools.errorMsg( 'ссылка', 'Неизвестный параметр «' .. tmp .. '»', '' ) | return tools.errorMsg( 'ссылка', 'Неизвестный параметр «' .. tmp .. '»', '' ) | ||
Строка 139: | Строка 140: | ||
end | end | ||
global.set( 'Cite1', Args['заголовок'] or header( Args ) ) | global.set( 'Cite1', Args['заголовок'] or header( Args ) ) | ||
local style = Args['формат'] | |||
if style then | |||
style = '; white-space: ' .. style | |||
end | |||
local out = [[ | local out = [[ | ||
<div style="width: 100%; max-width: 1000px; background-color: #e8f0e6; margin-bottom: 10px; "> | <div style="width: 100%; max-width: 1000px; background-color: #e8f0e6; margin-bottom: 10px; "> | ||
<div style="display: table; "> | <div style="display: table; width: 100%; "> | ||
<div style="display: table-row; "> | <div style="display: table-row; "> | ||
<div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: top; "><i class="fa fa-quote-left fa-3x" style="color: #AEC8A9; "></i></div> | <div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: top; "><i class="fa fa-quote-left fa-3x" style="color: #AEC8A9; "></i></div> | ||
<div style="display:table-cell;padding:2px; "> | <div style="display: table-cell; padding: 2px]] .. ( style or '' ) .. [[; "> | ||
]] | ]] | ||
if Args['текст'] then | if Args['текст'] then |
Версия от 13:17, 4 июня 2017
Для документации этого модуля может быть создана страница Модуль:Ссылки/doc
local p = {}
tools = require( 'Модуль:Tools' )
local global = mw.ext.luaglobal;
p[''] = function ( frame )
local Args, tmp = tools.checkargs( frame:getParent().args,
{ ['публикация'] = true, ['источник'] = true, ['архив'] = true, } )
if not Args then
return tools.errorMsg( 'Ссылки', 'Неизвестный параметр «' .. tmp .. '»', '' )
end
local out = {}
if Args['публикация'] then
out[#out+1] = 'опубликовано: <span class="nkvd-value">'
.. Args['публикация'] .. '</span>'
end
if Args['источник'] then
out[#out+1] = 'воспроизводится по: <span class="nkvd-value">'
.. Args['источник'] .. '</span>'
end
if Args['архив'] then
out[#out+1] = '<span class="nkvd-value">'
.. Args['архив'] .. '</span>'
end
return '<span class="nkvd-links">' .. table.concat( out, ' • ' ) .. '</span>'
end
local function header( Args )
local out
if Args['первоисточник'] then
out = '<span class="nkvd-value">' .. Args['первоисточник']
.. '</span> (цит. по: <span class="nkvd-value">'
.. ( Args[1] or Args['источник'] ) .. '</span>)'
elseif Args[1] or Args['источник'] then
out = '<span class="nkvd-value">' .. ( Args[1] or Args['источник'] ) .. '</span>'
end
if Args['архив'] then
if out then
out = out .. '; '
else
out = ''
end
out = out .. '<span class="nkvd-archive">' .. Args['архив'] .. '</span>'
end
return '<span class="nkvd-links">' .. out .. tools.commonParams( Args['дополнение'], Args['сноска'] )
.. '</span>'
end
local function endCite()
return [[
</div>
<div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: bottom; "><i class="fa fa-quote-right fa-3x" style="color: #AEC8A9; "></i></div>
</div>
</div>
</div>
]]
end
p.Main = function ( frame )
local Args, tmp = tools.checkargs( frame:getParent().args,
{ true, ['первоисточник'] = true, ['источник'] = true, ['архив'] = true,
['дополнение'] = true, ['сноска'] = true, } )
if not Args then
return tools.errorMsg( 'ссылка', 'Неизвестный параметр «' .. tmp .. '»', '' )
end
if Args[1] and Args['источник'] then
return tools.errorMsg( 'ссылка', 'Источник задан и как позиционный параметр, и как ключевой', '' )
end
return header( Args )
end
p.Cite = function ( frame )
local Args, tmp = tools.checkargs( frame:getParent().args,
{ true, ['заголовок'] = true, ['текст'] = true,
['первоисточник'] = true, ['источник'] = true, ['архив'] = true,
['дополнение'] = true, ['сноска'] = true, } )
if not Args then
return tools.errorMsg( 'ссылка', 'Неизвестный параметр «' .. tmp .. '»', '' )
end
if Args[1] == 'конец' then
return endCite()
end
if Args[1] and ( Args['источник'] or Args['заголовок'] ) then
return tools.errorMsg( 'ссылка', 'Параметры «заголовок» и «источник» не могут использоваться при наличии позиционного (безымянного) параметра', '' )
end
if Args['заголовок'] and ( Args[1] or Args['источник'] or Args['первоисточник'] or Args['архив'] or Args['дополнение'] ) then
return tools.errorMsg( 'ссылка', 'Если задан параметр «заголовок», то «источник» и другие параметры для автоматического формирования заголовка не могут использоваться', '' )
end
local out = [[
<div style="width: 100%; max-width: 1000px; background-color: #e8f0e6; margin-bottom: 10px; ">
<div style="display: table; width: 100%; ">
<div style="display: table-caption; background-color: #B9C7B7; padding: 4px; ">]]
.. ( Args['заголовок'] or header( Args ) ) .. [[</div>
<div style="display:table-row; ">
<div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: top; "><i class="fa fa-quote-left fa-3x" style="color:#AEC8A9; "></i></div>
<div style="display: table-cell; padding: 2px; ">
]]
if Args['текст'] then
return out .. Args['текст'] .. endCite()
end
return out
end
local function endCite1()
return [[
<i></i>
</div>
<div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: bottom; "><i class="fa fa-quote-right fa-3x" style="color: #AEC8A9; "></i></div>
</div>
<div style="display: table-row; ">
<div style="display: table-cell; padding: 2px; width: 80px; "></div>
<div style="display: table-cell; padding: 2px; ">
<hr>
<p style="text-align:right; font-size:90%;">]] .. global.get( 'Cite1' ) .. [[</p>
</div>
<div style="display: table-cell; padding: 2px; width: 80px; "></div>
</div>
</div>
</div>
]]
end
p.Cite1 = function ( frame )
local Args, tmp = tools.checkargs( frame:getParent().args,
{ true, ['заголовок'] = true, ['текст'] = true,
['первоисточник'] = true, ['источник'] = true, ['архив'] = true,
['дополнение'] = true, ['сноска'] = true, ['формат'] = true, } )
if not Args then
return tools.errorMsg( 'ссылка', 'Неизвестный параметр «' .. tmp .. '»', '' )
end
if Args[1] == 'конец' then
return endCite1()
end
if Args[1] and ( Args['источник'] or Args['заголовок'] ) then
return tools.errorMsg( 'ссылка', 'Параметры «заголовок» и «источник» не могут использоваться при наличии позиционного (безымянного) параметра', '' )
end
if Args['заголовок'] and ( Args[1] or Args['источник'] or Args['первоисточник'] or Args['архив'] or Args['дополнение'] ) then
return tools.errorMsg( 'ссылка', 'Если задан параметр «заголовок», то «источник» и другие параметры для автоматического формирования заголовка не могут использоваться', '' )
end
global.set( 'Cite1', Args['заголовок'] or header( Args ) )
local style = Args['формат']
if style then
style = '; white-space: ' .. style
end
local out = [[
<div style="width: 100%; max-width: 1000px; background-color: #e8f0e6; margin-bottom: 10px; ">
<div style="display: table; width: 100%; ">
<div style="display: table-row; ">
<div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: top; "><i class="fa fa-quote-left fa-3x" style="color: #AEC8A9; "></i></div>
<div style="display: table-cell; padding: 2px]] .. ( style or '' ) .. [[; ">
]]
if Args['текст'] then
return out .. Args['текст'] .. endCite1()
end
return out
end
return p