Skip to content

Commit 4445e00

Browse files
committed
Use Mustache to add component and tokens versions in documentation
1 parent 2052c84 commit 4445e00

File tree

13 files changed

+97
-61
lines changed

13 files changed

+97
-61
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ docs/dokka/
3636

3737
# App
3838
app/src/main/res/raw/changelog.md
39+
40+
# Mustache output
41+
Module.md

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ fun updateBuildConfig() {
168168
gradle.projectsEvaluated {
169169
tasks["preBuild"].apply {
170170
dependsOn(":checkNotice")
171-
dependsOn(":checkTokensVersion")
172171
dependsOn(tasks["updateAppChangelog"])
173172
}
174173
updateBuildConfig()

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ plugins {
2424
id("release")
2525
id("netlify")
2626
id("check-notice")
27-
id("tokens-version")
2827
}
2928

3029
dependencies {

buildSrc/build.gradle.kts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,17 @@ dependencies {
4242
implementation(libs.javapoet) // https://github.com/google/dagger/issues/3282
4343
implementation(libs.json)
4444
implementation(libs.kotlin.gradle.plugin) // https://issuetracker.google.com/issues/176079157#comment14
45-
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) // https://github.com/gradle/gradle/issues/15383
45+
implementation(libs.mustache.java)
4646
implementation(libs.zxing.core)
4747
implementation(libs.zxing.javase)
48+
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) // https://github.com/gradle/gradle/issues/15383
49+
}
50+
51+
sourceSets {
52+
named("main") {
53+
java {
54+
srcDir("../theme-contract/src/main/java")
55+
setIncludes(listOf("com/orange/ouds/theme/OudsVersion.kt"))
56+
}
57+
}
4858
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Software Name: OUDS Android
3+
* SPDX-FileCopyrightText: Copyright (c) Orange SA
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* This software is distributed under the MIT license,
7+
* the text of which is available at https://opensource.org/license/MIT/
8+
* or see the "LICENSE" file for more details.
9+
*
10+
* Software description: Android library of reusable graphical components
11+
*/
12+
13+
import com.github.mustachejava.DefaultMustacheFactory
14+
import java.io.FileOutputStream
15+
import java.io.PrintWriter
16+
import kotlin.reflect.full.declaredMemberProperties
17+
18+
tasks.register<DefaultTask>("prepareDocumentation") {
19+
doLast {
20+
val mustacheFactory = DefaultMustacheFactory()
21+
22+
// Retrieve OudsVersion.Component object and fill the table in core/Module.md with the component design versions
23+
val coreModuleDocumentationWriter = PrintWriter(FileOutputStream("core/Module.md"))
24+
// Build a map in order to loop through all component versions in core Module.mustache
25+
val componentVersions = Class.forName("com.orange.ouds.theme.OudsVersion${'$'}Component")
26+
.kotlin
27+
.declaredMemberProperties
28+
.map { property ->
29+
val name = property.name
30+
.split("(?=\\p{Upper})".toRegex())
31+
.filter { it.isNotEmpty() }
32+
.mapIndexed { index, word -> if (index == 0) word else word.lowercase() }
33+
.joinToString(" ")
34+
val value = property.getter.call() as String
35+
mapOf("name" to name, "value" to value)
36+
}
37+
mustacheFactory.compile("core/Module.mustache")
38+
.execute(coreModuleDocumentationWriter, mapOf("versions" to componentVersions))
39+
.flush()
40+
41+
// Retrieve OudsVersion.Tokens object and fill the tokens versions in various Module.md files
42+
val moduleDocumentationDirectories = listOf(
43+
"global-raw-tokens",
44+
"theme-contract",
45+
"theme-orange",
46+
"theme-sosh"
47+
)
48+
// Use OudsVersion.Tokens directly in various Module.mustache files
49+
val tokensVersions = Class.forName("com.orange.ouds.theme.OudsVersion${'$'}Tokens").kotlin.objectInstance
50+
moduleDocumentationDirectories.forEach { moduleDocumentationDirectory ->
51+
val moduleDocumentationWriter = PrintWriter(FileOutputStream("$moduleDocumentationDirectory/Module.md"))
52+
mustacheFactory.compile("$moduleDocumentationDirectory/Module.mustache")
53+
.execute(moduleDocumentationWriter, tokensVersions)
54+
.flush()
55+
}
56+
}
57+
}

buildSrc/src/main/kotlin/dokka.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
plugins {
1414
id("org.jetbrains.dokka")
15+
id("documentation")
1516
}
1617

1718
dokka {
@@ -30,3 +31,8 @@ dokka {
3031
failOnWarning.set(true)
3132
}
3233
}
34+
35+
gradle.projectsEvaluated {
36+
tasks["dokkaGenerate"].dependsOn(tasks["prepareDocumentation"]) // Case where dokkaGenerate is called from the subproject
37+
tasks["dokkaGenerateModuleHtml"].dependsOn(tasks["prepareDocumentation"]) // Case where dokkaGenerate is called from the root project
38+
}

buildSrc/src/main/kotlin/tokens-version.gradle.kts

Lines changed: 0 additions & 54 deletions
This file was deleted.

core/Module.md renamed to core/Module.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
Contains the main elements of the OUDS Android library.
44

5+
The table below lists the design version of each component:
6+
7+
| Component | Design version |
8+
| :--- | ---: |
9+
{{#versions}}
10+
| {{name}} | {{value}} |
11+
{{/versions}}
12+
513
# Package com.orange.ouds.core.component
614

715
Contains all OUDS basic components: OudsButton, OudsLink,...
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Module global-raw-tokens
22

33
```
4-
Tokens version 1.2.0
4+
Android core tokens version {{AndroidCore}}
5+
OUDS core tokens version {{OudsCore}}
56
```
67

78
Contains the raw tokens that can be used by any theme.

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ kotlin = "2.2.0"
2525
material = "1.12.0"
2626
mockitoAndroid = "5.18.0"
2727
mockitoKotlin = "6.0.0"
28+
mustacheJava = "0.9.14"
2829
navigationCompose = "2.9.2"
2930
paparazzi = "1.3.5"
3031
zxing = "3.5.3"
@@ -68,6 +69,7 @@ kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect", vers
6869
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
6970
mockito-android = { group = "org.mockito", name = "mockito-android", version.ref = "mockitoAndroid" }
7071
mockito-kotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version.ref = "mockitoKotlin" }
72+
mustache-java = { module = "com.github.spullara.mustache.java:compiler", version.ref = "mustacheJava" }
7173
zxing-core = { module = "com.google.zxing:core", version.ref = "zxing" }
7274
zxing-javase = { module = "com.google.zxing:javase", version.ref = "zxing" }
7375

0 commit comments

Comments
 (0)