Модуль:DeptCard

Версия от 12:04, 16 мая 2026; M 9SCO (обсуждение | вклад) (Новая страница: «-- Module:DeptCard -- Generates department card HTML for main page grid. -- Usage: {{#invoke:DeptCard|card|dept=sec|tag=SEC|title=...|...}} local p = {} local function splitLines( s ) local result = {} for line in s:gmatch( '[^\n]+' ) do local trimmed = mw.text.trim( line ) if trimmed ~= '' then result[#result + 1] = trimmed end end return result end function p.card( frame ) local args = frame.args if not args.dept and not args.title then...»)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)

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

-- Module:DeptCard
-- Generates department card HTML for main page grid.
-- Usage: {{#invoke:DeptCard|card|dept=sec|tag=SEC|title=...|...}}

local p = {}

local function splitLines( s )
	local result = {}
	for line in s:gmatch( '[^\n]+' ) do
		local trimmed = mw.text.trim( line )
		if trimmed ~= '' then
			result[#result + 1] = trimmed
		end
	end
	return result
end

function p.card( frame )
	local args = frame.args
	if not args.dept and not args.title then
		args = frame:getParent().args
	end

	local dept = args.dept or 'sec'
	local tag = args.tag or ''
	local title = args.title or ''
	local roles = args.roles or ''
	local articles = args.articles or ''
	local updated = args.updated or ''

	-- Card click destination (separate from visible links)
	local href = mw.text.trim( args.href or '' )
	local hrefAttr = ''
	if href ~= '' then
		local t = mw.title.new( href )
		if t then
			hrefAttr = ' data-href="' .. t:localUrl() .. '"'
		end
	end

	-- Dynamic links: multiline link/link-text paired by index
	local links = splitLines( args.link or '' )
	local texts = splitLines( args['link-text'] or '' )
	local linksHtml = ''
	for i = 1, #links do
		local page = links[i]
		local text = texts[i] or page
		linksHtml = linksHtml .. '[[' .. page .. '|' .. text .. ']]'
	end

	local out = '<div class="ss-mp-dept-card ss-dept-' .. mw.text.trim( dept )
		.. ' ss-mp-clickcard"' .. hrefAttr .. '>'
		.. '<span class="ss-mp-dept-tag">' .. mw.text.nowiki( tag ) .. '</span>'
		.. '<div class="ss-mp-dept-card-title">' .. mw.text.nowiki( title ) .. '</div>'
		.. '<div class="ss-mp-dept-roles">' .. mw.text.nowiki( roles ) .. '</div>'
		.. '<div class="ss-mp-dept-links">' .. linksHtml .. '</div>'
		.. '<div class="ss-mp-dept-foot"><span>' .. mw.text.nowiki( articles )
		.. '</span><span>' .. mw.text.nowiki( updated ) .. '</span></div>'
		.. '</div>'

	return out
end

return p