-
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.
* Added initial contentful setup and dummy models & views to test the integration * Added a custom renderer for Unordered lists as a POC
- Loading branch information
Showing
12 changed files
with
159 additions
and
1 deletion.
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
13 changes: 13 additions & 0 deletions
13
src/Dfe.EarlyYearsQualification.Content/Dfe.EarlyYearsQualification.Content.csproj
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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="contentful.csharp" Version="7.5.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
14 changes: 14 additions & 0 deletions
14
src/Dfe.EarlyYearsQualification.Content/Entities/LandingPage.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,14 @@ | ||
using Contentful.Core.Models; | ||
|
||
namespace Dfe.EarlyYearsQualification.Content.Entities; | ||
|
||
public class LandingPage | ||
{ | ||
public string Header { get; set; } = string.Empty; | ||
|
||
public Document? ServiceIntroduction { get; set; } | ||
|
||
public string ServiceIntroductionHtml { get; set; } = string.Empty; | ||
|
||
public string StartButtonText { get; set; } = string.Empty; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Dfe.EarlyYearsQualification.Content/Renderers/UnorderedListRenderer.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,30 @@ | ||
using System.Text; | ||
using Contentful.Core.Models; | ||
|
||
namespace Dfe.EarlyYearsQualification.Content.Renderers; | ||
|
||
public class UnorderedListRenderer : IContentRenderer | ||
{ | ||
public int Order { get; set; } | ||
|
||
public Task<string> RenderAsync(IContent content) | ||
{ | ||
var list = content as List; | ||
var sb = new StringBuilder(); | ||
sb.Append("<ul class=\"govuk-list govuk-list--bullet\">"); | ||
foreach (IContent listItem in list!.Content) | ||
{ | ||
var listItemValue = listItem as ListItem; | ||
var listItemParagraph = listItemValue!.Content[0] as Paragraph; | ||
var listItemText = listItemParagraph!.Content[0] as Text; | ||
sb.Append($"<li>{listItemText!.Value}</li>"); | ||
} | ||
sb.Append("</ul>"); | ||
return Task.FromResult(sb.ToString()); | ||
} | ||
|
||
public bool SupportsContent(IContent content) | ||
{ | ||
return content is List && (content as List)!.NodeType == "unordered-list"; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentService.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,26 @@ | ||
using Contentful.Core; | ||
using Contentful.Core.Models; | ||
using Dfe.EarlyYearsQualification.Content.Entities; | ||
using Dfe.EarlyYearsQualification.Content.Renderers; | ||
|
||
namespace Dfe.EarlyYearsQualification.Content.Services; | ||
|
||
public class ContentfulContentService : IContentService | ||
{ | ||
private readonly IContentfulClient _contentfulClient; | ||
|
||
public ContentfulContentService(IContentfulClient contentfulClient) | ||
{ | ||
_contentfulClient = contentfulClient; | ||
} | ||
|
||
public async Task<LandingPage> GetLandingPage() | ||
{ | ||
var landingPageEntries = await _contentfulClient.GetEntriesByType<LandingPage>("landingPage"); | ||
var landingPageContent = landingPageEntries.First(); | ||
var htmlRenderer = new HtmlRenderer(); | ||
htmlRenderer.AddRenderer(new UnorderedListRenderer() { Order = 10 }); | ||
landingPageContent.ServiceIntroductionHtml = await htmlRenderer.ToHtml(landingPageContent.ServiceIntroduction); | ||
return landingPageContent; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Dfe.EarlyYearsQualification.Content/Services/IContentService.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,8 @@ | ||
using Dfe.EarlyYearsQualification.Content.Entities; | ||
|
||
namespace Dfe.EarlyYearsQualification.Content.Services; | ||
|
||
public interface IContentService | ||
{ | ||
Task<LandingPage> GetLandingPage(); | ||
} |
20 changes: 19 additions & 1 deletion
20
src/Dfe.EarlyYearsQualification.Web/Controllers/HomeController.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
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
10 changes: 10 additions & 0 deletions
10
src/Dfe.EarlyYearsQualification.Web/Models/Content/LandingPageModel.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,10 @@ | ||
namespace Dfe.EarlyYearsQualification.Web.Models.Content; | ||
|
||
public class LandingPageModel | ||
{ | ||
public string Header { get; set; } = string.Empty; | ||
|
||
public string ServiceIntroduction { get; set; } = string.Empty; | ||
|
||
public string StartButtonText { get; set; } = string.Empty; | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/Dfe.EarlyYearsQualification.Web/Views/Home/Content.cshtml
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 @@ | ||
@model Dfe.EarlyYearsQualification.Web.Models.Content.LandingPageModel | ||
|
||
@{ | ||
ViewData["Title"] = "Content Page"; | ||
} | ||
|
||
<div class="text-center"> | ||
<h1 class="display-4">@Model.Header</h1> | ||
@Html.Raw(Model.ServiceIntroduction) | ||
<button>@Model.StartButtonText</button> | ||
</div> |
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