Модуль:DocTools

Материал из Кадровый состав НКВД 1935-1939
Перейти к навигации Перейти к поиску

Для документации этого модуля может быть создана страница Модуль:DocTools/doc

local doctools = {}
local tools = require( 'Module:Tools' )

function doctools.endRecord( args, noRef, refs )
	local refTools = require( 'Module:RefTools' )
	local reference = refs or args['сноска']
	if reference and not noRef then
		reference = refTools.makeRef( reference )
	elseif reference then
		reference = '[[Категория:Сноски в псевдодокументе]]'
	else
		reference = ''
	end
	local comment = args['комментарий']
	local canceledBy = args['отмена']
	if canceledBy then
		if mw.ustring.sub( canceledBy, 1, 9 ) == 'Документ:' then
			canceledBy = mw.ustring.sub( canceledBy, 10, -1 )
		end
		comment = '<b>Отменено:</b> [[Документ:' .. canceledBy .. '|'
			.. canceledBy .. ']]. ' .. (comment or '')
	end
	if comment then
		comment = '<div class="nkvd-doc-comment">'
			.. tools.phrase( comment )  .. '</div>'
	end
	return reference  .. '</p>' .. (comment or '')
end

function doctools.abbr( text, tab )
	if not text then
		return nil
	end

	local u = mw.text.split( text, ' +' )
	local z
	for i, v in ipairs( u ) do
		z = tab[v]
		if z then
			u[i] = z
		end
	end
	return table.concat( u, ' ' )
end

function doctools.parseName ( name )
	local disambig = string.find( name, ' (', 1, true )
	local warn
	if disambig then
		disambig = string.sub( name, disambig+1, -1 )
		name = string.sub( name, 1, disambig-1 )
	end
	name = mw.ustring.gsub( name, '%.%.%.([^%.])', '#\1' )
	name = mw.ustring.gsub( name, '%.%.%.$', '#' )
	if string.match( name .. ' ', '[,#%.][^ ]' ) then
		warn = 'После запятой, точки и многоточия пробелы обязательны!'
		name = mw.ustring.gsub( name, '([,#%.])([^ ])', '%1 %2' )
	end
	name = mw.ustring.gsub( name, '[#%.]', '' )
	local lastN = string.find( name, ', ', 1, true )
	local firstN, middleN
	if lastN then
		lastN, firstN = string.sub( name, 1, lastN-1 ), string.sub( name, lastN+2, -1 )
		middleN = string.find( firstN, ' ', 1, true )
		if middleN then
			firstN, middleN = string.sub( firstN, 1, middleN-1 ), string.sub( firstN, middleN+1, -1 )
		else
			middleN = ''
		end
	else
		lastN = name
		firstN, middleN = '', ''
	end
	return lastN, firstN, middleN, disambig, warn
end





return doctools