Skip to content

Commit

Permalink
Implemented suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
qtzar committed Oct 12, 2023
1 parent 66183b8 commit 15b75c7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ architecture model:
| `generatr.search.language` | Indexing/stemming language for the search index. See [Lunr language support](https://github.com/olivernn/lunr-languages) | `en` | `nl` |
| `generatr.markdown.flexmark.extensions` | Additional extensions to the markdown generator to add new markdown capabilities. [More Details](https://avisi-cloud.github.io/structurizr-site-generatr/main/extended-markdown-features/) | Tables | `Tables,Admonition` |
| `generatr.svglink.target` | Specifies the link target for element links in the exported svg | `_top` | `_self` |
| `generatr.nav.nestgroups` | Will show software systems in the left side navigator in collapsable groups | `false` | `true` |
| `generatr.site.nestGroups` | Will show software systems in the left side navigator in collapsable groups | `false` | `true` |


See the included example for usage of some those properties in the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package nl.avisi.structurizr.site.generatr.site.model

data class MenuNodeViewModel(val name: String, val children: List<MenuNodeViewModel>)
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,34 @@ class MenuViewModel(generatorContext: GeneratorContext, private val pageViewMode
private fun createMenuItem(title: String, href: String, exact: Boolean = true) =
LinkViewModel(pageViewModel, title, href, exact)

data class Node(val name: String, val children: MutableList<Node>)
fun softwareSystemNodes(): MenuNodeViewModel {
data class MutableMenuNode(val name: String, val children: MutableList<MutableMenuNode>) {
fun toMenuNode(): MenuNodeViewModel = MenuNodeViewModel(name, children.map { it.toMenuNode() })
}

val nestedSoftwareSystems = generatorContext.workspace.model.includedSoftwareSystems
.map {it.group + "/" + it.name}
.sortedBy {it.lowercase()}
val rootNode = MutableMenuNode("", mutableListOf())

fun buildTree(data: List<String>, delimiter: Char):MutableList<Node> {
val rootNode = Node("", mutableListOf())
for (path in data) {
val parts = path.split(delimiter)
softwareSystemPaths.forEach { path ->
var currentNode = rootNode

for (part in parts) {
path.split(delimiter).forEach { part ->
val existingNode = currentNode.children.find { it.name == part }
currentNode = if (existingNode == null) {
val newNode = Node(part, mutableListOf())
val newNode = MutableMenuNode(part, mutableListOf())
currentNode.children.add(newNode)
newNode
} else {
existingNode
}
}
}
return rootNode.children

return rootNode.toMenuNode()
}

private val softwareSystemPaths = generatorContext.workspace.model.includedSoftwareSystems
.map { it.group + "/" + it.name }
.sortedBy { it.lowercase() }

private val delimiter = '/'

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class PageViewModel(protected val generatorContext: GeneratorContext) {
val includeAdmonition = flexmarkConfig.selectedExtensionMap.containsKey("Admonition")
val includeKatex = flexmarkConfig.selectedExtensionMap.containsKey("GitLab")
val configuration = generatorContext.workspace.views.configuration.properties
val includeTreeview = configuration.getOrDefault("generatr.nav.nestgroups", "false").toBoolean()
val includeTreeview = configuration.getOrDefault("generatr.site.nestGroups", "false").toBoolean()

abstract val url: String
abstract val pageSubTitle: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nl.avisi.structurizr.site.generatr.site.views
import kotlinx.html.*
import nl.avisi.structurizr.site.generatr.site.GeneratorContext
import nl.avisi.structurizr.site.generatr.site.model.LinkViewModel
import nl.avisi.structurizr.site.generatr.site.model.MenuNodeViewModel
import nl.avisi.structurizr.site.generatr.site.model.MenuViewModel

fun DIV.menu(viewModel: MenuViewModel, nestGroups:Boolean) {
Expand All @@ -20,13 +21,10 @@ private fun ASIDE.generalSection(items: List<LinkViewModel>) {
private fun ASIDE.softwareSystemsSection(viewModel: MenuViewModel, nestGroups:Boolean) {
p(classes = "menu-label") { +"Software systems" }
if(nestGroups){
// Display SoftwareSystems as a nested lists
val rootNode = MenuViewModel.Node("", viewModel.buildTree(viewModel.nestedSoftwareSystems, "/".toCharArray()[0]))
ul(classes = "listree menu-list has-site-branding"){
buildHtmlTree(rootNode, viewModel).invoke(this)
buildHtmlTree(viewModel.softwareSystemNodes(), viewModel).invoke(this)
}
} else {
// Display SoftwareSystems as a flat list
menuItemLinks(viewModel.softwareSystemItems)
}
}
Expand All @@ -41,7 +39,7 @@ private fun ASIDE.menuItemLinks(items: List<LinkViewModel>) {
}
}

private fun buildHtmlTree(node: MenuViewModel.Node, viewModel: MenuViewModel): UL.() -> Unit = {
private fun buildHtmlTree(node: MenuNodeViewModel, viewModel: MenuViewModel): UL.() -> Unit = {

if (node.name.isNotEmpty() && node.children.isEmpty()) {
val itemLink = viewModel.softwareSystemItems.find { it.title == node.name }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private fun HTML.headFragment(viewModel: PageViewModel) {
link(rel = "stylesheet", href = "../" + "/style.css".asUrlToFile(viewModel.url))
link(rel = "stylesheet", href = "./" + "/style-branding.css".asUrlToFile(viewModel.url))

if(viewModel.includeTreeview)
if (viewModel.includeTreeview)
link(rel = "stylesheet", href = "../" + "/treeview.css".asUrlToFile(viewModel.url))

if (viewModel.includeAdmonition)
Expand Down

0 comments on commit 15b75c7

Please sign in to comment.