Skip to content

Show data tables in tabs, and examples before usage #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1131,12 +1131,11 @@ import TabItem from '@theme/TabItem';

writeSourceLinks(recipeDescriptor, origin)
writeOptions(recipeDescriptor)
writeLicense(origin)
writeDefinition(recipeDescriptor, origin)
writeExamples(recipeDescriptor)
writeUsage(recipeDescriptor, origin)
writeModerneLink(recipeDescriptor)
writeDataTables(recipeDescriptor)
writeExamples(recipeDescriptor)
writeContributors(recipeDescriptor)
}
}
Expand Down Expand Up @@ -1199,6 +1198,25 @@ import TabItem from '@theme/TabItem';
)
}
}

writeLicense(origin)
}

private fun BufferedWriter.writeLicense(origin: RecipeOrigin) {
val licenseText = when (origin.license) {
Licenses.Unknown -> "The license for this recipe is unknown."
Licenses.Apache2, Licenses.Proprietary, Licenses.MSAL -> "This recipe is available under the ${origin.license.markdown()}."
else -> "This recipe is available under the ${origin.license.markdown()} License, as defined by the recipe authors."
}

//language=markdown
writeln(
"""

$licenseText

""".trimIndent()
)
}

private fun BufferedWriter.writeOptions(recipeDescriptor: RecipeDescriptor) {
Expand Down Expand Up @@ -1263,38 +1281,23 @@ import TabItem from '@theme/TabItem';
}
}

private fun BufferedWriter.writeLicense(origin: RecipeOrigin) {
val licenseText = when (origin.license) {
Licenses.Unknown -> "The license for this recipe is unknown."
Licenses.Apache2, Licenses.Proprietary, Licenses.MSAL -> "This recipe is available under the ${origin.license.markdown()}."
else -> "This recipe is available under the ${origin.license.markdown()} License, as defined by the recipe authors."
}

//language=markdown
writeln(
"""
## License

$licenseText

""".trimIndent()
)
}

private fun BufferedWriter.writeDataTables(recipeDescriptor: RecipeDescriptor) {
if (recipeDescriptor.dataTables.isNotEmpty()) {
writeln(
//language=markdown
"""
## Data Tables

<Tabs groupId="data-tables">
""".trimIndent()
)

for (dataTable in recipeDescriptor.dataTables) {
//language=markdown
writeln(
"""
<TabItem value="${dataTable.name}" label="${dataTable.name.substringAfterLast('.')}">

### ${dataTable.displayName}
**${dataTable.name}**

Expand All @@ -1314,8 +1317,22 @@ import TabItem from '@theme/TabItem';
)
}

writeln(
"""

</TabItem>
""".trimIndent()
)

newLine()
}

writeln(
//language=markdown
"""
</Tabs>
""".trimIndent()
)
}
}

Expand Down