-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from StuffOfInterest/feature-do
Feature do
- Loading branch information
Showing
9 changed files
with
135 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,5 +33,10 @@ public IActionResult TestFor() | |
{ | ||
return View(); | ||
} | ||
|
||
public IActionResult TestDo() | ||
{ | ||
return View(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h2>Test 1</h2> | ||
|
||
@{ var x = 0; } | ||
<do condition="() => x < 10"> | ||
@{ x++; } | ||
<p>Should display @x.</p> | ||
</do> | ||
|
||
<h2>Test 2</h2> | ||
|
||
@try | ||
{ | ||
<do> | ||
<p>Should not display.</p> | ||
</do> | ||
} | ||
catch (Exception ex) | ||
{ | ||
<p>Expected exception occurred: '@ex.Message'.</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
|
||
namespace LogicTagHelpers | ||
{ | ||
/// <summary> | ||
/// Do loop render block of code until condition is no longer met. | ||
/// </summary> | ||
public class DoTagHelper : TagHelper | ||
{ | ||
/// <summary> | ||
/// Function to evaluate exit condition. | ||
/// Inner content will render as long as the condition returns true. | ||
/// </summary> | ||
public Func<bool> Condition { get; set; } | ||
|
||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
if (Condition == null) | ||
{ | ||
throw new LogicTagHelperException("Condition may not be null."); | ||
} | ||
|
||
output.TagName = null; | ||
output.Content.Clear(); | ||
|
||
do | ||
{ | ||
var childContent = await output.GetChildContentAsync(false); | ||
output.Content.AppendHtml(childContent); | ||
} while (Condition.Invoke()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters