Skip to content

Commit

Permalink
Merge pull request #51 from jp7677/software-system-home
Browse files Browse the repository at this point in the history
Show documentation section on software systems home
  • Loading branch information
dirkgroot committed Sep 15, 2022
2 parents 1ce3b73 + f172cbc commit 4b8058b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
11 changes: 11 additions & 0 deletions docs/example/internet-banking-system/docs/0001-introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Description

This is our fancy Internet Banking System.

## Vision

One system to rule them all!

## References

- Source Code on GitHub: [https://github.com/avisi-cloud/structurizr-site-generatr]
1 change: 1 addition & 0 deletions docs/example/workspace.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ workspace "Big Bank plc" "This is an example workspace to illustrate the key fea
atm = softwaresystem "ATM" "Allows customers to withdraw cash." "Existing System"

internetBankingSystem = softwaresystem "Internet Banking System" "Allows customers to view information about their bank accounts, and make payments." {
!docs internet-banking-system/docs
!adrs internet-banking-system/adr

singlePageApplication = container "Single-Page Application" "Provides all of the Internet banking functionality to customers via their web browser." "JavaScript and Angular" "Web Browser"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ import com.structurizr.model.SoftwareSystem
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemHomePageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
SoftwareSystemPageViewModel(generatorContext, softwareSystem, Tab.HOME)
SoftwareSystemPageViewModel(generatorContext, softwareSystem, Tab.HOME) {
val content = softwareSystem.documentation.sections
.sortedBy { it.filename }
.firstOrNull()
?.let { MarkdownViewModel(it.content) }
?: MarkdownViewModel("# Description${System.lineSeparator()}${softwareSystem.description}")
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package nl.avisi.structurizr.site.generatr.site.views

import kotlinx.html.HTML
import kotlinx.html.h1
import kotlinx.html.p
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemHomePageViewModel

fun HTML.softwareSystemHomePage(viewModel: SoftwareSystemHomePageViewModel) {
softwareSystemPage(viewModel) {
h1 { +"Description" }
p { +viewModel.description }
markdown(viewModel, viewModel.content)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package nl.avisi.structurizr.site.generatr.site.model

import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.prop
import com.structurizr.documentation.Format
import com.structurizr.documentation.Section
import com.structurizr.model.SoftwareSystem
import kotlin.test.Test

Expand All @@ -15,4 +18,32 @@ class SoftwareSystemHomePageViewModelTest : ViewModelTest() {
assertThat(viewModel.tabs.single { it.link.active }.tab)
.isEqualTo(SoftwareSystemPageViewModel.Tab.HOME)
}

@Test
fun `no section present`() {
val generatorContext = generatorContext()
val softwareSystem: SoftwareSystem = generatorContext.workspace.model.addSoftwareSystem("Software system")
.apply { description = "It's a system." }
val viewModel = SoftwareSystemHomePageViewModel(generatorContext, softwareSystem)

assertThat(viewModel.content)
.prop(MarkdownViewModel::markdown).isEqualTo(
"# Description${System.lineSeparator()}${softwareSystem.description}"
)
}

@Test
fun `section present`() {
val generatorContext = generatorContext()
val softwareSystem: SoftwareSystem = generatorContext.workspace.model.addSoftwareSystem("Software system")
.apply {
documentation.addSection(Section("Title", Format.Markdown, "# Content"))
}
val viewModel = SoftwareSystemHomePageViewModel(generatorContext, softwareSystem)

assertThat(viewModel.content)
.prop(MarkdownViewModel::markdown).isEqualTo(
softwareSystem.documentation.sections.single().content
)
}
}

0 comments on commit 4b8058b

Please sign in to comment.