Skip to content

Commit

Permalink
Rename title function
Browse files Browse the repository at this point in the history
To avoid confusion with the still existing title property.
  • Loading branch information
jp7677 committed Mar 15, 2023
1 parent 84fc3b5 commit 229f9fe
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fun PageViewModel.createSectionsTableViewModel(sections: Collection<Section>, hr
.forEach { (section, index) ->
bodyRow(
cellWithIndex(index.toString()),
cellWithLink(this@createSectionsTableViewModel, section.title(), hrefFactory(section))
cellWithLink(this@createSectionsTableViewModel, section.contentTitle(), hrefFactory(section))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 229f9fe

Please sign in to comment.