-
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.
Add support for a custom stylesheet (#315)
* Add the ability to supply your own custom css file * Added reference to new property in readme file. * Moved the loading of the custom CSS to be the last item in the header so you can override css for FlexMark plugins also. Also a small bit of code cleanup * Add support for customer CSS to be either a local file or a hosted file * Change from customCSS to customStylesheet * Change from customCSS to customStylesheet ( readme file ) * move view logic to modal and simplify code. * Added tests and fixed example property in the workspace.dsl * removed obsolete './'
- Loading branch information
Showing
7 changed files
with
84 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
svg g g[id^="link"]:hover path { | ||
stroke:#FF0000 !important; | ||
stroke-width: 2.0; | ||
} | ||
|
||
svg g g[id^="link"]:hover polygon { | ||
stroke:#FF0000 !important; | ||
} | ||
|
||
svg g g[id^="link"]:hover text { | ||
fill:#FF0000 !important; | ||
} |
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
23 changes: 23 additions & 0 deletions
23
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model | ||
|
||
import nl.avisi.structurizr.site.generatr.site.GeneratorContext | ||
|
||
class CustomStylesheetViewModel(generatorContext: GeneratorContext) { | ||
val resourceURI = getResourceURI(generatorContext) | ||
val includeCustomStylesheet = resourceURI != null | ||
|
||
private fun getResourceURI(generatorContext: GeneratorContext): String? { | ||
val stylesheet = generatorContext.workspace.views.configuration.properties | ||
.getOrDefault( | ||
"generatr.style.customStylesheet", | ||
null | ||
) | ||
|
||
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
29 changes: 29 additions & 0 deletions
29
...est/kotlin/nl/avisi/structurizr/site/generatr/site/model/CustomStylesheetViewModelTest.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import org.junit.jupiter.api.Test | ||
|
||
class CustomStylesheetViewModelTest : ViewModelTest() { | ||
private val generatorContext = generatorContext() | ||
|
||
@Test | ||
fun `Configuration Property Missing`() { | ||
val customStylesheetViewModel = CustomStylesheetViewModel(generatorContext) | ||
assertThat(customStylesheetViewModel.resourceURI).isEqualTo(null) | ||
} | ||
|
||
@Test | ||
fun `Configuration Property Set To URL`() { | ||
generatorContext.workspace.views.configuration.addProperty("generatr.style.customStylesheet","http://example.uri/custom.css") | ||
val customStylesheetViewModel = CustomStylesheetViewModel(generatorContext) | ||
assertThat(customStylesheetViewModel.resourceURI).isEqualTo("http://example.uri/custom.css") | ||
} | ||
|
||
@Test | ||
fun `Configuration Property Set To Local File`() { | ||
generatorContext.workspace.views.configuration.addProperty("generatr.style.customStylesheet","custom.css") | ||
val customStylesheetViewModel = CustomStylesheetViewModel(generatorContext) | ||
assertThat(customStylesheetViewModel.resourceURI).isEqualTo("./custom.css") | ||
} | ||
} |