Skip to content

Commit

Permalink
resolves #1586 preserve workspace styles while applying theme (#1592)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie authored Jul 14, 2023
1 parent 482f7dc commit 4e3ca68
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/src/main/java/io/kroki/server/service/Structurizr.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,19 @@ private byte[] convert(String source, FileFormat fileFormat, JsonObject options)
private static void applyTheme(ViewSet viewSet, StructurizrTheme theme) {
List<ElementStyle> elementStyles = theme.getElementStyles();
for (ElementStyle elementStyle : elementStyles) {
viewSet.getConfiguration().getStyles().add(elementStyle);
String tag = elementStyle.getTag();
ElementStyle currentElementStyle = viewSet.getConfiguration().getStyles().getElementStyle(tag);
if (currentElementStyle == null) {
viewSet.getConfiguration().getStyles().add(elementStyle);
}
}
List<RelationshipStyle> relationshipStyles = theme.getRelationshipStyle();
for (RelationshipStyle relationshipStyle : relationshipStyles) {
viewSet.getConfiguration().getStyles().add(relationshipStyle);
String tag = relationshipStyle.getTag();
ElementStyle currentRelationshipStyle = viewSet.getConfiguration().getStyles().getElementStyle(tag);
if (currentRelationshipStyle == null) {
viewSet.getConfiguration().getStyles().add(relationshipStyle);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ public void should_throw_exception_when_script_directive_used() throws IOExcepti
.hasMessage("Unable to parse the Structurizr DSL. Error running inline script, caused by java.lang.RuntimeException: Could not load a scripting engine for extension \"kts\" at line 5: }.");
}

@Test
public void should_preserve_styles_defined_in_workspace_while_applying_theme() throws IOException, InterruptedException {
String source = read("./workspace-style-with-theme.structurizr");
byte[] convert = Structurizr.convert(source, FileFormat.SVG, plantumlCommand, new StructurizrPlantUMLExporter(), new JsonObject());
assertThat(new String(convert)).isEqualTo(read("./workspace-style-with-theme.svg"));
}

private String stripComments(String xmlContent) {
return xmlContent.replaceAll("<!--[\\s\\S]*?-->", "");
}
Expand Down
21 changes: 21 additions & 0 deletions server/src/test/resources/workspace-style-with-theme.structurizr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
workspace {

model {
softwareSystem "Software System"
}

views {
theme default

systemLandscape "SystemLandscape" {
include *
autoLayout
}

styles {
element "Software System" {
background orange
}
}
}
}
1 change: 1 addition & 0 deletions server/src/test/resources/workspace-style-with-theme.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4e3ca68

Please sign in to comment.