Skip to content

Commit

Permalink
Merge pull request #5 from Toine-db/improved_naming
Browse files Browse the repository at this point in the history
Naming for IViewSupplier improved, more intuitive
  • Loading branch information
Toine-db authored Nov 27, 2024
2 parents 80b4492 + 4556d6c commit e3a86bf
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
30 changes: 15 additions & 15 deletions src/MarkdownParser/IViewSupplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ namespace MarkdownParser
public interface IViewSupplier<T>
{
/// <summary>
/// registering reference definitions (sometimes at the end of the document or used for creating links)
/// reference definitions are known, triggered before first view is created (reference definitions are sometimes placed at the end of the document or used for creating links)
/// </summary>
/// <param name="markdownReferenceDefinitions">collection of Reference Definitions</param>
/// <returns></returns>
void RegisterReferenceDefinitions(IEnumerable<MarkdownReferenceDefinition> markdownReferenceDefinitions);
void OnReferenceDefinitionsPublished(IEnumerable<MarkdownReferenceDefinition> markdownReferenceDefinitions);

/// <summary>
/// a default text view
/// </summary>
/// <param name="textBlock">textBlock with a collection of text segments</param>
/// <returns></returns>
T GetTextView(TextBlock textBlock);
T CreateTextView(TextBlock textBlock);

/// <summary>
/// a block quote view, where other views can be inserted
/// </summary>
/// <param name="childView"></param>
/// <returns></returns>
T GetBlockquotesView(T childView);
T CreateBlockquotesView(T childView);

/// <summary>
/// a title, subtitle or header view
/// </summary>
/// <param name="textBlock">textBlock with a collection of text segments</param>
/// <param name="headerLevel">header level</param>
/// <returns></returns>
T GetHeaderView(TextBlock textBlock, int headerLevel);
T CreateHeaderView(TextBlock textBlock, int headerLevel);

/// <summary>
/// a image view with an optional subscription text view
Expand All @@ -41,61 +41,61 @@ public interface IViewSupplier<T>
/// <param name="subscription">(optional) null or empty when not used</param>
/// <param name="imageId">(optional) id for image</param>
/// <returns></returns>
T GetImageView(string url, string subscription, string imageId);
T CreateImageView(string url, string subscription, string imageId);

/// <summary>
/// a view that shows a list of list-items
/// </summary>
/// <param name="items"></param>
/// <returns></returns>
T GetListView(List<T> items);
T CreateListView(List<T> items);

/// <summary>
/// a view that shows a single item for a ListView (return View can be used in GetListView)
/// a view that shows a single item for a ListView (return View can be used in CreateListView)
/// </summary>
/// <param name="childView">view as child-view (or use the content parameter)</param>
/// <param name="isOrderedList">does the item belong to a ordered (numbered) list</param>
/// <param name="sequenceNumber">number of sequence</param>
/// <param name="listLevel">level depth of the list, root level starting at 1</param>
/// <returns></returns>
T GetListItemView(T childView, bool isOrderedList, int sequenceNumber, int listLevel);
T CreateListItemView(T childView, bool isOrderedList, int sequenceNumber, int listLevel);

/// <summary>
/// a layout that shows a collection of views
/// </summary>
/// <param name="childViews">collection of views</param>
/// <returns></returns>
T GetStackLayoutView(List<T> childViews);
T CreateStackLayoutView(List<T> childViews);

/// <summary>
/// an image view that separates content
/// </summary>
/// <returns></returns>
T GetThematicBreak();
T CreateThematicBreak();

/// <summary>
/// a placeholder for views or other objects
/// </summary>
/// <param name="placeholderName">placeholder string</param>
/// <returns></returns>
T GetPlaceholder(string placeholderName);
T CreatePlaceholder(string placeholderName);

/// <summary>
/// a view that shows fenced code (found in MD blocks starting with ```cs )
/// </summary>
/// <returns></returns>
T GetFencedCodeBlock(TextBlock textBlock, string codeInfo);
T CreateFencedCodeBlock(TextBlock textBlock, string codeInfo);

/// <summary>
/// a view that shows indented code (found in MD lines starting with at least 4 spaces)
/// </summary>
/// <returns></returns>
T GetIndentedCodeBlock(TextBlock textBlock);
T CreateIndentedCodeBlock(TextBlock textBlock);

/// <summary>
/// a view that shows html content
/// </summary>
/// <returns></returns>
T GetHtmlBlock(TextBlock textBlock);
T CreateHtmlBlock(TextBlock textBlock);
}
}
28 changes: 14 additions & 14 deletions src/MarkdownParser/Writer/ViewWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void RegisterReferenceDefinitions(Dictionary<string, Reference> reference
});
}

