Skip to content

Commit bcfd10b

Browse files
authored
Merge pull request #81 from modelix/feat/dokka-setup
MODELIX-429: Automatic API reference generation
2 parents f177e27 + 1ceb511 commit bcfd10b

File tree

5 files changed

+212
-0
lines changed

5 files changed

+212
-0
lines changed

.github/workflows/docs.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build and Publish Docs
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.0' # New Major or Minor Releases
7+
jobs:
8+
docs:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout Project
12+
uses: actions/checkout@v3
13+
- name: Set up JDK 11
14+
uses: actions/setup-java@v3
15+
with:
16+
distribution: 'temurin'
17+
java-version: '11'
18+
- name: Use tag as version
19+
run: echo "${GITHUB_REF#refs/*/}" > version.txt
20+
- name: Generate Docs with Dokka
21+
run: ./gradlew dokkaHtmlMultiModule
22+
- name: Publish to GitHub Pages
23+
uses: peaceiris/actions-gh-pages@v3
24+
with:
25+
github_token: ${{ secrets.GITHUB_TOKEN }}
26+
publish_dir: build/dokka
27+
keep_files: true

build.gradle.kts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import kotlinx.html.*
2+
import kotlinx.html.stream.createHTML
3+
import org.jetbrains.dokka.base.DokkaBase
4+
import org.jetbrains.dokka.base.DokkaBaseConfiguration
5+
6+
buildscript {
7+
dependencies {
8+
classpath("org.jetbrains.dokka:versioning-plugin:1.8.10")
9+
}
10+
}
11+
112
plugins {
213
kotlin("multiplatform") apply false
314
kotlin("plugin.serialization") apply false
@@ -6,6 +17,13 @@ plugins {
617
id("org.jlleitschuh.gradle.ktlint") version "10.3.0" apply false
718
id("com.diffplug.spotless") version "5.0.0" apply false
819
id("com.dorongold.task-tree") version "2.1.0"
20+
id("org.jetbrains.dokka") version "1.8.10"
21+
}
22+
23+
repositories {
24+
mavenLocal()
25+
maven { url = uri("https://artifacts.itemis.cloud/repository/maven-mps/") }
26+
mavenCentral()
927
}
1028

1129
group = "org.modelix"
@@ -23,8 +41,13 @@ fun computeVersion(): Any {
2341
}
2442
}
2543

44+
dependencies {
45+
dokkaPlugin("org.jetbrains.dokka:versioning-plugin:1.8.10")
46+
}
47+
2648
subprojects {
2749
apply(plugin = "maven-publish")
50+
apply(plugin = "org.jetbrains.dokka")
2851
version = rootProject.version
2952
group = rootProject.group
3053

@@ -88,3 +111,122 @@ subprojects {
88111
tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask> {
89112
dependsOn(":ts-model-api:npm_run_build")
90113
}
114+
val docsDir = buildDir.resolve("dokka")
115+
116+
tasks.dokkaHtmlMultiModule {
117+
outputDirectory.set(docsDir.resolve("$version"))
118+
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
119+
customAssets += file(projectDir.resolve("dokka/logo-dark.svg"))
120+
customStyleSheets += file(projectDir.resolve("dokka/logo-styles.css"))
121+
footerMessage = createFooterMessage()
122+
}
123+
doLast {
124+
val index = file(docsDir.resolve("index.html"))
125+
index.writeText(createDocsIndexPage(), Charsets.ISO_8859_1)
126+
}
127+
}
128+
129+
fun createFooterMessage(): String {
130+
return createHTML().span {
131+
createFooter()
132+
}
133+
}
134+
135+
fun FlowContent.createFooter() {
136+
p {
137+
+"For more information visit "
138+
a("https://modelix.org") { +"modelix.org" }
139+
+", for further documentation visit "
140+
a("https://docs.modelix.org") { +"docs.modelix.org" }
141+
+"."
142+
}
143+
p {
144+
+"Copyright \u00A9 2021-present by the "
145+
a("https://modelix.org") { +"modelix open source project" }
146+
+" and the individual contributors. All Rights reserved."
147+
}
148+
p {
149+
+"Except where otherwise noted, "
150+
a("https://api.modelix.org") {+"api.modelix.org"}
151+
+", modelix, and the modelix framework, are licensed under the "
152+
a("https://www.apache.org/licenses/LICENSE-2.0.html") { +"Apache-2.0 license"}
153+
+"."
154+
}
155+
}
156+
157+
fun createDocsIndexPage(): String {
158+
return createHTML().html {
159+
head {
160+
link(href = "./$version/styles/style.css", rel = "Stylesheet")
161+
link(href = "./$version/styles/logo-styles.css", rel = "Stylesheet")
162+
title("modelix.core API Reference")
163+
style {
164+
unsafe {
165+
+"""
166+
.library-name {
167+
padding-top: 6px;
168+
padding-bottom: 6px;
169+
}
170+
""".trimIndent()
171+
}
172+
}
173+
}
174+
body {
175+
div("navigation-wrapper") {
176+
id = "navigation-wrapper"
177+
div("library-name") {
178+
a { +"modelix.core API Reference" }
179+
}
180+
}
181+
div("wrapper") {
182+
id = "container"
183+
div {
184+
id ="leftColumn"
185+
}
186+
div {
187+
id = "main"
188+
div("main-content") {
189+
id ="content"
190+
div("breadcrumbs")
191+
div("cover") {
192+
h2 { +"Available versions:" }
193+
div("table") {
194+
val versionDirs = docsDir.listFiles()
195+
?.filter { it.isDirectory }
196+
?.sortedByDescending { it.name }
197+
if (versionDirs != null) {
198+
for (versionDir in versionDirs) {
199+
val versionIndex = versionDir.resolve("index.html")
200+
if (versionIndex.exists()) {
201+
div("table-row") {
202+
div("main-subrow") {
203+
div("w-100") {
204+
span("inline-flex") {
205+
a( href = versionIndex.relativeTo(docsDir).path) {
206+
+"modelix.core ${versionDir.name}"
207+
}
208+
}
209+
}
210+
}
211+
}
212+
}
213+
}
214+
}
215+
}
216+
}
217+
}
218+
div("footer") {
219+
span("go-to-top-icon") {
220+
a("#content") {
221+
id = "go-to-top-link"
222+
}
223+
}
224+
span {
225+
createFooter()
226+
}
227+
}
228+
}
229+
}
230+
}
231+
}
232+
}

dokka/logo-dark.svg

Lines changed: 27 additions & 0 deletions
Loading

dokka/logo-styles.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.library-name a {
2+
position: relative;
3+
margin-left: 55px;
4+
}
5+
6+
.library-name a::before {
7+
content: '';
8+
background: url('../images/logo-dark.svg') center no-repeat;
9+
background-size: contain;
10+
position: absolute;
11+
width: 50px;
12+
height: 50px;
13+
top: -18px;
14+
left: -55px;
15+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
org.gradle.jvmargs=-Xmx512m "-XX:MaxMetaspaceSize=2g"
12
systemProp.org.gradle.internal.http.socketTimeout=120000
23
kotlin.daemon.jvmargs=-Xmx2G
34

0 commit comments

Comments
 (0)