Skip to content
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

Support links between ADR's #284

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ class SoftwareSystemDecisionPageViewModel(
) : SoftwareSystemPageViewModel(generatorContext, softwareSystem, Tab.DECISIONS) {
override val url = url(softwareSystem, decision)

val content = markdownToHtml(this, decision.content, generatorContext.svgFactory)
val content = markdownToHtml(this, fixADRLinks(decision.content, softwareSystem), generatorContext.svgFactory)

private fun fixADRLinks(content: String, softwareSystem: SoftwareSystem) =
dirkgroot marked this conversation as resolved.
Show resolved Hide resolved
content.replace("\\[(.*)]\\(#(\\d+)\\)".toRegex()) {
"[${it.groupValues[1]}](${url(softwareSystem, Tab.DECISIONS)}/${it.groupValues[2]})"
}

companion object {
fun url(softwareSystem: SoftwareSystem, decision: Decision) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ class WorkspaceDecisionPageViewModel(generatorContext: GeneratorContext, decisio
override val url = url(decision)
override val pageSubTitle: String = decision.title

val content = markdownToHtml(this, decision.content, generatorContext.svgFactory)
val content = markdownToHtml(this, fixADRLinks(decision.content), generatorContext.svgFactory)

private fun fixADRLinks(content: String) =
dirkgroot marked this conversation as resolved.
Show resolved Hide resolved
content.replace("\\[(.*)]\\(#(\\d+)\\)".toRegex()) {
"[${it.groupValues[1]}](decisions/${it.groupValues[2]})"
}

companion object {
fun url(decision: Decision) = "/decisions/${decision.id}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package nl.avisi.structurizr.site.generatr.site.model
import assertk.assertThat
import assertk.assertions.isEqualTo
import nl.avisi.structurizr.site.generatr.normalize
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel.Companion.url
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel.Tab
import kotlin.test.Test

class SoftwareSystemDecisionPageViewModelTest : ViewModelTest() {
Expand All @@ -25,7 +27,7 @@ class SoftwareSystemDecisionPageViewModelTest : ViewModelTest() {
val viewModel = SoftwareSystemDecisionPageViewModel(generatorContext, softwareSystem, createDecision())

assertThat(viewModel.tabs.single { it.link.active }.tab)
.isEqualTo(SoftwareSystemPageViewModel.Tab.DECISIONS)
.isEqualTo(Tab.DECISIONS)
}

@Test
Expand All @@ -35,4 +37,28 @@ class SoftwareSystemDecisionPageViewModelTest : ViewModelTest() {

assertThat(viewModel.content).isEqualTo(markdownToHtml(viewModel, decision.content, svgFactory))
}


@Test
fun `link to other ADR`() {
val decision = createDecision().apply {
content = """
Decision with [link to other ADR](#2).
[Web link](https://google.com)
[Internal link](#other-section)
""".trimIndent()
}
val viewModel = SoftwareSystemDecisionPageViewModel(generatorContext, softwareSystem, decision)

assertThat(viewModel.content).isEqualTo(
markdownToHtml(
viewModel, """
Decision with [link to other ADR](${url(softwareSystem, Tab.DECISIONS)}/2).
[Web link](https://google.com)
[Internal link](#other-section)
""".trimIndent(),
svgFactory
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,27 @@ class WorkspaceDecisionPageViewModelTest : ViewModelTest() {

assertThat(viewModel.content).isEqualTo(markdownToHtml(viewModel, decision.content, svgFactory))
}

@Test
fun `link to other ADR`() {
val decision = createDecision().apply {
content = """
Decision with [link to other ADR](#2).
[Web link](https://google.com)
[Internal link](#other-section)
""".trimIndent()
}
val viewModel = WorkspaceDecisionPageViewModel(generatorContext(), decision)

assertThat(viewModel.content).isEqualTo(
markdownToHtml(
viewModel, """
Decision with [link to other ADR](decisions/2).
[Web link](https://google.com)
[Internal link](#other-section)
""".trimIndent(),
svgFactory
)
)
}
}