Модуль:LawLink

From in.wiki
Jump to navigation Jump to search

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

local p = {}

function p.LL(frame)
	local params = frame:getParent().args
	local configs = frame.args
	local before, article, after, label = mw.text.trim(params[1] or ''), mw.text.trim(params[2] or ''), 
		mw.text.trim(params[3] or ''), mw.text.trim(params[4] or '')
	local mode
	local res = ''
	if article == '' or article == '+' or article == '+.' or article == '.' or article == '!' then -- link to whole doc
		if before == '!' then -- exclamation mark into second position (article)
			before, article = article, before
		end	
		if article ~= '!' then
			res = '[[' .. configs['ссылка'] .. '|'
		end
		if before == '+' then
			res = res .. configs['род']
		elseif before == '+.' then
			res = res .. ( configs['род.'] or configs['род'] )
		elseif before == '' then
			res = res .. configs['им']
		elseif before == '.' then
			res = res .. ( configs['им.'] or configs['им'] )
		else
			res = res .. before
		end
		if article ~= '!' then
			res = res .. ']]'
		end
	else
		if label ~= '!' then
			res = '[[' .. configs['ссылка'] .. ':'
			local x = mw.ustring.sub(article,1,1)
			if x >= '0' and x <= '9' then
				res = res .. (configs['статья'] or 'Статья ')
			end
			res = res .. article
			if label ~= '' then
				res = res .. '#' .. label
			end
			res = res .. '|'
		end
		local resar = {}
		if before ~= '!' then
			if before ~= '' then
				table.insert(resar, before)
			end
			table.insert(resar, article)
		end
		if after == '+' then
			table.insert(resar, configs['род'])
		elseif after == '.' or after == '+.'  then
			table.insert(resar, configs['род.'] or configs['род'])
		elseif after ~= '' then
			table.insert(resar, after)
		end
		res = res .. table.concat(resar, ' ')
		if label ~= '!' then
			res = res .. ']]'
		end
	end
	
	return res		
end

return p