Skip to content

Commit d83fec6

Browse files
authored
flesh out docs site (#108)
1 parent 5279400 commit d83fec6

File tree

4 files changed

+129
-31
lines changed

4 files changed

+129
-31
lines changed

build.gradle.kts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import com.vanniktech.maven.publish.SonatypeHost
44
import fr.brouillard.oss.jgitver.Strategies
5-
import kotlin.time.Duration.Companion.seconds
6-
import kotlin.time.toJavaDuration
75
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
8-
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl
6+
import ru.vyarus.gradle.plugin.mkdocs.task.MkdocsTask
97

108
plugins {
119
alias(libs.plugins.kotlin.multiplatform)
@@ -34,27 +32,14 @@ kotlin {
3432

3533
jvm()
3634

37-
fun KotlinJsSubTargetDsl.configureWithKarma() {
38-
testTask {
39-
useKarma {
40-
useChromeHeadless()
41-
timeout = 60.seconds.toJavaDuration()
42-
}
43-
}
44-
}
45-
46-
fun KotlinJsSubTargetDsl.configureWithMocha() {
47-
testTask { useMocha { timeout = "60s" } }
48-
}
49-
5035
js(IR) {
51-
browser { configureWithMocha() }
52-
nodejs { configureWithMocha() }
36+
browser()
37+
nodejs()
5338
}
5439

5540
wasmJs {
56-
browser { configureWithMocha() }
57-
nodejs { configureWithMocha() }
41+
browser()
42+
nodejs()
5843
d8 {}
5944
}
6045

@@ -77,6 +62,7 @@ kotlin {
7762
tvosArm64()
7863

7964
// native tier 3
65+
// android native platforms aren't supported due to lack of Ktor support
8066
mingwX64()
8167
watchosDeviceArm64()
8268

@@ -159,9 +145,10 @@ dokka {
159145
remoteUrl("https://github.com/PokeAPI/pokekotlin/tree/${project.ext["base_tag"]}/")
160146
localDirectory.set(rootDir)
161147
}
162-
externalDocumentationLinks {
163-
// TODO
164-
}
148+
externalDocumentationLinks { create("ktor") { url("https://api.ktor.io/") } }
149+
suppressedFiles.from(
150+
"build/generated/ksp/metadata/commonMain/kotlin/dev/sargunv/pokekotlin/_PokeApiImpl.kt"
151+
)
165152
}
166153
}
167154
}
@@ -174,6 +161,12 @@ mkdocs {
174161
}
175162
}
176163

