-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
378 additions
and
12 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
19 changes: 19 additions & 0 deletions
19
src/web/CareLeavers.Web/Contentful/ContentfulEntityResolver.cs
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,19 @@ | ||
using CareLeavers.Web.Models.Content; | ||
using Contentful.Core.Configuration; | ||
|
||
namespace CareLeavers.Web.Contentful; | ||
|
||
public class ContentfulEntityResolver : IContentTypeResolver | ||
{ | ||
private Dictionary<string, Type> _types = new() | ||
{ | ||
{ Page.ContentType, typeof(Page) }, | ||
{ Grid.ContentType, typeof(Grid) }, | ||
{ Card.ContentType, typeof(Card) } | ||
}; | ||
|
||
public Type? Resolve(string contentTypeId) | ||
{ | ||
return _types.TryGetValue(contentTypeId, out var type) ? type : null; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/web/CareLeavers.Web/ContentfulRenderers/GDSGridRenderer.cs
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,35 @@ | ||
using CareLeavers.Web.Models.Content; | ||
using Contentful.Core.Models; | ||
|
||
namespace CareLeavers.Web.ContentfulRenderers; | ||
|
||
public class GDSGridRenderer(IServiceProvider serviceProvider) : GDSRazorContentRenderer(serviceProvider) | ||
{ | ||
public override bool SupportsContent(IContent content) | ||
{ | ||
if (content is EntryStructure { NodeType: "embedded-entry-block" } entryStructure) | ||
{ | ||
if (entryStructure.Data.Target is Grid) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return content is Grid; | ||
} | ||
|
||
public override Task<string> RenderAsync(IContent content) | ||
{ | ||
Grid? grid; | ||
if (content is Grid) | ||
{ | ||
grid = content as Grid; | ||
} | ||
else | ||
{ | ||
grid = (content as EntryStructure)?.Data.Target as Grid; | ||
} | ||
|
||
return RenderToString("Shared/Grid", grid); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/web/CareLeavers.Web/ContentfulRenderers/GDSRazorContentRenderer.cs
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,21 @@ | ||
using Contentful.AspNetCore.Authoring; | ||
using Contentful.Core.Models; | ||
using Microsoft.AspNetCore.Mvc.Razor; | ||
using Microsoft.AspNetCore.Mvc.ViewFeatures; | ||
|
||
namespace CareLeavers.Web.ContentfulRenderers; | ||
|
||
public abstract class GDSRazorContentRenderer( | ||
IServiceProvider serviceProvider) | ||
: RazorContentRenderer( | ||
serviceProvider.GetRequiredService<IRazorViewEngine>(), | ||
serviceProvider.GetRequiredService<ITempDataProvider>(), | ||
serviceProvider) | ||
{ | ||
public override string Render(IContent content) | ||
{ | ||
var result = RenderAsync(content); | ||
result.Wait(); | ||
return result.Result; | ||
} | ||
} |
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,20 @@ | ||
using Contentful.Core.Models; | ||
|
||
namespace CareLeavers.Web.Models.Content; | ||
|
||
public class Card : ContentfulContent | ||
{ | ||
public static string ContentType { get; } = "card"; | ||
|
||
public string? Title { get; set; } | ||
|
||
public string? Text { get; set; } | ||
|
||
public Asset? Image { get; set; } | ||
|
||
public Page? Link { get; set; } | ||
|
||
public List<string> Types { get; set; } = []; | ||
|
||
public int Position { get; set; } = 0; | ||
} |
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,19 @@ | ||
using CareLeavers.Web.Models.Enums; | ||
using Contentful.Core.Models; | ||
|
||
namespace CareLeavers.Web.Models.Content; | ||
|
||
public class Grid : ContentfulContent | ||
{ | ||
public static string ContentType { get; } = "grid"; | ||
|
||
public string? Title { get; set; } | ||
|
||
public GridType? GridType { get; set; } | ||
|
||
public bool ShowTitle { get; set; } | ||
|
||
public List<IContent>? Content { get; set; } | ||
|
||
public string? CssClass { get; set; } = "govuk-grid-column-full"; | ||
} |
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,15 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace CareLeavers.Web.Models.Enums; | ||
|
||
public enum GridType | ||
{ | ||
Cards, | ||
[EnumMember(Value = "Alternating Image and Text")] | ||
AlternatingImageAndText, | ||
[EnumMember(Value = "External Links")] | ||
ExternalLinks, | ||
Banner, | ||
[EnumMember(Value = "Small Banner")] | ||
SmallBanner | ||
} |
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,7 @@ | ||
namespace CareLeavers.Web.Models.Enums; | ||
|
||
public enum PageType | ||
{ | ||
Guide, | ||
Advice | ||
} |
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,11 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace CareLeavers.Web.Models.Enums; | ||
|
||
public enum PageWidth | ||
{ | ||
[EnumMember(Value = "Two Thirds")] | ||
TwoThirds, | ||
[EnumMember(Value = "Full Width")] | ||
FullWidth | ||
} |
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
Oops, something went wrong.