Skip to content

Commit 9290b34

Browse files
authored
Introduce product type markers to applies blocks/metadata (#113)
1 parent af7048c commit 9290b34

File tree

4 files changed

+84
-10
lines changed

4 files changed

+84
-10
lines changed

docs/source/markup/applies.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ Are equivalent, note `all` just means we won't be rendering the version portion
4949

5050

5151
## This section has its own applies annotations
52-
```{applies}
52+
:::{applies}
5353
:stack: unavailable
5454
:serverless: tech-preview
55-
```
55+
:cloud: ga
56+
:::
5657

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

5962

60-
the `{applies}` directive **MUST** be preceded by a heading.
63+
This section describes a feature that's unavailable in `stack` and `ga` in all cloud products
64+
however its tech preview on `serverless` since it overrides what `cloud` specified.

src/Elastic.Markdown/Myst/Directives/AppliesBlock.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,23 @@ public class AppliesBlock(DirectiveBlockParser parser, Dictionary<string, string
1616

1717
public override void FinalizeAndValidate(ParserContext context)
1818
{
19-
if (TryGetAvailability("stack", out var version))
19+
if (TryGetAvailability("cloud", out var version))
20+
{
21+
Deployment ??= new Deployment();
22+
Deployment.Cloud ??= new CloudManagedDeployment();
23+
Deployment.Cloud.Serverless = version;
24+
Deployment.Cloud.Hosted = version;
25+
}
26+
if (TryGetAvailability("self", out version))
27+
{
28+
Deployment ??= new Deployment();
29+
Deployment.SelfManaged ??= new SelfManagedDeployment();
30+
Deployment.SelfManaged.Ece = version;
31+
Deployment.SelfManaged.Eck = version;
32+
Deployment.SelfManaged.Stack = version;
33+
}
34+
35+
if (TryGetAvailability("stack", out version))
2036
{
2137
Deployment ??= new Deployment();
2238
Deployment.SelfManaged ??= new SelfManagedDeployment();

src/Elastic.Markdown/Myst/FrontMatter/Deployment.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,27 @@ public class DeploymentConverter : IYamlTypeConverter
7474
if (string.Equals(value.Value, "all", StringComparison.InvariantCultureIgnoreCase))
7575
return Deployment.All;
7676
}
77-
var x = rootDeserializer.Invoke(typeof(Dictionary<string, string>));
78-
if (x is not Dictionary<string, string> { Count: > 0 } dictionary)
77+
var deserialized = rootDeserializer.Invoke(typeof(Dictionary<string, string>));
78+
if (deserialized is not Dictionary<string, string> { Count: > 0 } dictionary)
7979
return null;
8080

8181
var deployment = new Deployment();
82-
if (TryGetAvailability("stack", out var version))
82+
83+
if (TryGetAvailability("cloud", out var version))
84+
{
85+
deployment.Cloud ??= new CloudManagedDeployment();
86+
deployment.Cloud.Serverless = version;
87+
deployment.Cloud.Hosted = version;
88+
}
89+
if (TryGetAvailability("self", out version))
90+
{
91+
deployment.SelfManaged ??= new SelfManagedDeployment();
92+
deployment.SelfManaged.Ece = version;
93+
deployment.SelfManaged.Eck = version;
94+
deployment.SelfManaged.Stack = version;
95+
}
96+
97+
if (TryGetAvailability("stack", out version))
8398
{
8499
deployment.SelfManaged ??= new SelfManagedDeployment();
85100
deployment.SelfManaged.Stack = version;

tests/Elastic.Markdown.Tests/FrontMatter/ProductConstraintTests.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ public void Assert() =>
111111
File.YamlFrontMatter!.AppliesTo!.SelfManaged!.Stack.Should().BeEquivalentTo(ProductAvailability.GenerallyAvailable);
112112
}
113113

114-
public class EmptyCloudSetsAllProductsToAll(ITestOutputHelper output) : DirectiveTest(output,
114+
public class EmptyCloudSetsAllCloudProductsToAll(ITestOutputHelper output) : DirectiveTest(output,
115115
"""
116116
---
117117
title: Elastic Docs v3
118118
navigation_title: "Documentation Guide"
119119
applies:
120-
hosted:
120+
cloud:
121121
---
122122
"""
123123
)
@@ -126,3 +126,42 @@ public class EmptyCloudSetsAllProductsToAll(ITestOutputHelper output) : Directiv
126126
public void Assert() =>
127127
File.YamlFrontMatter!.AppliesTo!.Cloud!.Hosted.Should().BeEquivalentTo(ProductAvailability.GenerallyAvailable);
128128
}
129+
130+
public class EmptySelfSetsAllSelfManagedProductsToAll(ITestOutputHelper output) : DirectiveTest(output,
131+
"""
132+
---
133+
title: Elastic Docs v3
134+
navigation_title: "Documentation Guide"
135+
applies:
136+
self:
137+
stack: deprecated 9.0.0
138+
---
139+
"""
140+
)
141+
{
142+
[Fact]
143+
public void Assert()
144+
{
145+
File.YamlFrontMatter!.AppliesTo!.SelfManaged!.Eck.Should()
146+
.BeEquivalentTo(ProductAvailability.GenerallyAvailable);
147+
File.YamlFrontMatter!.AppliesTo!.SelfManaged!.Stack.Should()
148+
.BeEquivalentTo(new ProductAvailability { Lifecycle = Deprecated, Version = new (9,0,0) });
149+
}
150+
}
151+
152+
public class CloudProductsOverwriteDeploymentType(ITestOutputHelper output) : DirectiveTest(output,
153+
"""
154+
---
155+
title: Elastic Docs v3
156+
navigation_title: "Documentation Guide"
157+
applies:
158+
cloud:
159+
---
160+
"""
161+
)
162+
{
163+
[Fact]
164+
public void Assert() =>
165+
File.YamlFrontMatter!.AppliesTo!.Cloud!.Hosted.Should().BeEquivalentTo(ProductAvailability.GenerallyAvailable);
166+
}
167+

0 commit comments

Comments
 (0)