164+
tasks.withType<MkdocsTask>().configureEach {
165+
val releaseVersion = ext["base_tag"].toString().replace("v", "")
166+
val snapshotVersion = "${ext["next_patch_version"]}-SNAPSHOT"
167+
extras.set(mapOf("release_version" to releaseVersion, "snapshot_version" to snapshotVersion))
168+
}
169+
177170
tasks.register("generateDocs") {
178171
dependsOn("dokkaGenerate", "mkdocsBuild")
179172
doLast {

docs/docs/index.md

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,98 @@
11
# Overview
22

3-
PokeKotlin is a [Kotlin](https://kotlinlang.org/) client for
4-
[PokeApi](https://github.com/PokeAPI/pokeapi).
3+
## Introduction
54

6-
Documentation is under construction. For now, see the
7-
[API Reference](./api/index.html).
5+
PokeKotlin is a modern [Kotlin Multiplatform] client for [PokéAPI]. You can use
6+
it to integrate all sorts of Pokémon data into your Kotlin projects.
7+
8+
Under the hood, it's built on [Ktor], [Kotlin Serialization], and coroutines.
9+
10+
## Supported platforms
11+
12+
- Kotlin/JVM, including Android
13+
- Kotlin/JS for browser and Node
14+
- Kotlin/WASM for browser and Node
15+
- Kotlin/Native for Linux, Windows, macOS, iOS, tvOS, and watchOS
16+
17+
## Installation
18+
19+
This library is published via [Maven Central], and snapshot builds of `main` are
20+
additionally available on [GitHub Packages].
21+
22+
=== "Releases (Maven Central)"
23+
24+
The latest release is **v{{ gradle.release_version }}**. In your Gradle version catalog, add:
25+
26+
```toml title="libs.versions.toml"
27+
[libraries]
28+
pokekotlin = { module = "dev.sargunv.pokekotlin:pokekotlin", version = "{{ gradle.release_version }}" }
29+
```
30+
31+
=== "Snapshots (GitHub Packages)"
32+
33+
!!! warning
34+
35+
The published documentation is for the latest release, and may not match the snapshot
36+
version. If using snapshots, always refer to the [latest source code][repo] for the most
37+
accurate information.
38+
39+
First, follow [GitHub's guide][gh-packages-guide] for authenticating to GitHub Packages. Your
40+
settings.gradle.kts should have something like this:
41+
42+
```kotlin title="settings.gradle.kts"
43+
repositories {
44+
maven {
45+
url = uri("https://maven.pkg.github.com/pokeapi/pokekotlin")
46+
credentials {
47+
username = project.findProperty("gpr.user") as String? ?: System.getenv("GH_USERNAME")
48+
password = project.findProperty("gpr.key") as String? ?: System.getenv("GH_TOKEN")
49+
}
50+
}
51+
}
52+
```
53+
54+
The latest snapshot is **v{{ gradle.snapshot_version }}**. In your Gradle version catalog, add:
55+
56+
```toml title="libs.versions.toml"
57+
[libraries]
58+
pokekotlin = { module = "dev.sargunv.pokekotlin:pokekotlin", version = "{{ gradle.snapshot_version }}" }
59+
```
60+
61+
In your Gradle build script, add:
62+
63+
```kotlin title="build.gradle.kts"
64+
commonMain.dependencies {
65+
implementation(libs.maplibre.compose)
66+
}
67+
```
68+
69+
## Usage
70+
71+
For basic usage, use the global `PokeApi` instance:
72+
73+
```kotlin
74+
-8<- "src/commonTest/kotlin/dev/sargunv/pokekotlin/example/example.kt:simple"
75+
```
76+
77+
By default, the client will connect to the official `https://pokeapi.co/`
78+
instance and cache results in memory.
79+
80+
If you want to customize the client, create a custom instance of the client:
81+
82+
```kotlin
83+
-8<- "src/commonTest/kotlin/dev/sargunv/pokekotlin/example/example.kt:custom"
84+
```
85+
86+
For further details, see the Dokka [API Reference](./api).
87+
88+
[Kotlin Multiplatform]: https://kotlinlang.org/docs/multiplatform.html
89+
[PokéAPI]: https://pokeapi.co/
90+
[Maven Central]: https://central.sonatype.com/namespace/dev.sargunv.pokekotlin
91+
[GitHub Packages]:
92+
https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry
93+
[gh-packages-guide]:
94+
https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#using-a-published-package
95+
[repo]: https://github.com/pokeapi/pokekotlin
96+
[Ktor]: https://ktor.io/
97+
[Kotlin Serialization]: https://github.com/Kotlin/kotlinx.serialization
98+
[coroutines]: https://kotlinlang.org/docs/coroutines-guide.html

src/commonMain/kotlin/dev/sargunv/pokekotlin/PokeApi.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@file:JvmName("PokeApiClient")
2-
31
package dev.sargunv.pokekotlin
42

53
import de.jensklingenberg.ktorfit.Ktorfit.Builder
@@ -68,7 +66,6 @@ import io.ktor.client.plugins.cache.storage.CacheStorage
6866
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
6967
import io.ktor.http.ContentType
7068
import io.ktor.serialization.kotlinx.json.json
71-
import kotlin.jvm.JvmName
7269

7370
interface PokeApi {
7471

@@ -563,7 +560,6 @@ interface PokeApi {
563560
companion object : PokeApi by PokeApi()
564561
}
565562

566-
@JvmName("create")
567563
fun PokeApi(
568564
baseUrl: String = "https://pokeapi.co/api/v2/",
569565
engine: HttpClientEngine = getDefaultEngine(),
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package dev.sargunv.pokekotlin.example
2+
3+
import dev.sargunv.pokekotlin.PokeApi
4+
5+
suspend fun simple() {
6+
// -8<- [start:simple]
7+
val bulbasaur = PokeApi.getPokemon(1)
8+
println(bulbasaur)
9+
// -8<- [end:simple]
10+
}
11+
12+
suspend fun custom() {
13+
// -8<- [start:custom]
14+
val client = PokeApi(baseUrl = "https://localhost:8080")
15+
val bulbasaur = client.getPokemon(1)
16+
println(bulbasaur)
17+
// -8<- [end:custom]
18+
}

0 commit comments

Comments
 (0)