-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ExcludeGenerator to exclude DocItem from the documentation gene…
…ration based on regex (closes #160)
- Loading branch information
Showing
5 changed files
with
59 additions
and
6 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
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
45 changes: 45 additions & 0 deletions
45
source/DefaultDocumentation.Markdown/DocItemGenerators/ExcludeGenerator.cs
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,45 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using DefaultDocumentation.Api; | ||
using DefaultDocumentation.Models; | ||
|
||
namespace DefaultDocumentation.Markdown.DocItemGenerators; | ||
|
||
/// <summary> | ||
/// Implementation of the <see cref="IDocItemGenerator"/> to remove <see cref="DocItem"/> from the documentation generation based on <see href="https://github.com/Doraku/DefaultDocumentation#MarkdownConfiguration_Exclude">Markdown.Exclude</see>. | ||
/// </summary> | ||
public sealed class ExcludeGenerator : IDocItemGenerator | ||
{ | ||
/// <summary> | ||
/// The name of this implementation used at the configuration level. | ||
/// </summary> | ||
public const string ConfigName = "Exclude"; | ||
|
||
/// <inheritdoc/> | ||
public string Name => ConfigName; | ||
|
||
/// <inheritdoc/> | ||
public void Generate(IDocItemsContext context) | ||
{ | ||
context.ThrowIfNull(); | ||
|
||
void Remove(DocItem item) | ||
{ | ||
context.Items.Remove(item.Id); | ||
context.ItemsWithOwnPage.Remove(item); | ||
|
||
foreach (DocItem child in context.Items.Values.Where(child => child.Parent == item).ToArray()) | ||
{ | ||
Remove(child); | ||
} | ||
} | ||
|
||
foreach (DocItem item in (context.GetSetting<string[]>("Markdown.Exclude") ?? []) | ||
.SelectMany(regex => context.Items.Values.Where(item => Regex.IsMatch(item.Id, regex))) | ||
.ToArray()) | ||
{ | ||
Remove(item); | ||
} | ||
} | ||
} |