refactor!: renamed GetText to GetTextContentString

This commit is contained in:
D. Moonfire 2023-01-15 12:43:42 -06:00
parent a8c6d0e582
commit c5c9b8bf9c
11 changed files with 37 additions and 21 deletions

View file

@ -21,7 +21,7 @@ public class IdentifyHandlebarsFromContent : IOperation
Entity entity,
ITextContent content)
{
string text = content.GetText();
string text = content.GetTextContentString();
if (text.Contains("{{") && text.Contains("}}"))
{

View file

@ -51,7 +51,7 @@ public partial class RenderContentTemplate : OperationBase
HasHandlebarsTemplate _,
ITextContent content)
{
string text = content.GetText();
string text = content.GetTextContentString();
HandlebarsTemplate<object, object> template =
this.cache.GetLiteralTemplate(text);
object model = this.CreateModelCallback!(entity);

View file

@ -22,7 +22,7 @@ public class ConvertHtmlEntitiesToUnicode : OperationBase
Entity entity,
ITextContent content)
{
string text = content.GetText();
string text = content.GetTextContentString();
string resolved = WebUtility.HtmlDecode(text);
return entity.SetTextContent(resolved);

View file

@ -44,7 +44,7 @@ public class ConvertMarkdownToGemtext : ConvertMarkdownToBase
ITextContent markdownContent,
MarkdownPipeline options)
{
string markdown = markdownContent.GetText();
string markdown = markdownContent.GetTextContentString();
string gemtext = MarkdownGemtext.ToGemtext(markdown, options);
var content = new StringTextContent(gemtext);

View file

@ -43,7 +43,7 @@ public class ConvertMarkdownToHtml : ConvertMarkdownToBase
MarkdownPipeline options)
{
// Convert the entity to Html.
string markdown = markdownContent.GetText();
string markdown = markdownContent.GetTextContentString();
string html = Markdig.Markdown.ToHtml(markdown, options);
var htmlContent = new StringTextContent(html);

View file

@ -38,7 +38,7 @@ public class MakeSingleLinkListItems : IOperation
/// </summary>
private Entity MakeSingleLinkLists(Entity entity)
{
string content = entity.GetText()!;
string content = entity.GetTextContentString()!;
string output = Regex.Replace(
content,

View file

@ -32,7 +32,7 @@ public static class NitrideYamlEntityExtensions
this Entity entity,
IDeserializer deserializer)
{
string? text = entity.GetText();
string? text = entity.GetTextContentString();
return text != null
? deserializer.Deserialize<TType>(text)

View file

@ -1,3 +1,5 @@
using System.Text;
using MfGames.Gallium;
namespace MfGames.Nitride.Contents;
@ -41,7 +43,6 @@ public static class EntityTextContentExtensions
/// </summary>
/// <param name="entity">The entity to query and modify.</param>
/// <param name="content">The content to add to the entity.</param>
/// <typeparam name="TType">The base type of the content.</typeparam>
/// <returns>The entity or a copy with the new component.</returns>
public static Entity SetTextContent(
this Entity entity,
@ -49,4 +50,19 @@ public static class EntityTextContentExtensions
{
return entity.SetTextContent(new StringTextContent(content));
}
/// <summary>
/// Remove all existing content components from the entity and then adds
/// the new text content as a component into the entity before
/// returning it.
/// </summary>
/// <param name="entity">The entity to query and modify.</param>
/// <param name="content">The content to add to the entity.</param>
/// <returns>The entity or a copy with the new component.</returns>
public static Entity SetTextContent(
this Entity entity,
StringBuilder content)
{
return entity.SetTextContent(content.ToString());
}
}

View file

@ -6,7 +6,7 @@ namespace MfGames.Nitride.Contents;
public static class TextContentExtensions
{
public static string GetText(this ITextContent content)
public static string GetTextContentString(this ITextContent content)
{
var writer = new StringWriter();
using TextReader reader = content.GetReader();
@ -21,28 +21,28 @@ public static class TextContentExtensions
return writer.ToString();
}
public static string? GetText(this IBinaryContent content)
public static string? GetTextContentString(this IBinaryContent content)
{
if (content is ITextContentConvertable convertableContent)
{
return convertableContent
.ToTextContent()
.GetText();
.GetTextContentString();
}
return null;
}
public static string? GetText(this Entity entity)
public static string? GetTextContentString(this Entity entity)
{
if (entity.TryGet(out ITextContent textContent))
{
return textContent.GetText();
return textContent.GetTextContentString();
}
if (entity.TryGet(out IBinaryContent binaryContent))
{
return binaryContent.GetText();
return binaryContent.GetTextContentString();
}
return null;

View file

@ -34,7 +34,7 @@ public class MakeSingleLinkListItemsTests : TestBase<MarkdownTestContext>
MakeSingleLinkListItems?
op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetText()!.Trim();
string content = output.First().GetTextContentString()!.Trim();
Assert.Equal("- [Empty](link)", content);
}
@ -53,7 +53,7 @@ public class MakeSingleLinkListItemsTests : TestBase<MarkdownTestContext>
MakeSingleLinkListItems?
op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetText()!.Trim();
string content = output.First().GetTextContentString()!.Trim();
Assert.Equal("- [Empty space](link)", content);
}
@ -72,7 +72,7 @@ public class MakeSingleLinkListItemsTests : TestBase<MarkdownTestContext>
MakeSingleLinkListItems?
op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetText()!.Trim();
string content = output.First().GetTextContentString()!.Trim();
Assert.Equal("- Empty", content);
}
@ -91,7 +91,7 @@ public class MakeSingleLinkListItemsTests : TestBase<MarkdownTestContext>
MakeSingleLinkListItems?
op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetText()!.Trim();
string content = output.First().GetTextContentString()!.Trim();
Assert.Equal("- [Empty space](link)", content);
}

View file

@ -39,7 +39,7 @@ public class ParseYamlHeaderTest : NitrideTestBase
string.Empty,
},
output.Get<ITextContent>()
.GetText()
.GetTextContentString()
.Split("\n"));
Assert.True(output.Has<TestHeader>());
@ -72,7 +72,7 @@ public class ParseYamlHeaderTest : NitrideTestBase
string.Empty,
},
output.Get<ITextContent>()
.GetText()
.GetTextContentString()
.Split("\n"));
Assert.True(output.Has<TestHeader>());
@ -109,7 +109,7 @@ public class ParseYamlHeaderTest : NitrideTestBase
string.Empty,
},
output.Get<ITextContent>()
.GetText()
.GetTextContentString()
.Split("\n"));
Assert.True(output.Has<TestHeader>());