-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DisplayAsync to return actual pre-rendered IHtmlContent #15247
Changes from 7 commits
7d458a8
eb7a1f0
6bfff18
01f86e9
72b54e8
6fb8f0e
47ddfa1
4f14544
0393d53
e42fac8
82645d9
b331411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.Encodings.Web; | ||
|
@@ -8,7 +9,7 @@ | |
|
||
namespace OrchardCore.DisplayManagement | ||
{ | ||
public class PositionWrapper : IHtmlContent, IPositioned, IShape | ||
public sealed class PositionWrapper : IHtmlContent, IPositioned, IShape | ||
{ | ||
private readonly IHtmlContent _value; | ||
public string Position { get; set; } | ||
|
@@ -29,13 +30,13 @@ public class PositionWrapper : IHtmlContent, IPositioned, IShape | |
|
||
public IReadOnlyList<IPositioned> Items => throw new System.NotImplementedException(); | ||
|
||
public PositionWrapper(IHtmlContent value, string position) | ||
private PositionWrapper(IHtmlContent value, string position) | ||
{ | ||
_value = value; | ||
Position = position; | ||
} | ||
|
||
public PositionWrapper(string value, string position) | ||
private PositionWrapper(string value, string position) | ||
{ | ||
_value = new HtmlContentString(value); | ||
Position = position; | ||
|
@@ -50,5 +51,24 @@ public ValueTask<IShape> AddAsync(object item, string position) | |
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public static PositionWrapper TryWrap(object value, string position) | ||
{ | ||
if (value is PositionWrapper wrapper) | ||
{ | ||
// Update the new Position | ||
wrapper.Position = position; | ||
return wrapper; | ||
} | ||
else if (value is IHtmlContent content) | ||
return new PositionWrapper(content, position); | ||
else if (value is string stringContent) | ||
return new PositionWrapper(stringContent, position); | ||
else | ||
throw new System.NotSupportedException($"Type of {nameof(value)} must be either {nameof(String)}, {nameof(IHtmlContent)} or {nameof(PositionWrapper)}."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it unwrap if the position is "" ? Is that the meaning of "" in ThemeLayout.cs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's default, I believe when empty it will sort based on the order of items added
Throwing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to return null instead of throwing exception |
||
} | ||
|
||
public static IHtmlContent UnWrap(PositionWrapper wrapper) | ||
=> wrapper._value; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,13 +65,13 @@ public virtual ValueTask<IShape> AddAsync(object item, string position) | |
|
||
_items ??= []; | ||
|
||
if (item is IHtmlContent) | ||
if (item is IHtmlContent htmlContent) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't this whole if/else/else be a single TryWrap? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
{ | ||
_items.Add(new PositionWrapper((IHtmlContent)item, position)); | ||
_items.Add(PositionWrapper.TryWrap(htmlContent, position)); | ||
} | ||
else if (item is string) | ||
else if (item is string stringContent) | ||
{ | ||
_items.Add(new PositionWrapper((string)item, position)); | ||
_items.Add(PositionWrapper.TryWrap(stringContent, position)); | ||
} | ||
else | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is IPositioned
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used
PositionWrapper
because return value must be bothIPositioned
andIShape