|
3 | 3 | // See the LICENSE file in the project root for more information |
4 | 4 |
|
5 | 5 | using Elastic.Documentation; |
| 6 | +using Elastic.Documentation.Configuration; |
| 7 | +using Elastic.Documentation.Configuration.Assembler; |
| 8 | +using Elastic.Documentation.Configuration.Builder; |
| 9 | +using Elastic.Documentation.Site; |
6 | 10 | using Elastic.Documentation.Site.FileProviders; |
7 | 11 | using Elastic.Documentation.Site.Navigation; |
8 | 12 | using Microsoft.AspNetCore.Html; |
9 | 13 |
|
10 | 14 | namespace Elastic.ApiExplorer; |
11 | 15 |
|
12 | | -public abstract class ApiViewModel |
| 16 | +public abstract class ApiViewModel(ApiRenderContext context) |
13 | 17 | { |
14 | | - public required string NavigationHtml { get; init; } |
15 | | - public required StaticFileContentHashProvider StaticFileContentHashProvider { get; init; } |
16 | | - public required INavigationItem CurrentNavigationItem { get; init; } |
17 | | - public required IMarkdownStringRenderer MarkdownRenderer { get; init; } |
| 18 | + public string NavigationHtml { get; } = context.NavigationHtml; |
| 19 | + public StaticFileContentHashProvider StaticFileContentHashProvider { get; } = context.StaticFileContentHashProvider; |
| 20 | + public INavigationItem CurrentNavigationItem { get; } = context.CurrentNavigation; |
| 21 | + public IMarkdownStringRenderer MarkdownRenderer { get; } = context.MarkdownRenderer; |
| 22 | + public BuildContext BuildContext { get; } = context.BuildContext; |
18 | 23 |
|
19 | 24 |
|
20 | 25 | public HtmlString RenderMarkdown(string? markdown) => |
21 | | - string.IsNullOrEmpty(markdown) ? new(string.Empty) : new(MarkdownRenderer.Render(markdown, null)); |
| 26 | + new(string.IsNullOrEmpty(markdown) ? string.Empty : MarkdownRenderer.Render(markdown, null)); |
| 27 | + |
| 28 | + |
| 29 | + public GlobalLayoutViewModel CreateGlobalLayoutModel() => |
| 30 | + new() |
| 31 | + { |
| 32 | + DocSetName = "Api Explorer", |
| 33 | + Description = "", |
| 34 | + CurrentNavigationItem = CurrentNavigationItem, |
| 35 | + Previous = null, |
| 36 | + Next = null, |
| 37 | + NavigationHtml = NavigationHtml, |
| 38 | + UrlPathPrefix = BuildContext.UrlPathPrefix, |
| 39 | + AllowIndexing = BuildContext.AllowIndexing, |
| 40 | + CanonicalBaseUrl = BuildContext.CanonicalBaseUrl, |
| 41 | + GoogleTagManager = new GoogleTagManagerConfiguration(), |
| 42 | + Features = new FeatureFlags([]), |
| 43 | + StaticFileContentHashProvider = StaticFileContentHashProvider |
| 44 | + }; |
22 | 45 | } |
0 commit comments