메뉴 여닫기
436
320
90
23K
이터널 리턴 이스포츠 위키
환경 설정 메뉴 여닫기
개인 메뉴 여닫기
로그인하지 않음
지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

이 모듈에 대한 설명문서는 모듈:InfoboxNeue/설명문서에서 만들 수 있습니다

-- Module:InfoboxNeue
-- bori.wiki 적응 버전 (원본: Star Citizen Wiki)
-- 의존성 간소화: FloatingUI, i18n 제거

local InfoboxNeue = {}

local metatable = {}
local methodtable = {}

local libraryUtil = require( 'libraryUtil' )
local checkType = libraryUtil.checkType
local checkTypeMulti = libraryUtil.checkTypeMulti

metatable.__index = methodtable

metatable.__tostring = function( self )
	return tostring( self:renderInfobox() )
end

--- 쉼표 구분 테이블→문자열
function methodtable.tableToCommaList( data )
	if type( data ) == 'table' then
		return table.concat( data, ', ' )
	end
	return data
end

--- 두 값이 다르면 범위 표시
function methodtable.formatRange( s1, s2 )
	if s1 == nil and s2 == nil then return end
	if s1 and s2 and s1 ~= s2 then
		return s1 .. ' – ' .. s2
	end
	return s1 or s2
end

--- 값이 있으면 단위 추가
function methodtable.addUnitIfExists( s, unit )
	if s == nil then return end
	return s .. ' ' .. unit
end

--- 이미지 렌더링
function methodtable.renderImage( self, filename )
	checkType( 'Module:InfoboxNeue.renderImage', 1, self, 'table' )

	if type( filename ) ~= 'string' or filename == '' then
		return ''
	end

	-- "파일:" 접두사 제거
	local parts = mw.text.split( filename, ':', true )
	if #parts > 1 then
		table.remove( parts, 1 )
		filename = table.concat( parts, ':' )
	end

	local html = mw.html.create( 'div' )
		:addClass( 'infobox__image' )
		:wikitext( string.format( '[[File:%s|400px]]', filename ) )

	local item = tostring( html )
	table.insert( self.entries, item )
	return item
end

--- 인디케이터 (상태 뱃지)
function methodtable.renderIndicator( self, data )
	checkType( 'Module:InfoboxNeue.renderIndicator', 1, self, 'table' )
	checkType( 'Module:InfoboxNeue.renderIndicator', 2, data, 'table' )

	if data == nil or data['data'] == nil or data['data'] == '' then return '' end

	local html = mw.html.create( 'div' ):addClass( 'infobox__indicators' )
	local classes = { 'infobox__indicator' }

	if data['class'] then table.insert( classes, data['class'] ) end
	if data['color'] then table.insert( classes, 'infobox__indicator--' .. data['color'] ) end

	html:wikitext(
		self:renderItem( {
			data = data['data'],
			class = table.concat( classes, ' ' ),
			row = true,
			spacebetween = true
		} )
	)

	local item = tostring( html )
	table.insert( self.entries, item )
	return item
end

--- 헤더 (타이틀 + 서브타이틀)
function methodtable.renderHeader( self, data )
	checkType( 'Module:InfoboxNeue.renderHeader', 1, self, 'table' )
	checkTypeMulti( 'Module:InfoboxNeue.renderHeader', 2, data, { 'table', 'string' } )

	if type( data ) == 'string' then
		data = { title = data }
	end

	if data == nil or data['title'] == nil then return '' end

	local html = mw.html.create( 'div' ):addClass( 'infobox__header' )

	if data['badge'] then
		html:tag( 'div' )
			:addClass( 'infobox__item infobox__badge' )
			:wikitext( data['badge'] )
	end

	local titleItem = mw.html.create( 'div' ):addClass( 'infobox__item' )
	titleItem:tag( 'div' )
		:addClass( 'infobox__title' )
		:wikitext( data['title'] )

	if data['subtitle'] then
		titleItem:tag( 'div' )
			:addClass( 'infobox__subtitle infobox__data' )
			:wikitext( data['subtitle'] )
	end

	html:node( titleItem )

	local item = tostring( html )
	table.insert( self.entries, item )
	return item
end

--- 섹션 래퍼
function methodtable.renderSection( self, data, noInsert )
	checkType( 'Module:InfoboxNeue.renderSection', 1, self, 'table' )
	checkType( 'Module:InfoboxNeue.renderSection', 2, data, 'table' )

	noInsert = noInsert or false

	if type( data.content ) == 'table' then
		data.content = table.concat( data.content )
	end

	if data == nil or data['content'] == nil or data['content'] == '' then return '' end

	local html = mw.html.create( 'div' ):addClass( 'infobox__section' )

	if data['title'] then
		local header = html:tag( 'div' ):addClass( 'infobox__sectionHeader' )
		header:tag( 'div' )
			:addClass( 'infobox__sectionTitle' )
			:wikitext( data['title'] )
		if data['subtitle'] then
			header:tag( 'div' )
				:addClass( 'infobox__sectionSubtitle' )
				:wikitext( data['subtitle'] )
		end
	end

	local content = html:tag( 'div' )
	content:addClass( 'infobox__sectionContent' )
		:wikitext( data['content'] )

	if data['border'] == false then html:addClass( 'infobox__section--noborder' ) end
	if data['col'] then content:addClass( 'infobox__grid--cols-' .. data['col'] ) end
	if data['class'] then html:addClass( data['class'] ) end

	local item = tostring( html )

	if not noInsert then
		table.insert( self.entries, item )
	end

	return item
