From 73a2a80985760a9469b9d27db1d003b4d6c65724 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Wed, 15 Mar 2023 15:16:28 +0100 Subject: [PATCH 1/7] Add helper to extract title from a markdown document --- .../site/generatr/site/model/SectionTitle.kt | 32 +++++++++++ .../generatr/site/model/SectionTitleTest.kt | 55 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt create mode 100644 src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt new file mode 100644 index 00000000..90df5125 --- /dev/null +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt @@ -0,0 +1,32 @@ +package nl.avisi.structurizr.site.generatr.site.model + +import com.structurizr.documentation.Section +import com.vladsch.flexmark.ast.Heading +import com.vladsch.flexmark.ast.Paragraph +import com.vladsch.flexmark.parser.Parser + +private val parser = Parser.builder().build() +private const val MAX_TITLE_LENGTH = 50 + +fun Section.title(): String { + val document = parser.parse(content) + + if (!document.hasChildren()) + return "no title" + + val header = document.children.firstOrNull { it is Heading }?.let { it as Heading } + if (header != null) + return header.text.toString() + + val paragraph = document.children.firstOrNull { it is Paragraph }?.let { it as Paragraph }?.chars?.toString() + if (paragraph != null) + return if (paragraph.length > MAX_TITLE_LENGTH) { + val whitespacePosition = paragraph.withIndex() + .filter { it.value.isWhitespace() } + .lastOrNull { it.index < MAX_TITLE_LENGTH } + ?.index + paragraph.take(whitespacePosition ?: MAX_TITLE_LENGTH) + } else paragraph + + return "unknown title" +} diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt new file mode 100644 index 00000000..6b066734 --- /dev/null +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt @@ -0,0 +1,55 @@ +package nl.avisi.structurizr.site.generatr.site.model + +import assertk.assertThat +import assertk.assertions.isEqualTo +import com.structurizr.documentation.Format +import com.structurizr.documentation.Section +import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource + +class SectionTitleTest { + + @Test + fun `no content`() { + val section = Section(Format.Markdown, "") + assertThat(section.title()).isEqualTo("no title") + } + + @Test + fun `only whitespaces`() { + val section = Section(Format.Markdown, " \n ") + assertThat(section.title()).isEqualTo("no title") + } + + @Test + fun `short paragraph`() { + val section = Section(Format.Markdown, "some content") + assertThat(section.title()).isEqualTo("some content") + } + + @Test + fun `long paragraph`() { + val section = Section( + Format.Markdown, + "some very very long content we really need to truncate since no one wants to read such an exhausting title" + ) + assertThat(section.title()).isEqualTo("some very very long content we really need to") + } + + @Test + fun `long paragraph without whitespaces`() { + val section = Section( + Format.Markdown, + "some-very-very-long-content-we-really-need-to-truncate-since-no-one-wants-to-read-such-an-exhausting-title" + ) + assertThat(section.title()).isEqualTo("some-very-very-long-content-we-really-need-to-trun") + } + + @ParameterizedTest + @ValueSource(strings = ["# header", "## header", "### header"]) + fun `with heading`(content: String) { + val section = Section(Format.Markdown, content) + assertThat(section.title()).isEqualTo("header") + } +} From bde8deecb05b878b9737530cc4314f92e982da15 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Wed, 15 Mar 2023 15:18:15 +0100 Subject: [PATCH 2/7] Replace section title from workspace with our own title The section title will be removed soon. --- .../structurizr/site/generatr/site/model/MenuViewModel.kt | 2 +- .../site/generatr/site/model/SectionsTableViewModel.kt | 2 +- .../model/WorkspaceDocumentationSectionPageViewModel.kt | 4 ++-- .../site/generatr/site/model/HomePageViewModelTest.kt | 4 +--- .../site/generatr/site/model/MenuViewModelTest.kt | 7 +++---- .../site/model/SoftwareSystemHomePageViewModelTest.kt | 2 +- .../generatr/site/model/SoftwareSystemPageViewModelTest.kt | 4 ++-- .../structurizr/site/generatr/site/model/ViewModelTest.kt | 2 +- .../WorkspaceDocumentationSectionPageViewModelTest.kt | 2 +- 9 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModel.kt index 7a9ce9dc..9f082334 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModel.kt @@ -16,7 +16,7 @@ class MenuViewModel(generatorContext: GeneratorContext, private val pageViewMode generatorContext.workspace.documentation.sections .sortedBy { it.order } .drop(1) - .forEach { yield(createMenuItem(it.title, WorkspaceDocumentationSectionPageViewModel.url(it))) } + .forEach { yield(createMenuItem(it.title(), WorkspaceDocumentationSectionPageViewModel.url(it))) } }.toList() val softwareSystemItems = generatorContext.workspace.model.includedSoftwareSystems diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionsTableViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionsTableViewModel.kt index 8359f5ee..7fd006ec 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionsTableViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionsTableViewModel.kt @@ -12,7 +12,7 @@ fun PageViewModel.createSectionsTableViewModel(sections: Collection
, hr .forEach { (section, index) -> bodyRow( cellWithIndex(index.toString()), - cellWithLink(this@createSectionsTableViewModel, section.title, hrefFactory(section)) + cellWithLink(this@createSectionsTableViewModel, section.title(), hrefFactory(section)) ) } } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModel.kt index 6dad229d..6f8896c9 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModel.kt @@ -7,13 +7,13 @@ import nl.avisi.structurizr.site.generatr.site.GeneratorContext class WorkspaceDocumentationSectionPageViewModel(generatorContext: GeneratorContext, section: Section) : PageViewModel(generatorContext) { override val url = url(section) - override val pageSubTitle: String = section.title + override val pageSubTitle: String = section.title() val content = markdownToHtml(this, section.content, generatorContext.svgFactory) companion object { fun url(section: Section): String { - return "/${section.title.normalize()}" + return "/${section.title().normalize()}" } } } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/HomePageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/HomePageViewModelTest.kt index c6c15e6b..31614cee 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/HomePageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/HomePageViewModelTest.kt @@ -3,8 +3,6 @@ package nl.avisi.structurizr.site.generatr.site.model import assertk.assertThat import assertk.assertions.isEqualTo import assertk.assertions.isTrue -import com.structurizr.documentation.Format -import com.structurizr.documentation.Section import nl.avisi.structurizr.site.generatr.site.model.HomePageViewModel.Companion.DEFAULT_HOMEPAGE_CONTENT import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource @@ -30,7 +28,7 @@ class HomePageViewModelTest : ViewModelTest() { fun `homepage with workspace docs`() { val generatorContext = generatorContext() generatorContext.workspace.documentation.addSection( - Section("Section title", Format.Markdown, "Section content") + createSection("Section content") ) val viewModel = HomePageViewModel(generatorContext) diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModelTest.kt index 4882ec8c..adc62157 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModelTest.kt @@ -7,7 +7,6 @@ import assertk.assertions.isEqualTo import assertk.assertions.isTrue import com.structurizr.documentation.Decision import com.structurizr.documentation.Format -import com.structurizr.documentation.Section import com.structurizr.model.Location import nl.avisi.structurizr.site.generatr.site.GeneratorContext import org.junit.jupiter.api.Test @@ -66,10 +65,10 @@ class MenuViewModelTest : ViewModelTest() { @ValueSource(strings = ["main", "branch-2"]) fun `workspace-level documentation in general section`(currentBranch: String) { val generatorContext = generatorContext(branches = listOf("main", "branch-2"), currentBranch = currentBranch) - generatorContext.workspace.documentation.addSection(Section("Home", Format.Markdown, "content")) - val section1 = Section("Doc 1", Format.Markdown, "content") + generatorContext.workspace.documentation.addSection(createSection("# Home")) + val section1 = createSection("# Doc 1") .also { generatorContext.workspace.documentation.addSection(it) } - val section2 = Section("Doc Title 2", Format.Markdown, "content") + val section2 = createSection(" Doc Title 2") .also { generatorContext.workspace.documentation.addSection(it) } val pageViewModel = createPageViewModel(generatorContext) val viewModel = MenuViewModel(generatorContext, pageViewModel) diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModelTest.kt index d1d4f4e2..aeb32379 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemHomePageViewModelTest.kt @@ -42,7 +42,7 @@ class SoftwareSystemHomePageViewModelTest : ViewModelTest() { val generatorContext = generatorContext() val softwareSystem: SoftwareSystem = generatorContext.workspace.model.addSoftwareSystem("Software system") .apply { - documentation.addSection(Section("Title", Format.Markdown, "# Content")) + documentation.addSection(createSection("# Title")) } val viewModel = SoftwareSystemHomePageViewModel(generatorContext, softwareSystem) diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModelTest.kt index 86c9edf0..f99d96eb 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModelTest.kt @@ -175,9 +175,9 @@ class SoftwareSystemPageViewModelTest : ViewModelTest() { val viewModel = SoftwareSystemPageViewModel(generatorContext, softwareSystem, Tab.HOME) assertThat(getTab(viewModel, Tab.SECTIONS).visible).isFalse() - softwareSystem.documentation.addSection(createSection("Section 0000")) + softwareSystem.documentation.addSection(createSection("# Section 0000")) assertThat(getTab(viewModel, Tab.SECTIONS).visible).isFalse() - softwareSystem.documentation.addSection(createSection("Section 0001")) + softwareSystem.documentation.addSection(createSection("# Section 0001")) assertThat(getTab(viewModel, Tab.SECTIONS).visible).isTrue() } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ViewModelTest.kt index 1fca8be1..c338b962 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ViewModelTest.kt @@ -37,5 +37,5 @@ abstract class ViewModelTest { content = "Decision $id content" } - protected fun createSection(title: String = "Section 1") = Section(title, Format.Markdown, "# Content") + protected fun createSection(content: String = "# Content") = Section(Format.Markdown, content) } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModelTest.kt index 51b1615b..402cfbcd 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModelTest.kt @@ -29,7 +29,7 @@ class WorkspaceDocumentationSectionPageViewModelTest : ViewModelTest() { val section = createSection() val viewModel = WorkspaceDocumentationSectionPageViewModel(generatorContext, section) - assertThat(viewModel.pageSubTitle).isEqualTo(section.title) + assertThat(viewModel.pageSubTitle).isEqualTo(section.title()) } @Test From 7f9a42b673bb083706ce40739ee075af2f4fb756 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Wed, 15 Mar 2023 15:18:35 +0100 Subject: [PATCH 3/7] Update structurizr libraries --- build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ea7bea34..f91a6532 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,9 +19,9 @@ dependencies { implementation("org.eclipse.jgit:org.eclipse.jgit:6.5.0.202303070854-r") - implementation("com.structurizr:structurizr-core:1.21.0") - implementation("com.structurizr:structurizr-dsl:1.27.1") - implementation("com.structurizr:structurizr-export:1.10.1") + implementation("com.structurizr:structurizr-core:1.23.0") + implementation("com.structurizr:structurizr-dsl:1.29.0") + implementation("com.structurizr:structurizr-export:1.12.1") implementation("net.sourceforge.plantuml:plantuml:1.2023.4") From 5124bad53367adb6d48916c7dbbc7d2aa91724fc Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Wed, 15 Mar 2023 15:47:33 +0100 Subject: [PATCH 4/7] Improve title extraction --- .../site/generatr/site/model/SectionTitle.kt | 4 +- .../generatr/site/model/SectionTitleTest.kt | 46 ++++++++++++------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt index 90df5125..92a8bc90 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt @@ -12,7 +12,7 @@ fun Section.title(): String { val document = parser.parse(content) if (!document.hasChildren()) - return "no title" + return "untitled document" val header = document.children.firstOrNull { it is Heading }?.let { it as Heading } if (header != null) @@ -28,5 +28,5 @@ fun Section.title(): String { paragraph.take(whitespacePosition ?: MAX_TITLE_LENGTH) } else paragraph - return "unknown title" + return "unknown document" } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt index 6b066734..6e8b8a52 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt @@ -10,37 +10,49 @@ import org.junit.jupiter.params.provider.ValueSource class SectionTitleTest { - @Test - fun `no content`() { - val section = Section(Format.Markdown, "") - assertThat(section.title()).isEqualTo("no title") + @ParameterizedTest + @ValueSource(strings = ["Markdown", "AsciiDoc"]) + fun `no content`(format: Format) { + val section = Section(format, "") + assertThat(section.title()).isEqualTo("untitled document") + } + + @ParameterizedTest + @ValueSource(strings = ["Markdown", "AsciiDoc"]) + fun `only whitespaces`(format: Format) { + val section = Section(format, " \n ") + assertThat(section.title()).isEqualTo("untitled document") } - @Test - fun `only whitespaces`() { - val section = Section(Format.Markdown, " \n ") - assertThat(section.title()).isEqualTo("no title") + @ParameterizedTest + @ValueSource(strings = ["Markdown", "AsciiDoc"]) + fun `invalid format`(format: Format) { + val section = Section(format, "

title

") + assertThat(section.title()).isEqualTo("unknown document") } - @Test - fun `short paragraph`() { - val section = Section(Format.Markdown, "some content") + @ParameterizedTest + @ValueSource(strings = ["Markdown", "AsciiDoc"]) + fun `short paragraph`(format: Format) { + val section = Section(format, "some content") assertThat(section.title()).isEqualTo("some content") } - @Test - fun `long paragraph`() { + @ParameterizedTest + @ValueSource(strings = ["Markdown", "AsciiDoc"]) + fun `long paragraph`(format: Format) { val section = Section( - Format.Markdown, + format, "some very very long content we really need to truncate since no one wants to read such an exhausting title" ) assertThat(section.title()).isEqualTo("some very very long content we really need to") } - @Test - fun `long paragraph without whitespaces`() { + @ParameterizedTest + @ValueSource(strings = ["Markdown", "AsciiDoc"]) + fun `long paragraph without whitespaces`(format: Format) { val section = Section( - Format.Markdown, + format, "some-very-very-long-content-we-really-need-to-truncate-since-no-one-wants-to-read-such-an-exhausting-title" ) assertThat(section.title()).isEqualTo("some-very-very-long-content-we-really-need-to-trun") From 853f780fbad5cff18ca268e0cfd7c01bd3be1860 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Wed, 15 Mar 2023 15:49:53 +0100 Subject: [PATCH 5/7] Improve example documentation --- docs/example/internet-banking-system/docs/0001-history.md | 6 ++---- docs/example/internet-banking-system/docs/0002-guide.md | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/example/internet-banking-system/docs/0001-history.md b/docs/example/internet-banking-system/docs/0001-history.md index 89e9b491..62a7c0a9 100644 --- a/docs/example/internet-banking-system/docs/0001-history.md +++ b/docs/example/internet-banking-system/docs/0001-history.md @@ -1,5 +1,3 @@ -# Documentation +# History -## History - -Some notes how we got to the current state. \ No newline at end of file +Some notes how we got to the current state. diff --git a/docs/example/internet-banking-system/docs/0002-guide.md b/docs/example/internet-banking-system/docs/0002-guide.md index 23d08863..229f2c7a 100644 --- a/docs/example/internet-banking-system/docs/0002-guide.md +++ b/docs/example/internet-banking-system/docs/0002-guide.md @@ -1,5 +1,3 @@ -# Documentation - -## Usage +# Usage This is how we use this thing. From c8d039ead101203c6fdf9b7805927f2ddc691443 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Wed, 15 Mar 2023 16:11:21 +0100 Subject: [PATCH 6/7] Validate section format for title extraction --- .../site/generatr/site/model/SectionTitle.kt | 4 ++ .../generatr/site/model/SectionTitleTest.kt | 44 ++++++++----------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt index 92a8bc90..c6d10996 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt @@ -1,5 +1,6 @@ package nl.avisi.structurizr.site.generatr.site.model +import com.structurizr.documentation.Format import com.structurizr.documentation.Section import com.vladsch.flexmark.ast.Heading import com.vladsch.flexmark.ast.Paragraph @@ -9,6 +10,9 @@ private val parser = Parser.builder().build() private const val MAX_TITLE_LENGTH = 50 fun Section.title(): String { + if (format != Format.Markdown) + return "unsupported document" + val document = parser.parse(content) if (!document.hasChildren()) diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt index 6e8b8a52..8c354ceb 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt @@ -10,49 +10,43 @@ import org.junit.jupiter.params.provider.ValueSource class SectionTitleTest { - @ParameterizedTest - @ValueSource(strings = ["Markdown", "AsciiDoc"]) - fun `no content`(format: Format) { - val section = Section(format, "") + @Test + fun `no content`() { + val section = Section(Format.Markdown, "") assertThat(section.title()).isEqualTo("untitled document") } - @ParameterizedTest - @ValueSource(strings = ["Markdown", "AsciiDoc"]) - fun `only whitespaces`(format: Format) { - val section = Section(format, " \n ") + @Test + fun `only whitespaces`() { + val section = Section(Format.Markdown, " \n ") assertThat(section.title()).isEqualTo("untitled document") } - @ParameterizedTest - @ValueSource(strings = ["Markdown", "AsciiDoc"]) - fun `invalid format`(format: Format) { - val section = Section(format, "

title

") - assertThat(section.title()).isEqualTo("unknown document") + @Test + fun `no markdown`() { + val section = Section(Format.AsciiDoc, "== title") + assertThat(section.title()).isEqualTo("unsupported document") } - @ParameterizedTest - @ValueSource(strings = ["Markdown", "AsciiDoc"]) - fun `short paragraph`(format: Format) { - val section = Section(format, "some content") + @Test + fun `short paragraph`() { + val section = Section(Format.Markdown, "some content") assertThat(section.title()).isEqualTo("some content") } - @ParameterizedTest - @ValueSource(strings = ["Markdown", "AsciiDoc"]) - fun `long paragraph`(format: Format) { + @Test + fun `long paragraph`() { val section = Section( - format, + Format.Markdown, "some very very long content we really need to truncate since no one wants to read such an exhausting title" ) assertThat(section.title()).isEqualTo("some very very long content we really need to") } - @ParameterizedTest - @ValueSource(strings = ["Markdown", "AsciiDoc"]) - fun `long paragraph without whitespaces`(format: Format) { + @Test + fun `long paragraph without whitespaces`() { val section = Section( - format, + Format.Markdown, "some-very-very-long-content-we-really-need-to-truncate-since-no-one-wants-to-read-such-an-exhausting-title" ) assertThat(section.title()).isEqualTo("some-very-very-long-content-we-really-need-to-trun") From b36ffe15500da9d8a1aea41d38635899bd46f67d Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Wed, 15 Mar 2023 16:14:29 +0100 Subject: [PATCH 7/7] Rename title function To avoid confusion with the still existing title property. --- .../site/generatr/site/model/MenuViewModel.kt | 2 +- .../site/generatr/site/model/SectionTitle.kt | 2 +- .../generatr/site/model/SectionsTableViewModel.kt | 2 +- .../WorkspaceDocumentationSectionPageViewModel.kt | 4 ++-- .../site/generatr/site/model/SectionTitleTest.kt | 14 +++++++------- ...rkspaceDocumentationSectionPageViewModelTest.kt | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModel.kt index 9f082334..6cb888e6 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/MenuViewModel.kt @@ -16,7 +16,7 @@ class MenuViewModel(generatorContext: GeneratorContext, private val pageViewMode generatorContext.workspace.documentation.sections .sortedBy { it.order } .drop(1) - .forEach { yield(createMenuItem(it.title(), WorkspaceDocumentationSectionPageViewModel.url(it))) } + .forEach { yield(createMenuItem(it.contentTitle(), WorkspaceDocumentationSectionPageViewModel.url(it))) } }.toList() val softwareSystemItems = generatorContext.workspace.model.includedSoftwareSystems diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt index c6d10996..480eac82 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitle.kt @@ -9,7 +9,7 @@ import com.vladsch.flexmark.parser.Parser private val parser = Parser.builder().build() private const val MAX_TITLE_LENGTH = 50 -fun Section.title(): String { +fun Section.contentTitle(): String { if (format != Format.Markdown) return "unsupported document" diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionsTableViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionsTableViewModel.kt index 7fd006ec..3233ba54 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionsTableViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionsTableViewModel.kt @@ -12,7 +12,7 @@ fun PageViewModel.createSectionsTableViewModel(sections: Collection
, hr .forEach { (section, index) -> bodyRow( cellWithIndex(index.toString()), - cellWithLink(this@createSectionsTableViewModel, section.title(), hrefFactory(section)) + cellWithLink(this@createSectionsTableViewModel, section.contentTitle(), hrefFactory(section)) ) } } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModel.kt index 6f8896c9..e0c2cbaf 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModel.kt @@ -7,13 +7,13 @@ import nl.avisi.structurizr.site.generatr.site.GeneratorContext class WorkspaceDocumentationSectionPageViewModel(generatorContext: GeneratorContext, section: Section) : PageViewModel(generatorContext) { override val url = url(section) - override val pageSubTitle: String = section.title() + override val pageSubTitle: String = section.contentTitle() val content = markdownToHtml(this, section.content, generatorContext.svgFactory) companion object { fun url(section: Section): String { - return "/${section.title().normalize()}" + return "/${section.contentTitle().normalize()}" } } } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt index 8c354ceb..7770243f 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SectionTitleTest.kt @@ -13,25 +13,25 @@ class SectionTitleTest { @Test fun `no content`() { val section = Section(Format.Markdown, "") - assertThat(section.title()).isEqualTo("untitled document") + assertThat(section.contentTitle()).isEqualTo("untitled document") } @Test fun `only whitespaces`() { val section = Section(Format.Markdown, " \n ") - assertThat(section.title()).isEqualTo("untitled document") + assertThat(section.contentTitle()).isEqualTo("untitled document") } @Test fun `no markdown`() { val section = Section(Format.AsciiDoc, "== title") - assertThat(section.title()).isEqualTo("unsupported document") + assertThat(section.contentTitle()).isEqualTo("unsupported document") } @Test fun `short paragraph`() { val section = Section(Format.Markdown, "some content") - assertThat(section.title()).isEqualTo("some content") + assertThat(section.contentTitle()).isEqualTo("some content") } @Test @@ -40,7 +40,7 @@ class SectionTitleTest { Format.Markdown, "some very very long content we really need to truncate since no one wants to read such an exhausting title" ) - assertThat(section.title()).isEqualTo("some very very long content we really need to") + assertThat(section.contentTitle()).isEqualTo("some very very long content we really need to") } @Test @@ -49,13 +49,13 @@ class SectionTitleTest { Format.Markdown, "some-very-very-long-content-we-really-need-to-truncate-since-no-one-wants-to-read-such-an-exhausting-title" ) - assertThat(section.title()).isEqualTo("some-very-very-long-content-we-really-need-to-trun") + assertThat(section.contentTitle()).isEqualTo("some-very-very-long-content-we-really-need-to-trun") } @ParameterizedTest @ValueSource(strings = ["# header", "## header", "### header"]) fun `with heading`(content: String) { val section = Section(Format.Markdown, content) - assertThat(section.title()).isEqualTo("header") + assertThat(section.contentTitle()).isEqualTo("header") } } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModelTest.kt index 402cfbcd..bb1d787c 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDocumentationSectionPageViewModelTest.kt @@ -29,7 +29,7 @@ class WorkspaceDocumentationSectionPageViewModelTest : ViewModelTest() { val section = createSection() val viewModel = WorkspaceDocumentationSectionPageViewModel(generatorContext, section) - assertThat(viewModel.pageSubTitle).isEqualTo(section.title()) + assertThat(viewModel.pageSubTitle).isEqualTo(section.contentTitle()) } @Test