Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Expose text/textlist in generators #1250

Merged
merged 2 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ protected ScopeBody(string declaration = null) : base(declaration)
{
}

public void Text(Text text)
{
Add(text);
}

public void TextList(TextList textList)
{
Add(textList);
}

public void Line(string snippet)
{
Add(new Text(snippet));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public AnnotationOutsideType Annotate(string annotation)
return new AnnotationOutsideType(this, annotation);
}

public void Text(Text text)
{
Add(text);
}

public void TextList(TextList textList)
{
Add(textList);
}

public void Line(string snippet)
{
Add(new Text(snippet));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public AnnotationInsideType Annotate(string annotation)
return new AnnotationInsideType(this, annotation);
}

public void Text(Text text)
{
Add(text);
}

public void TextList(TextList textList)
{
Add(textList);
}

public void Line(string snippet)
{
Add(new Text(snippet));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Improbable.Gdk.CodeGeneration.CodeWriter
/// <summary>
/// Free-form text to write.
/// </summary>
internal class Text : ICodeBlock
public class Text : ICodeBlock
{
private readonly string snippet;

Expand All @@ -15,6 +15,11 @@ internal Text(string snippet, bool trim = true)
this.snippet = trim ? snippet.Trim() : snippet;
}

public static Text New(string snippet)
{
return new Text(snippet);
}

public bool HasValue()
{
return !string.IsNullOrEmpty(snippet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Improbable.Gdk.CodeGeneration.CodeWriter
/// <summary>
/// A grouping of un-trimmed text to be on consecutive lines.
/// </summary>
internal class TextList : ICodeBlock
public class TextList : ICodeBlock
{
private readonly string snippetListSeparator;

Expand All @@ -26,6 +26,16 @@ internal TextList(string separator, IEnumerable<string> snippets)
Add(snippets);
}

public static TextList New(IEnumerable<string> snippets)
{
return new TextList(snippets);
}

public static TextList New(string separator, IEnumerable<string> snippets)
{
return new TextList(separator, snippets);
}

private void Add(IEnumerable<string> snippets)
{
textBlocks.AddRange(snippets.Select(s => new Text(s, trim: false)));
Expand Down