Skip to content

Commit 26e6343

Browse files
committed
Reorganize Elastic.Markdown so that code is grouped by purpose not type
1 parent afcce69 commit 26e6343

File tree

88 files changed

+420
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+420
-319
lines changed

src/Elastic.Markdown/Slices/DescriptionGenerator.cs renamed to src/Elastic.Markdown/DescriptionGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Markdig.Syntax;
88
using Markdig.Syntax.Inlines;
99

10-
namespace Elastic.Markdown.Slices;
10+
namespace Elastic.Markdown;
1111

1212
public interface IDescriptionGenerator
1313
{

src/Elastic.Markdown/DocumentationGenerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using Elastic.Markdown.Exporters;
1616
using Elastic.Markdown.IO;
1717
using Elastic.Markdown.Links.CrossLinks;
18-
using Elastic.Markdown.Slices;
1918
using Markdig.Syntax;
2019
using Microsoft.Extensions.Logging;
2120

src/Elastic.Markdown/Exporters/DocumentationFileExporter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.IO.Abstractions;
66
using Elastic.Documentation.Configuration;
77
using Elastic.Markdown.IO;
8-
using Elastic.Markdown.Slices;
98
using Markdig.Syntax;
109

1110
namespace Elastic.Markdown.Exporters;

src/Elastic.Markdown/Slices/HtmlWriter.cs renamed to src/Elastic.Markdown/HtmlWriter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
using Elastic.Documentation.Site.Navigation;
1111
using Elastic.Markdown.Extensions.DetectionRules;
1212
using Elastic.Markdown.IO;
13+
using Elastic.Markdown.Page;
1314
using Markdig.Syntax;
1415
using RazorSlices;
1516
using IFileInfo = System.IO.Abstractions.IFileInfo;
1617

17-
namespace Elastic.Markdown.Slices;
18+
namespace Elastic.Markdown;
1819

1920
public class HtmlWriter(
2021
DocumentationSet documentationSet,
@@ -99,7 +100,7 @@ private async Task<string> RenderLayout(MarkdownFile markdown, MarkdownDocument
99100
if (PositionalNavigation.MarkdownNavigationLookup.TryGetValue("docs-content://versions.md", out var item))
100101
allVersionsUrl = item.Url;
101102

102-
var slice = Index.Create(new IndexViewModel
103+
var slice = Page.Index.Create(new IndexViewModel
103104
{
104105
SiteName = siteName,
105106
DocSetName = DocumentationSet.Name,

src/Elastic.Markdown/IO/DocumentationFile.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Elastic.Documentation.Site;
66
using Elastic.Markdown.Myst;
77
using Elastic.Markdown.Myst.FrontMatter;
8-
using Elastic.Markdown.Slices;
98

109
namespace Elastic.Markdown.IO;
1110

src/Elastic.Markdown/IO/MarkdownFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
using Elastic.Markdown.Links.CrossLinks;
1414
using Elastic.Markdown.Myst;
1515
using Elastic.Markdown.Myst.Directives;
16+
using Elastic.Markdown.Myst.Directives.Include;
1617
using Elastic.Markdown.Myst.FrontMatter;
1718
using Elastic.Markdown.Myst.InlineParsers;
18-
using Elastic.Markdown.Slices;
1919
using Markdig;
2020
using Markdig.Extensions.Yaml;
2121
using Markdig.Renderers.Roundtrip;

src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information
44

55
using System.Diagnostics;
6-
using System.Diagnostics.CodeAnalysis;
76
using Elastic.Documentation;
87
using Elastic.Documentation.Configuration;
98
using Elastic.Documentation.Configuration.TableOfContents;
@@ -12,84 +11,6 @@
1211

1312
namespace Elastic.Markdown.IO.Navigation;
1413

15-
[DebuggerDisplay("Current: {Model.RelativePath}")]
16-
public record FileNavigationItem(MarkdownFile Model, DocumentationGroup Group, bool Hidden = false) : ILeafNavigationItem<MarkdownFile>
17-
{
18-
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; } = Group;
19-
public IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot { get; } = Group.NavigationRoot;
20-
public string Url => Model.Url;
21-
public string NavigationTitle => Model.NavigationTitle;
22-
public int NavigationIndex { get; set; }
23-
}
24-
25-
public class TableOfContentsTreeCollector
26-
{
27-
private Dictionary<Uri, TableOfContentsTree> NestedTableOfContentsTrees { get; } = [];
28-
29-
public void Collect(Uri source, TableOfContentsTree tree) =>
30-
NestedTableOfContentsTrees[source] = tree;
31-
32-
public void Collect(TocReference tocReference, TableOfContentsTree tree) =>
33-
NestedTableOfContentsTrees[tocReference.Source] = tree;
34-
35-
public bool TryGetTableOfContentsTree(Uri source, [NotNullWhen(true)] out TableOfContentsTree? tree) =>
36-
NestedTableOfContentsTrees.TryGetValue(source, out tree);
37-
}
38-
39-
40-
[DebuggerDisplay("Toc >{Depth} {FolderName} ({NavigationItems.Count} items)")]
41-
public class TableOfContentsTree : DocumentationGroup, IRootNavigationItem<MarkdownFile, INavigationItem>
42-
{
43-
public Uri Source { get; }
44-
45-
public TableOfContentsTreeCollector TreeCollector { get; }
46-
47-
public TableOfContentsTree(
48-
Uri source,
49-
BuildContext context,
50-
NavigationLookups lookups,
51-
TableOfContentsTreeCollector treeCollector,
52-
ref int fileIndex)
53-
: base(".", treeCollector, context, lookups, source, ref fileIndex, 0, null, null)
54-
{
55-
TreeCollector = treeCollector;
56-
NavigationRoot = this;
57-
58-
Source = source;
59-
TreeCollector.Collect(source, this);
60-
61-
//edge case if a tree only holds a single group, ensure we collapse it down to the root (this)
62-
if (NavigationItems.Count == 1 && NavigationItems.First() is DocumentationGroup { NavigationItems.Count: 0 })
63-
NavigationItems = [];
64-
65-
66-
}
67-
68-
internal TableOfContentsTree(
69-
Uri source,
70-
string folderName,
71-
TableOfContentsTreeCollector treeCollector,
72-
BuildContext context,
73-
NavigationLookups lookups,
74-
ref int fileIndex,
75-
int depth,
76-
IRootNavigationItem<MarkdownFile, INavigationItem> toplevelTree,
77-
DocumentationGroup? parent
78-
) : base(folderName, treeCollector, context, lookups, source, ref fileIndex, depth, toplevelTree, parent)
79-
{
80-
Source = source;
81-
TreeCollector = treeCollector;
82-
NavigationRoot = this;
83-
TreeCollector.Collect(source, this);
84-
}
85-
86-
protected override IRootNavigationItem<MarkdownFile, INavigationItem> DefaultNavigation => this;
87-
88-
// We rely on IsPrimaryNavEnabled to determine if we should show the dropdown
89-
/// <inheritdoc />
90-
public bool IsUsingNavigationDropdown => false;
91-
}
92-
9314
[DebuggerDisplay("Group >{Depth} {FolderName} ({NavigationItems.Count} items)")]
9415
public class DocumentationGroup : INodeNavigationItem<MarkdownFile, INavigationItem>
9516
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Diagnostics;
6+
using Elastic.Documentation.Site.Navigation;
7+
8+
namespace Elastic.Markdown.IO.Navigation;
9+
10+
[DebuggerDisplay("Current: {Model.RelativePath}")]
11+
public record FileNavigationItem(MarkdownFile Model, DocumentationGroup Group, bool Hidden = false) : ILeafNavigationItem<MarkdownFile>
12+
{
13+
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; } = Group;
14+
public IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot { get; } = Group.NavigationRoot;
15+
public string Url => Model.Url;
16+
public string NavigationTitle => Model.NavigationTitle;
17+
public int NavigationIndex { get; set; }
18+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Diagnostics;
6+
using Elastic.Documentation.Configuration;
7+
using Elastic.Documentation.Site.Navigation;
8+
9+
namespace Elastic.Markdown.IO.Navigation;
10+
11+
[DebuggerDisplay("Toc >{Depth} {FolderName} ({NavigationItems.Count} items)")]
12+
public class TableOfContentsTree : DocumentationGroup, IRootNavigationItem<MarkdownFile, INavigationItem>
13+
{
14+
public Uri Source { get; }
15+
16+
public TableOfContentsTreeCollector TreeCollector { get; }
17+
18+
public TableOfContentsTree(
19+
Uri source,
20+
BuildContext context,
21+
NavigationLookups lookups,
22+
TableOfContentsTreeCollector treeCollector,
23+
ref int fileIndex)
24+
: base(".", treeCollector, context, lookups, source, ref fileIndex, 0, null, null)
25+
{
26+
TreeCollector = treeCollector;
27+
NavigationRoot = this;
28+
29+
Source = source;
30+
TreeCollector.Collect(source, this);
31+
32+
//edge case if a tree only holds a single group, ensure we collapse it down to the root (this)
33+
if (NavigationItems.Count == 1 && NavigationItems.First() is DocumentationGroup { NavigationItems.Count: 0 })
34+
NavigationItems = [];
35+
36+
37+
}
38+
39+
internal TableOfContentsTree(
40+
Uri source,
41+
string folderName,
42+
TableOfContentsTreeCollector treeCollector,
43+
BuildContext context,
44+
NavigationLookups lookups,
45+
ref int fileIndex,
46+
int depth,
47+
IRootNavigationItem<MarkdownFile, INavigationItem> toplevelTree,
48+
DocumentationGroup? parent
49+
) : base(folderName, treeCollector, context, lookups, source, ref fileIndex, depth, toplevelTree, parent)
50+
{
51+
Source = source;
52+
TreeCollector = treeCollector;
53+
NavigationRoot = this;
54+
TreeCollector.Collect(source, this);
55+
}
56+
57+
protected override IRootNavigationItem<MarkdownFile, INavigationItem> DefaultNavigation => this;
58+
59+
// We rely on IsPrimaryNavEnabled to determine if we should show the dropdown
60+
/// <inheritdoc />
61+
public bool IsUsingNavigationDropdown => false;
62+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Diagnostics.CodeAnalysis;
6+
using Elastic.Documentation.Configuration.TableOfContents;
7+
8+
namespace Elastic.Markdown.IO.Navigation;
9+
10+
public class TableOfContentsTreeCollector
11+
{
12+
private Dictionary<Uri, TableOfContentsTree> NestedTableOfContentsTrees { get; } = [];
13+
14+
public void Collect(Uri source, TableOfContentsTree tree) =>
15+
NestedTableOfContentsTrees[source] = tree;
16+
17+
public void Collect(TocReference tocReference, TableOfContentsTree tree) =>
18+
NestedTableOfContentsTrees[tocReference.Source] = tree;
19+
20+
public bool TryGetTableOfContentsTree(Uri source, [NotNullWhen(true)] out TableOfContentsTree? tree) =>
21+
NestedTableOfContentsTrees.TryGetValue(source, out tree);
22+
}

0 commit comments

Comments
 (0)