end

--- 아이템 (label + data + desc)
function methodtable.renderItem( self, data, content )
	checkType( 'Module:InfoboxNeue.renderItem', 1, self, 'table' )
	checkTypeMulti( 'Module:InfoboxNeue.renderItem', 2, data, { 'table', 'string' } )
	checkTypeMulti( 'Module:InfoboxNeue.renderItem', 3, content, { 'string', 'number', 'nil' } )

	-- 간편 파라미터: renderItem("라벨", "데이터")
	if content ~= nil then
		data = { label = data, data = content }
	end

	if data == nil or data.data == nil or data.data == '' then return '' end

	local html = mw.html.create( 'div' ):addClass( 'infobox__item' )

	if data.class then html:addClass( data.class ) end
	if data.row == true then html:addClass( 'infobox__grid--row' ) end
	if data.spacebetween == true then html:addClass( 'infobox__grid--space-between' ) end
	if data.colspan then html:addClass( 'infobox__grid--col-span-' .. data.colspan ) end

	-- 텍스트 요소 렌더링
	local dataOrder = { 'label', 'data', 'desc' }
	for _, key in ipairs( dataOrder ) do
		if data[key] then
			if type( data[key] ) == 'table' then
				data[key] = table.concat( data[key], ', ' )
			end
			html:tag( 'div' )
				:addClass( 'infobox__' .. key )
				:wikitext( data[key] )
		end
	end

	return tostring( html )
end

--- 링크 버튼
function methodtable.renderLinkButton( self, data )
	checkType( 'Module:InfoboxNeue.renderLinkButton', 1, self, 'table' )
	checkType( 'Module:InfoboxNeue.renderLinkButton', 2, data, 'table' )

	if data == nil or data['label'] == nil or (data['link'] == nil and data['page'] == nil) then return '' end

	local html = mw.html.create( 'div' ):addClass( 'infobox__linkButton' )

	if data['link'] then
		html:wikitext( string.format( '[%s %s]', data['link'], data['label'] ) )
	elseif data['page'] then
		html:wikitext( string.format( '[[%s|%s]]', data['page'], data['label'] ) )
	end

	return tostring( html )
end

--- 푸터
function methodtable.renderFooter( self, data )
	checkType( 'Module:InfoboxNeue.renderFooter', 1, self, 'table' )
	checkType( 'Module:InfoboxNeue.renderFooter', 2, data, 'table' )

	if data == nil then return '' end

	local html = mw.html.create( 'div' ):addClass( 'infobox__footer' )

	if data['content'] then
		html:addClass( 'infobox__footer--has-content' )
		html:tag( 'div' )
			:addClass( 'infobox__section' )
			:wikitext( type( data['content'] ) == 'table' and table.concat( data['content'] ) or data['content'] )
	end

	local item = tostring( html )
	table.insert( self.entries, item )
	return item
end

--- 인포박스 최종 렌더링
function methodtable.renderInfobox( self, innerHtml, snippetText )
	checkType( 'Module:InfoboxNeue.renderInfobox', 1, self, 'table' )

	if type( innerHtml ) ~= 'string' then
		innerHtml = table.concat( self.entries )
	end

	if snippetText == nil then
		snippetText = mw.title.getCurrentTitle().text
	end

	local frame = mw.getCurrentFrame()

	-- 콘텐츠
	local content = mw.html.create( 'div' )
		:addClass( 'infobox__content' )
		:wikitext( innerHtml )

	-- 스니펫 (접힌 상태 요약)
	local snippet = mw.html.create()
	snippet:tag( 'div' )
		:addClass( 'infobox__data' )
		:wikitext( '요약:' )
		:done()
		:tag( 'div' )
		:addClass( 'infobox__desc' )
		:wikitext( snippetText )

	-- <details> + <summary> 조합
	local summary = frame:extensionTag {
		name = 'summary',
		content = tostring( snippet ),
		args = { class = 'infobox__snippet' }
	}
	local details = frame:extensionTag {
		name = 'details',
		content = summary .. tostring( content ),
		args = { class = 'infobox floatright', open = true }
	}

	-- TemplateStyles 로드
	local styles = frame:extensionTag {
		name = 'templatestyles',
		args = { src = 'Module:InfoboxNeue/styles.css' }
	}

	return styles .. details
end

--- 새 인스턴스 생성
function InfoboxNeue.new( self, config )
	local instance = {
		config = config or {},
		entries = {},
	}

	setmetatable( instance, metatable )
	return instance
end

return InfoboxNeue