ViewSupplier.RegisterReferenceDefinitions(markdownReferenceDefinition);
ViewSupplier.OnReferenceDefinitionsPublished(markdownReferenceDefinition);
}

public void StartBlock(BlockTag blockType)
Expand All @@ -90,7 +90,7 @@ public void FinalizeParagraphBlock()
foreach (var itemsCacheTuple in itemsCache)
{
var view = itemsCacheTuple.TextBlock != null
? ViewSupplier.GetTextView(itemsCacheTuple.TextBlock)
? ViewSupplier.CreateTextView(itemsCacheTuple.TextBlock)
: itemsCacheTuple.Value;

if (view != null)
Expand All @@ -117,7 +117,7 @@ public void FinalizeBlockquoteBlock()
var childViews = itemsCache.Select(itemsCacheTuple => itemsCacheTuple.Item2).ToList();
var childView = StackViews(childViews);

var blockView = ViewSupplier.GetBlockquotesView(childView);
var blockView = ViewSupplier.CreateBlockquotesView(childView);

StoreView(blockView);
}
Expand All @@ -140,7 +140,7 @@ public void FinalizeHeaderBlock(int headerLevel)
foreach (var itemsCacheTuple in itemsCache)
{
var view = itemsCacheTuple.TextBlock != null
? ViewSupplier.GetHeaderView(itemsCacheTuple.TextBlock, headerLevel)
? ViewSupplier.CreateHeaderView(itemsCacheTuple.TextBlock, headerLevel)
: itemsCacheTuple.Value;

views.Add(view);
Expand All @@ -162,7 +162,7 @@ public void FinalizeListBlock()
var itemsCache = topWorkbenchItem.FlushCache();

var listItems = itemsCache.Select(itemsCacheTuple => itemsCacheTuple.Item2).ToList();
var listView = ViewSupplier.GetListView(listItems);
var listView = ViewSupplier.CreateListView(listItems);

StoreView(listView);
}
Expand All @@ -188,7 +188,7 @@ public void FinalizeListItemBlock(ListData listData)
foreach (var itemsCacheTuple in itemsCache)
{
var view = itemsCacheTuple.TextBlock != null
? ViewSupplier.GetTextView(itemsCacheTuple.TextBlock)
? ViewSupplier.CreateTextView(itemsCacheTuple.TextBlock)
: itemsCacheTuple.Value;

if (view != null)
Expand All @@ -199,7 +199,7 @@ public void FinalizeListItemBlock(ListData listData)

var flattenedView = StackViews(views);

var listItemView = ViewSupplier.GetListItemView(flattenedView, isOrderedList, sequenceNumber, depthLevel);
var listItemView = ViewSupplier.CreateListItemView(flattenedView, isOrderedList, sequenceNumber, depthLevel);

StoreView(listItemView);
}
Expand Down Expand Up @@ -250,43 +250,43 @@ public void AddEmphasis(Inline inline, int firstCharacterPosition, int length)

public void StartAndFinalizeImageBlock(string targetUrl, string subscription, string imageId)
{
var imageView = ViewSupplier.GetImageView(targetUrl, subscription, imageId);
var imageView = ViewSupplier.CreateImageView(targetUrl, subscription, imageId);
StoreView(imageView);
}

