-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move view logic to modal and simplify code.
- Loading branch information
Showing
3 changed files
with
17 additions
and
20 deletions.
There are no files selected for viewing
26 changes: 14 additions & 12 deletions
26
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/CustomStylesheetViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters