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

Show documentation section on software systems home #51

Merged
merged 2 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
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
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
)
}
}