Skip to content

Commit

Permalink
fixes #265
Browse files Browse the repository at this point in the history
  • Loading branch information
petrsvihlik committed Feb 7, 2021
1 parent c136595 commit 11eee9d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,5 @@ namespace Kentico.Kontent.Delivery.Abstractions
/// </summary>
public interface IRichTextContent : IEnumerable<IRichTextBlock>
{
/// <summary>
/// List of rich text content blocks
/// </summary>
IEnumerable<IRichTextBlock> Blocks { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class Article
public const string TitleCodename = "title";
public const string UrlPatternCodename = "url_pattern";

public string BodyCopy { get; set; }
public IRichTextContent BodyCopy { get; set; }
public string MetadataMetaDescription { get; set; }
public string MetadataMetaTitle { get; set; }
public string MetadataOgDescription { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions Kentico.Kontent.Delivery.Tests/ValueConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public async void RichTextViaValueConverter()
// Try to get recursive linked items on_roasts -> item -> on_roasts
var article = await client.GetItemAsync<Article>("coffee_beverages_explained", new DepthParameter(15));

var hostedVideo = article.Item.BodyCopyRichText.Blocks.FirstOrDefault(b => (b as IInlineContentItem)?.ContentItem is HostedVideo);
var tweet = article.Item.BodyCopyRichText.Blocks.FirstOrDefault(b => (b as IInlineContentItem)?.ContentItem is Tweet);
var hostedVideo = article.Item.BodyCopyRichText.FirstOrDefault(b => (b as IInlineContentItem)?.ContentItem is HostedVideo);
var tweet = article.Item.BodyCopyRichText.FirstOrDefault(b => (b as IInlineContentItem)?.ContentItem is Tweet);

Assert.NotNull(hostedVideo);
Assert.NotNull(tweet);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;
using Newtonsoft.Json;

namespace Kentico.Kontent.Delivery.ContentItems.RichText.Blocks
{
/// <summary>
/// Represents inline content item. IEnumerable is implemented so that Html.DisplayFor is automatically bridged to the underlying ContentItem property.
/// </summary>
internal class InlineContentItem : IInlineContentItem, IEnumerable<object>
internal class InlineContentItem : List<object>, IInlineContentItem
{
public object ContentItem
{
get;
get
{
return this[0];
}
}

public InlineContentItem(object contentItem)
[JsonConstructor]
private InlineContentItem()
{
ContentItem = contentItem;
}

public IEnumerator<object> GetEnumerator()
{
yield return ContentItem;
}

IEnumerator IEnumerable.GetEnumerator()
public InlineContentItem(object contentItem)
{
yield return ContentItem;
Add(contentItem);
}
}
}
25 changes: 5 additions & 20 deletions Kentico.Kontent.Delivery/ContentItems/RichText/RichTextContent.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;
using Newtonsoft.Json;

namespace Kentico.Kontent.Delivery.ContentItems.RichText
{
internal class RichTextContent : IRichTextContent
internal class RichTextContent : List<IRichTextBlock>, IRichTextContent
{
public IEnumerable<IRichTextBlock> Blocks
[JsonConstructor]
public RichTextContent()
{
get;
}

public RichTextContent(IEnumerable<IRichTextBlock> blocks)
{
Blocks = blocks;
}

public IEnumerator<IRichTextBlock> GetEnumerator()
{
return Blocks.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return Blocks.GetEnumerator();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task<object> GetPropertyValueAsync<TElement>(PropertyInfo property,
value = await new ContentLinkResolver(context.ContentLinkUrlResolver).ResolveContentLinksAsync(value, links);
}

var blocks = new List<IRichTextBlock>();
var blocks = new RichTextContent();
var htmlInput = await Parser.ParseDocumentAsync(value);
foreach (var block in htmlInput.Body.Children)
{
Expand All @@ -65,7 +65,7 @@ public async Task<object> GetPropertyValueAsync<TElement>(PropertyInfo property,
}
}

return new RichTextContent(blocks);
return blocks;
}
}
}

0 comments on commit 11eee9d

Please sign in to comment.