Skip to content

Commit

Permalink
Adds support for themes.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Jan 5, 2020
1 parent 7e8410f commit 9801cc4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
44 changes: 43 additions & 1 deletion Structurizr.Core.Tests/View/ConfigurationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xunit;
using System;
using Xunit;

namespace Structurizr.Core.Tests
{
Expand Down Expand Up @@ -33,6 +34,47 @@ public void test_copyConfigurationFrom()
ViewConfiguration destination = new ViewConfiguration();
destination.CopyConfigurationFrom(source);
Assert.Equal("someKey", destination.LastSavedView);
}

[Fact]
public void Test_SetTheme_WithAUrl()
{
ViewConfiguration configuration = new ViewConfiguration();
configuration.Theme = "https://example.com/theme.json";
Assert.Equal("https://example.com/theme.json", configuration.Theme);
}

[Fact]
public void Test_SetTheme_WithAUrlThatHasATrailingSpaceCharacter()
{
ViewConfiguration configuration = new ViewConfiguration();
configuration.Theme = "https://example.com/theme.json ";
Assert.Equal("https://example.com/theme.json", configuration.Theme);
}

[Fact]
public void Test_SetTheme_ThrowsAnIllegalArgumentException_WhenAnInvalidUrlIsSpecified()
{
ViewConfiguration configuration = new ViewConfiguration();
Assert.Throws<ArgumentException>(() =>
configuration.Theme = "blah"
);
}

[Fact]
public void Test_SetTheme_DoesNothing_WhenANullUrlIsSpecified()
{
ViewConfiguration configuration = new ViewConfiguration();
configuration.Theme = null;
Assert.Null(configuration.Theme);
}

[Fact]
public void Test_SetTheme_DoesNothing_WhenAnEmptyUrlIsSpecified()
{
ViewConfiguration configuration = new ViewConfiguration();
configuration.Theme = " ";
Assert.Null(configuration.Theme);
}

}
Expand Down
23 changes: 23 additions & 0 deletions Structurizr.Core/View/ViewConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Runtime.Serialization;
using Structurizr.Core.View;
using Structurizr.Util;

namespace Structurizr
{
Expand All @@ -21,6 +23,27 @@ internal ViewConfiguration()
[DataMember(Name = "styles", EmitDefaultValue = false)]
public Styles Styles { get; internal set; }

private String _theme;

[DataMember(Name = "theme", EmitDefaultValue = false)]
public string Theme
{
get { return _theme; }
set
{
if (value != null && value.Trim().Length > 0)
{
if (Url.IsUrl(value))
{
_theme = value.Trim();
}
else {
throw new ArgumentException(value + " is not a valid URL.");
}
}
}
}

[DataMember(Name = "branding", EmitDefaultValue = false)]
public Branding Branding { get; internal set; }

Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.9.6 (unreleased)

- Added A1 and A0 paper sizes.
- Adds support for themes.

## 0.9.5 (24th December 2019)

Expand Down

0 comments on commit 9801cc4

Please sign in to comment.