Skip to content

Introduce product type markers to applies blocks/metadata #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions docs/source/markup/applies.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ Are equivalent, note `all` just means we won't be rendering the version portion


## This section has its own applies annotations
```{applies}
:::{applies}
:stack: unavailable
:serverless: tech-preview
```
:cloud: ga
:::

This section describes a feature that's unavailable in `stack` and in tech preview on `serverless`
:::{note}
the `{applies}` directive **MUST** be preceded by a heading.
:::


the `{applies}` directive **MUST** be preceded by a heading.
This section describes a feature that's unavailable in `stack` and `ga` in all cloud products
however its tech preview on `serverless` since it overrides what `cloud` specified.
18 changes: 17 additions & 1 deletion src/Elastic.Markdown/Myst/Directives/AppliesBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,23 @@ public class AppliesBlock(DirectiveBlockParser parser, Dictionary<string, string

public override void FinalizeAndValidate(ParserContext context)
{
if (TryGetAvailability("stack", out var version))
if (TryGetAvailability("cloud", out var version))
{
Deployment ??= new Deployment();
Deployment.Cloud ??= new CloudManagedDeployment();
Deployment.Cloud.Serverless = version;
Deployment.Cloud.Hosted = version;
}
if (TryGetAvailability("self", out version))
{
Deployment ??= new Deployment();
Deployment.SelfManaged ??= new SelfManagedDeployment();
Deployment.SelfManaged.Ece = version;
Deployment.SelfManaged.Eck = version;
Deployment.SelfManaged.Stack = version;
}

if (TryGetAvailability("stack", out version))
{
Deployment ??= new Deployment();
Deployment.SelfManaged ??= new SelfManagedDeployment();
Expand Down
21 changes: 18 additions & 3 deletions src/Elastic.Markdown/Myst/FrontMatter/Deployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,27 @@ public class DeploymentConverter : IYamlTypeConverter
if (string.Equals(value.Value, "all", StringComparison.InvariantCultureIgnoreCase))
return Deployment.All;
}
var x = rootDeserializer.Invoke(typeof(Dictionary<string, string>));
if (x is not Dictionary<string, string> { Count: > 0 } dictionary)
var deserialized = rootDeserializer.Invoke(typeof(Dictionary<string, string>));
if (deserialized is not Dictionary<string, string> { Count: > 0 } dictionary)
return null;

var deployment = new Deployment();
if (TryGetAvailability("stack", out var version))

if (TryGetAvailability("cloud", out var version))
{
deployment.Cloud ??= new CloudManagedDeployment();
deployment.Cloud.Serverless = version;
deployment.Cloud.Hosted = version;
}
if (TryGetAvailability("self", out version))
{
deployment.SelfManaged ??= new SelfManagedDeployment();
deployment.SelfManaged.Ece = version;
deployment.SelfManaged.Eck = version;
deployment.SelfManaged.Stack = version;
}

if (TryGetAvailability("stack", out version))
{
deployment.SelfManaged ??= new SelfManagedDeployment();
deployment.SelfManaged.Stack = version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public void Assert() =>
File.YamlFrontMatter!.AppliesTo!.SelfManaged!.Stack.Should().BeEquivalentTo(ProductAvailability.GenerallyAvailable);
}

public class EmptyCloudSetsAllProductsToAll(ITestOutputHelper output) : DirectiveTest(output,
public class EmptyCloudSetsAllCloudProductsToAll(ITestOutputHelper output) : DirectiveTest(output,
"""
---
title: Elastic Docs v3
navigation_title: "Documentation Guide"
applies:
hosted:
cloud:
---
"""
)
Expand All @@ -126,3 +126,42 @@ public class EmptyCloudSetsAllProductsToAll(ITestOutputHelper output) : Directiv
public void Assert() =>
File.YamlFrontMatter!.AppliesTo!.Cloud!.Hosted.Should().BeEquivalentTo(ProductAvailability.GenerallyAvailable);
}

public class EmptySelfSetsAllSelfManagedProductsToAll(ITestOutputHelper output) : DirectiveTest(output,
"""
---
title: Elastic Docs v3
navigation_title: "Documentation Guide"
applies:
self:
stack: deprecated 9.0.0
---
"""
)
{
[Fact]
public void Assert()
{
File.YamlFrontMatter!.AppliesTo!.SelfManaged!.Eck.Should()
.BeEquivalentTo(ProductAvailability.GenerallyAvailable);
File.YamlFrontMatter!.AppliesTo!.SelfManaged!.Stack.Should()
.BeEquivalentTo(new ProductAvailability { Lifecycle = Deprecated, Version = new (9,0,0) });
}
}

public class CloudProductsOverwriteDeploymentType(ITestOutputHelper output) : DirectiveTest(output,
"""
---
title: Elastic Docs v3
navigation_title: "Documentation Guide"
applies:
cloud:
---
"""
)
{
[Fact]
public void Assert() =>
File.YamlFrontMatter!.AppliesTo!.Cloud!.Hosted.Should().BeEquivalentTo(ProductAvailability.GenerallyAvailable);
}

Loading