Skip to content

Commit

Permalink
Refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
JPVenson committed Aug 1, 2022
1 parent fa75b3b commit 3458fc4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
24 changes: 13 additions & 11 deletions Morestachio/Document/Custom/BlockDocumentItemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ public class BlockDocumentItem : BlockValueDocumentItemBase
/// </summary>
public BlockDocumentItem()
{

}

/// <inheritdoc />
public BlockDocumentItem(TextRange location,
BlockDocumentProviderFunction action,
public BlockDocumentItem(TextRange location,
BlockDocumentProviderFunction action,
string value,
IEnumerable<ITokenOption> tagCreationOptions) : base(location, value, tagCreationOptions)
IEnumerable<ITokenOption> tagCreationOptions) : base(location, value,
tagCreationOptions)
{
_action = action;
}

/// <inheritdoc />
public override async ItemExecutionPromise Render(IByteCounterStream outputStream, ContextObject context, ScopeData scopeData)
public override async ItemExecutionPromise Render(IByteCounterStream outputStream,
ContextObject context,
ScopeData scopeData)
{
return await _action(outputStream, context, scopeData, Value, Children).ConfigureAwait(false);
//return Array.Empty<DocumentItemExecution>();
Expand All @@ -67,11 +69,11 @@ public override void Accept(IDocumentItemVisitor visitor)
}

/// <inheritdoc />
public override IBlockDocumentItem CreateDocumentItem(string tag,
string value,
TokenPair token,
ParserOptions options,
IEnumerable<ITokenOption> tagCreationOptions)
public override IBlockDocumentItem CreateDocumentItem(string tag,
string value,
TokenPair token,
ParserOptions options,
IEnumerable<ITokenOption> tagCreationOptions)
{
return new BlockDocumentItem(token.TokenRange, _action, value, tagCreationOptions);
}
Expand Down
18 changes: 13 additions & 5 deletions Morestachio/Document/Custom/BlockDocumentItemProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class BlockDocumentItemProviderBase : CustomDocumentItemProvider
/// </summary>
protected readonly string TagOpen;


/// <summary>
/// Defines the closing tag
/// </summary>
Expand Down Expand Up @@ -46,29 +46,36 @@ public abstract IBlockDocumentItem CreateDocumentItem(string tag,
public override IEnumerable<TokenPair> Tokenize(TokenInfo token, ParserOptions options)
{
var trim = token.Token;

if (trim == TagOpen)
{
yield return new TokenPair(TagOpen, trim, token.Location);
}

if (trim == TagClose)
{
yield return new TokenPair(TagClose, trim, token.Location);
}
}

/// <inheritdoc />
public override bool ShouldParse(TokenPair token, ParserOptions options, IEnumerable<ITokenOption> tagCreationOptions)
public override bool ShouldParse(TokenPair token,
ParserOptions options,
IEnumerable<ITokenOption> tagCreationOptions)
{
return token.Type.Equals(TagOpen.Trim()) || token.Type.Equals(TagClose);
}

/// <inheritdoc />
public override IDocumentItem Parse(TokenPair token, ParserOptions options, Stack<DocumentScope> buildStack,
Func<int> getScope, IEnumerable<ITokenOption> tagCreationOptions)
public override IDocumentItem Parse(TokenPair token,
ParserOptions options,
Stack<DocumentScope> buildStack,
Func<int> getScope,
IEnumerable<ITokenOption> tagCreationOptions)
{
if (Equals(token.Type, TagOpen.Trim()))
{
var blockDocumentItem = CreateDocumentItem(TagOpen,
var blockDocumentItem = CreateDocumentItem(TagOpen,
token.Value?.Remove(0, TagOpen.Length).Trim(),
token, options, tagCreationOptions);
blockDocumentItem.BlockLocation = token.TokenRange;
Expand All @@ -80,6 +87,7 @@ public override IDocumentItem Parse(TokenPair token, ParserOptions options, Stac
{
buildStack.Pop();
}

return null;
}

Expand Down

0 comments on commit 3458fc4

Please sign in to comment.