Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #1586 preserve workspace styles while applying theme #1592

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.