테스트 페이지(Testing page) — Kotlin 문서 플랫폼 기능 데모
테스트 페이지(Testing page) — Kotlin 문서 플랫폼 기능 데모
이 페이지는 Kotlin 공식 문서 사이트의 문서 플랫폼 기능(탭, 접이식 섹션, 코드 블록, 표, 목록, 노트, 변수 등)을 테스트·시연하기 위한 페이지예요. 실제 사이트에서는 /docs/test-page.html 경로가 404를 반환하지만, 원본 소스는 kotlin-web-site 저장소에 존재해요. 목적 자체가 "테스트 전용"이므로 각 기능이 어떤 식으로 렌더링되는지 살펴보는 용도로 읽어주시면 돼요.
출처: Testing page
본문
요약: 이 페이지는 테스트 목적으로만 사용되는 페이지예요.
동기화된 탭(Synchronized tabs)
첫 번째 탭 그룹(Kotlin/Groovy):
plugins {
kotlin("kapt") version "1.9.23"
}
plugins {
id "org.jetbrains.kotlin.kapt" version "1.9.23"
}
두 번째 탭 그룹(Kotlin/Groovy):
plugins {
kotlin("plugin.noarg") version "1.9.23"
}
plugins {
id "org.jetbrains.kotlin.plugin.noarg" version "1.9.23"
}
섹션(Sections)
접힌 섹션(Collapsed section)
여기 텍스트와 코드 블록이 있어요:
plugins {
kotlin("plugin.noarg") version "1.9.23"
}
코드 블록(Codeblocks)
그냥 코드 블록 하나:
import java.util.*
@Service
class MessageService(val db: MessageRepository) {
fun findMessages(): List<Message> = db.findAll().toList()
fun findMessageById(id: String): List<Message> = db.findById(id).toList()
fun save(message: Message) {
db.save(message)
}
fun <T : Any> Optional<out T>.toList(): List<T> =
if (isPresent) listOf(get()) else emptyList()
}
펼칠 수 있는 코드 블록(Expandable codeblock)
package com.example.demo
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@SpringBootApplication
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@RestController
class MessageController {
@GetMapping("/")
fun index(@RequestParam("name") name: String) = "Hello, $name!"
}
실행 가능한 코드 블록(Runnable codeblock)
data class User(val name: String, val id: Int)
fun main() {
val user = User("Alex", 1)
//sampleStart
// Automatically uses toString() function so that output is easy to read
println(user)
// User(name=Alex, id=1)
//sampleEnd
}
표(Tables)
Markdown 표(Markdown table)
| Primitive-type array | Java에서의 동등형 |
|---|---|
BooleanArray |
boolean[] |
ByteArray |
byte[] |
CharArray |
char[] |
DoubleArray |
double[] |
FloatArray |
float[] |
IntArray |
int[] |
LongArray |
long[] |
ShortArray |
short[] |
XML 표(XML table)
| 마지막 수정일 | 2023년 12월 |
|---|---|
| 다음 업데이트 | 2024년 6월 |
코드 블록이 들어간 XML 표(XML table with codeblocks inside)
간단한 표:
| Before | Now |
|---|---|
kotlin<br>kotlin {<br> targets {<br> configure(['windows',<br> 'linux']) {<br> }<br> }<br>}<br> |
kotlin<br>kotlin {<br> targets {<br> configure([findByName('windows'),<br> findByName('linux')]) {<br> }<br> }<br>}<br> |
더 복잡한 표:
| Before | Now | |
|---|---|---|
jvmMain 컴파일의 의존성 |
kotlin<br>jvm<Scope><br> |
kotlin<br>jvmCompilation<Scope><br> |
kotlin<br>dependencies {<br> add("jvmImplementation",<br> "foo.bar.baz:1.2.3")<br>}<br> |
kotlin<br>dependencies {<br> add("jvmCompilationImplementation",<br> "foo.bar.baz:1.2.3")<br>}<br> |
|
jvmMain 소스 세트의 의존성 |
kotlin<br>jvmMain<Scope><br> |
|
jvmTest 컴파일의 의존성 |
kotlin<br>jvmTest<Scope><br> |
kotlin<br>jvmTestCompilation<Scope><br> |
jvmTest 소스 세트의 의존성 |
kotlin<br>jvmTest<Scope><br> |
목록(Lists)
순서 있는 목록(Ordered list)
-
하나(One)
-
둘(Two)
-
셋(Three)
- 셋의 1번(Three point 1)
- 셋의 2번(Three point 2)
- 셋의 3번(Three point 3)
- 셋의 1번과 1(Three point 1 and 1)
-
코드 블록이 들어 있는 항목:
jvmTest<Scope>
순서 없는 목록(Non-ordered list)
-
첫 번째 불릿(First bullet)
-
두 번째 불릿(Second bullet)
-
세 번째 불릿(Third bullet)
- 하나 더(One more)
- 또 하나(Another one)
- 와, 하나 더(Wow, one more)
-
코드 블록이 들어 있는 항목:
jvmTest<Scope>
정의 목록(Definition list)
- 접이식 항목 #1(Collapsible item #1):
CrudRepository인터페이스에서findById()함수의 반환 타입은Optional클래스의 인스턴스예요. 하지만 일관성을 위해 단일 메시지를 담은List를 반환하는 것이 더 편리할 거예요. 그러려면Optional값이 존재할 때 그 값을 풀어(unwrap) 값이 담긴 목록을 반환해야 해요. 이는Optional타입에 대한 확장 함수(extension function)로 구현할 수 있어요. 코드에서Optional<out T>.toList(), 즉.toList()는Optional에 대한 확장 함수예요. 확장 함수를 사용하면 어떤 클래스에든 추가 함수를 작성할 수 있는데, 일부 라이브러리 클래스의 기능을 확장하고 싶을 때 특히 유용해요. - 접이식 항목 #2(Collapsible item #2): 이 함수는 새 객체가 데이터베이스에 id가 없다는 가정하에 동작해요. 따라서 삽입(insert)을 위해서는 id가 null이어야 해요.
만약 id가 null이 아니라면,
CrudRepository는 객체가 이미 데이터베이스에 존재한다고 가정하고 이것을 *삽입(insert)*이 아닌 업데이트(update) 연산으로 간주해요. 삽입 연산이 끝나면id는 데이터 저장소에 의해 생성되어Message인스턴스에 다시 할당돼요. 그래서id프로퍼티는var키워드로 선언해야 해요.
텍스트 요소(Text elements)
- 굵은 텍스트(Bold text)
- 이탤릭 텍스트(italic text)
인라인 코드(inline code)- 내부 앵커(internal anchor)
- 내부 링크(internal link)
- 외부 링크(external link)
- 이모지 ❌✅🆕
변수(Variables)
- 변수 사용: 최신 Kotlin 버전은 %kotlinVersion%이에요.
임베디드 요소(Embedded elements)
YouTube 동영상(Video from YouTube)
그림(Pictures)
일반(Markdown):
{width="700"}
일반(XML):
{width="400"}
인라인(Inline):
{width=30}{type="joined"}
확대 가능(Zoomable):
{thumbnail="true" width="700" thumbnail-same-file="true"}
버튼 스타일(Button-style):
노트(Notes)
경고(Warning):
kapt 컴파일러 플러그인의 K2 지원은 Experimental 상태예요. 옵트인이 필요하며(자세한 내용은 아래 참고), 평가 목적으로만 사용해야 해요.
참고(Note):
Kotlin/Native와 함께 제공되는 네이티브 플랫폼 라이브러리(Foundation, UIKit, POSIX 등)의 경우, 그 API 중 일부만
@ExperimentalForeignApi로 옵트인이 필요해요. 그런 경우 옵트인 요구 사항과 함께 경고가 표시돼요.
팁(Tip):
Kotlin/Native와 함께 제공되는 네이티브 플랫폼 라이브러리(Foundation, UIKit, POSIX 등)의 경우, 그 API 중 일부만
@ExperimentalForeignApi로 옵트인이 필요해요. 그런 경우 옵트인 요구 사항과 함께 경고가 표시돼요.
더 알아보기
이 페이지는 테스트 전용으로, 실제 사이트에서는 404를 반환해요. 데모가 아닌 실질적인 Kotlin 문서는 Kotlin 문서 홈에서 확인해 주세요.
{style="block"}