Модуль:RefTools — различия между версиями
StasR (обсуждение | вклад) |
StasR (обсуждение | вклад) |
||
(не показано 8 промежуточных версий этого же участника) | |||
Строка 1: | Строка 1: | ||
local refTools = {} | local refTools = {} | ||
− | tools = require( 'Module:Tools' ) | + | local tools = require( 'Module:Tools' ) |
function refTools.makeRef( para, isSource ) | function refTools.makeRef( para, isSource ) | ||
Строка 7: | Строка 7: | ||
local name, content | local name, content | ||
for _, ref in pairs( refs ) do | for _, ref in pairs( refs ) do | ||
− | name, content = mw.ustring.match ( ref, '^/([^/]+)/(.*)$' ) | + | if ref ~= '' then |
− | + | name, content = mw.ustring.match ( ref, '^/([^/]+)/(.*)$' ) | |
− | content = 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 | ||
+ | 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 | else | ||
− | + | big[k] = { v } | |
end | end | ||
− | |||
end | 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