Модуль:RefTools — различия между версиями
StasR (обсуждение | вклад) |
StasR (обсуждение | вклад) |
||
(не показано 6 промежуточных версий этого же участника) | |||
Строка 12: | Строка 12: | ||
content = ref | content = ref | ||
end | end | ||
− | + | ||
if isSource then | if isSource then | ||
− | content = 'Источник: <cite>' .. content .. '</cite>' | + | if content ~= '' then |
+ | content = 'Источник: <cite>' .. content .. '</cite>' | ||
+ | end | ||
else | else | ||
content = tools.phrase( content ) | content = tools.phrase( content ) | ||
end | end | ||
− | result = result .. mw.getCurrentFrame():extensionTag( 'ref', content, name ) | + | result = result .. mw.getCurrentFrame():extensionTag( 'ref', content , { name = name } ) -- .. ' [' .. (name or '—').. ']' |
end | end | ||
end | end | ||
return result | return result | ||
end | end | ||
+ | |||
+ | local refNames = { 'должность', 'звание', 'должность+', 'звание+', 'награда' } | ||
+ | |||
+ | function refTools.collect( args, prefix ) | ||
+ | local refs = {} | ||
+ | refs.common = args[prefix] | ||
+ | for _, i in ipairs( refNames ) do | ||
+ | refs[i] = args[prefix .. '/' .. i] | ||
+ | end | ||
+ | return refs | ||
+ | end | ||
+ | |||
+ | function refTools.absorb( big, elems ) | ||
+ | for k, v in pairs( elems or {} ) do | ||
+ | local m = big[k] | ||
+ | if m then | ||
+ | m[#m+1] = v | ||
+ | else | ||
+ | big[k] = { v } | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function refTools.toline( refs ) | ||
+ | local str = '' | ||
+ | for _, v in pairs( refs ) do | ||
+ | str = str .. '¶' .. v | ||
+ | end | ||
+ | return mw.ustring.sub( str, 2, -1 ) | ||
+ | end | ||
+ | |||
+ | |||
return refTools | return refTools |
Версия 22:09, 7 февраля 2017
Для документации этого модуля может быть создана страница Модуль:RefTools/doc
local refTools = {}
local tools = require( 'Module:Tools' )
function refTools.makeRef( para, isSource )
local refs = mw.text.split( para or '', '¶' )
local result = ''
local name, content
for _, ref in pairs( refs ) do
if ref ~= '' then
name, content = mw.ustring.match ( ref, '^/([^/]+)/(.*)$' )
if not name then
content = ref
end
if isSource then
if content ~= '' then
content = 'Источник: <cite>' .. content .. '</cite>'
end
else
content = tools.phrase( content )
end
result = result .. mw.getCurrentFrame():extensionTag( 'ref', content , { name = name } ) -- .. ' [' .. (name or '—').. ']'
end
end
return result
end
local refNames = { 'должность', 'звание', 'должность+', 'звание+', 'награда' }
function refTools.collect( args, prefix )
local refs = {}
refs.common = args[prefix]
for _, i in ipairs( refNames ) do
refs[i] = args[prefix .. '/' .. i]
end
return refs
end
function refTools.absorb( big, elems )
for k, v in pairs( elems or {} ) do
local m = big[k]
if m then
m[#m+1] = v
else
big[k] = { v }
end
end
end
function refTools.toline( refs )
local str = ''
for _, v in pairs( refs ) do
str = str .. '¶' .. v
end
return mw.ustring.sub( str, 2, -1 )
end
return refTools