Skip to content

Commit

Permalink
move view logic to modal and simplify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
qtzar committed Oct 11, 2023
1 parent eec9cf7 commit 8f7aa35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package nl.avisi.structurizr.site.generatr.site.model

import nl.avisi.structurizr.site.generatr.site.GeneratorContext
import nl.avisi.structurizr.site.generatr.site.asUrlToFile

class CustomStylesheetViewModel(generatorContext: GeneratorContext, pageViewModel: PageViewModel) {
val url = customStylesheetPath(generatorContext)?.let { "/$it".asUrlToFile(pageViewModel.url) }
val type = extractType()
val includeCustomStylesheet = url != null
class CustomStylesheetViewModel(generatorContext: GeneratorContext) {
val resourceURI = getResourceURI(generatorContext)
val includeCustomStylesheet = resourceURI != null

private fun customStylesheetPath(generatorContext: GeneratorContext) =
generatorContext.workspace.views.configuration.properties
private fun getResourceURI(generatorContext: GeneratorContext): String? {
val stylesheet = generatorContext.workspace.views.configuration.properties
.getOrDefault(
"generatr.style.customStylesheet",
null
)
"generatr.style.customStylesheet",
null
)

private fun extractType(): String {
return if (url?.lowercase()?.startsWith("http") == true) "URI" else "FILE"
if (stylesheet != null) {
return if (stylesheet.lowercase().startsWith("http")) stylesheet else "./$stylesheet"
}

return null
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class PageViewModel(protected val generatorContext: GeneratorContext) {
pageSubTitle
}
val favicon by lazy { FaviconViewModel(generatorContext, this) }
val customStylesheet by lazy { CustomStylesheetViewModel(generatorContext, this) }
val customStylesheet by lazy { CustomStylesheetViewModel(generatorContext) }
val headerBar by lazy { HeaderBarViewModel(this, generatorContext) }
val menu by lazy { MenuViewModel(generatorContext, this) }
val includeAutoReloading = generatorContext.serving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ private fun HTML.headFragment(viewModel: PageViewModel) {
if (viewModel.includeAutoReloading)
autoReloadScript(viewModel)

if (viewModel.customStylesheet.includeCustomStylesheet){
when (viewModel.customStylesheet.type) {
"FILE" -> link(rel = "stylesheet", href = "./" + viewModel.customStylesheet.url)
"URI" -> link(rel = "stylesheet", href = viewModel.customStylesheet.url)
}
}

if (viewModel.customStylesheet.includeCustomStylesheet)
link(rel = "stylesheet", href = "./" + viewModel.customStylesheet.resourceURI)
}
}

Expand Down

0 comments on commit 8f7aa35

Please sign in to comment.