Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Fixes #241 (Allow styles defined in an extending workspace to overrid…
Browse files Browse the repository at this point in the history
…e those in the base workspace).
  • Loading branch information
simonbrowndotje committed Apr 2, 2023
1 parent a0b544d commit 579b61c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## (unreleased)

- Fixes https://github.com/structurizr/dsl/issues/241 (Allow styles defined in an extending workspace to override those in the base workspace).

## 1.30.0 (31st March 2023)

- Allows `deploymentEnvironment` to be used without starting a new context (i.e. without `{` and `}`) (see https://github.com/structurizr/cli/discussions/112).
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/structurizr/dsl/ElementStyleParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ ElementStyle parseElementStyle(DslContext context, Tokens tokens) {
}

Workspace workspace = context.getWorkspace();
return workspace.getViews().getConfiguration().getStyles().addElementStyle(tag);
ElementStyle elementStyle = workspace.getViews().getConfiguration().getStyles().getElementStyle(tag);
if (elementStyle == null) {
elementStyle = workspace.getViews().getConfiguration().getStyles().addElementStyle(tag);
}

return elementStyle;
} else {
throw new RuntimeException("Expected: element <tag> {");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ RelationshipStyle parseRelationshipStyle(DslContext context, Tokens tokens) {
}

Workspace workspace = context.getWorkspace();
return workspace.getViews().getConfiguration().getStyles().addRelationshipStyle(tag);
RelationshipStyle relationshipStyle = workspace.getViews().getConfiguration().getStyles().getRelationshipStyle(tag);
if (relationshipStyle == null) {
relationshipStyle = workspace.getViews().getConfiguration().getStyles().addRelationshipStyle(tag);
}

return relationshipStyle;
} else {
throw new RuntimeException("Expected: relationship <tag> {");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ void test_parseElementStyle_CreatesAnElementStyle() {
assertNotNull(style);
}

@Test
void test_parseElementStyle_FindsAnExistingElementStyle() {
ElementStyle style = workspace.getViews().getConfiguration().getStyles().addElementStyle("Tag");
assertSame(style, parser.parseElementStyle(context(), tokens("element", "Tag")));
}

@Test
void test_parseShape_ThrowsAnException_WhenThereAreTooManyTokens() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ void test_parseRelationshipStyle_CreatesAnRelationshipStyle() {
assertNotNull(style);
}

@Test
void test_parseRelationshipStyle_FindsAnExistingRelationshipStyle() {
RelationshipStyle style = workspace.getViews().getConfiguration().getStyles().addRelationshipStyle("Tag");
assertSame(style, parser.parseRelationshipStyle(context(), tokens("relationship", "Tag")));
}

@Test
void test_parseThickness_ThrowsAnException_WhenThereAreTooManyTokens() {
try {
Expand Down

0 comments on commit 579b61c

Please sign in to comment.