public void StartAndFinalizeFencedCodeBlock(StringContent content, string blockInfo)
{
var blocks = StringContentToBlocks(content);

var blockView = ViewSupplier.GetFencedCodeBlock(blocks, blockInfo);
var blockView = ViewSupplier.CreateFencedCodeBlock(blocks, blockInfo);
StoreView(blockView);
}

public void StartAndFinalizeIndentedCodeBlock(StringContent content)
{
var blocks = StringContentToBlocks(content);

var blockView = ViewSupplier.GetIndentedCodeBlock(blocks);
var blockView = ViewSupplier.CreateIndentedCodeBlock(blocks);
StoreView(blockView);
}

public void StartAndFinalizeHtmlBlock(StringContent content)
{
var blocks = StringContentToBlocks(content);

var blockView = ViewSupplier.GetHtmlBlock(blocks);
var blockView = ViewSupplier.CreateHtmlBlock(blocks);
StoreView(blockView);
}

public void StartAndFinalizeThematicBreak()
{
var separator = ViewSupplier.GetThematicBreak();
var separator = ViewSupplier.CreateThematicBreak();
StoreView(separator);
}

public void StartAndFinalizePlaceholderBlock(string placeholderName)
{
var placeholderView = ViewSupplier.GetPlaceholder(placeholderName);
var placeholderView = ViewSupplier.CreatePlaceholder(placeholderName);
StoreView(placeholderView);
}

Expand All @@ -301,7 +301,7 @@ private T StackViews(List<T> views)
// multiple views combine a single stack layout
var viewToStore = views.Count == 1
? views[0]
: ViewSupplier.GetStackLayoutView(views);
: ViewSupplier.CreateStackLayoutView(views);

return viewToStore;
}
Expand Down
26 changes: 13 additions & 13 deletions test/MarkdownParser.Test/Mocks/PassThroughComponentSupplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,67 @@ internal class PassThroughComponentSupplier : IViewSupplier<object>
{
public MarkdownReferenceDefinition[]? MarkdownReferenceDefinitions { get; private set; }

public void RegisterReferenceDefinitions(IEnumerable<MarkdownReferenceDefinition> markdownReferenceDefinitions)
public void OnReferenceDefinitionsPublished(IEnumerable<MarkdownReferenceDefinition> markdownReferenceDefinitions)
{
MarkdownReferenceDefinitions = markdownReferenceDefinitions.ToArray();
}

public object GetTextView(TextBlock textBlock)
public object CreateTextView(TextBlock textBlock)
{
return textBlock;
}

public object GetBlockquotesView(object childView)
public object CreateBlockquotesView(object childView)
{
return childView;
}

public object GetHeaderView(TextBlock textBlock, int headerLevel)
public object CreateHeaderView(TextBlock textBlock, int headerLevel)
{
return textBlock;
}

public object GetImageView(string url, string subscription, string imageId)
public object CreateImageView(string url, string subscription, string imageId)
{
return url;
}

public object GetListView(List<object> items)
public object CreateListView(List<object> items)
{
return items;
}

public object GetListItemView(object childView, bool isOrderedList, int sequenceNumber, int listLevel)
public object CreateListItemView(object childView, bool isOrderedList, int sequenceNumber, int listLevel)
{
return childView;
}

public object GetStackLayoutView(List<object> childViews)
public object CreateStackLayoutView(List<object> childViews)
{
return childViews;
}

public object GetThematicBreak()
public object CreateThematicBreak()
{
return "ThematicBreak";
}

public object GetPlaceholder(string placeholderName)
public object CreatePlaceholder(string placeholderName)
{
return placeholderName;
}

public object GetFencedCodeBlock(TextBlock textBlock, string codeInfo)
public object CreateFencedCodeBlock(TextBlock textBlock, string codeInfo)
{
return textBlock;
}

public object GetIndentedCodeBlock(TextBlock textBlock)
public object CreateIndentedCodeBlock(TextBlock textBlock)
{
return textBlock;
}

public object GetHtmlBlock(TextBlock textBlock)
public object CreateHtmlBlock(TextBlock textBlock)
{
return textBlock;
}
Expand Down
Loading

0 comments on commit e3a86bf

Please sign in to comment.