Skip to content

Commit eaa2f53

Browse files
committed
Add shortcode for Feature gate table
1 parent 6289ad6 commit eaa2f53

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

data/i18n/en/en.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,39 @@ other = "Were you looking for:"
115115
[examples_heading]
116116
other = "Examples"
117117

118+
[feature_gate_stage_alpha]
119+
other = "Alpha"
120+
121+
[feature_gate_stage_beta]
122+
other = "Beta"
123+
124+
[feature_gate_stage_stable]
125+
other = "GA"
126+
127+
[feature_gate_stage_deprecated]
128+
other = "Deprecated"
129+
130+
[feature_gate_table_header_default]
131+
other = "Default"
132+
133+
[feature_gate_table_header_feature]
134+
other = "Feature"
135+
136+
[feature_gate_table_header_from]
137+
other = "From"
138+
139+
[feature_gate_table_header_since]
140+
other = "Since"
141+
142+
[feature_gate_table_header_stage]
143+
other = "Stage"
144+
145+
[feature_gate_table_header_to]
146+
other = "To"
147+
148+
[feature_gate_table_header_until]
149+
other = "Until"
150+
118151
[feature_state]
119152
other = "FEATURE STATE:"
120153

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{{- $featureDataFiles := .Site.GetPage "page" "docs/reference/command-line-tools-reference/feature-gates" -}}
2+
3+
<!-- Check if 'show-removed' is passed to the shortcode to display only 'removed' feature gates -->
4+
{{- $removedFeatureGateRequested := .Get "show-removed" -}}
5+
6+
<!-- Extract value for the 'include' parameter passed to the shortcode -->
7+
{{- $includeValues := .Get "include" -}}
8+
9+
<!-- Sort Feature gate pages list -->
10+
{{- $sortedFeatureGates := sort ($featureDataFiles.Resources.ByType "page") -}}
11+
12+
<table class="sortable-table">
13+
<caption style="display:none">
14+
{{- .Get "caption" -}}
15+
</caption>
16+
<thead>
17+
<tr>
18+
<th>{{- T "feature_gate_table_header_feature" -}}</th>
19+
<th>{{- T "feature_gate_table_header_default" -}}</th>
20+
<th>{{- T "feature_gate_table_header_stage" -}}</th>
21+
<th>
22+
{{- if $removedFeatureGateRequested -}}
23+
{{- T "feature_gate_table_header_from" -}}
24+
{{- else -}}
25+
{{- T "feature_gate_table_header_since" -}}
26+
{{- end -}}
27+
</th>
28+
<th>
29+
{{- if $removedFeatureGateRequested -}}
30+
{{- T "feature_gate_table_header_to" -}}
31+
{{- else -}}
32+
{{- T "feature_gate_table_header_until" -}}
33+
{{- end -}}
34+
</th>
35+
</tr>
36+
</thead>
37+
<tbody>
38+
{{- range $featureGateFile := $sortedFeatureGates -}}
39+
40+
<!-- Extract the feature gate name from the "Title" parameter in file -->
41+
{{- $featureGateName := $featureGateFile.Params.Title -}}
42+
43+
<!-- Extract the feature gate status (i.e. removed or not) from the "Removed" parameter in file -->
44+
{{- $removedStatusForFeature := index $featureGateFile.Params.Removed -}}
45+
46+
<!-- Check if 'stages' parameter is missing in the front matter -->
47+
{{- if not (isSet $featureGateFile.Params "stages") -}}
48+
{{- warnf "Stages parameter is missing in the front matter for %s in %s" $featureGateName (print $featureGateFile.File.Lang "/" $featureGateFile.File.Path) -}}
49+
50+
{{- else -}}
51+
{{- if not $removedFeatureGateRequested -}}
52+
<!-- Check if the feature gate should be included based on the 'include' parameter -->
53+
54+
{{- if $removedStatusForFeature -}}
55+
{{- continue -}}
56+
{{- end -}}
57+
58+
<!-- Check if 'alpha' or 'beta' is specified in 'include' values, set flag accordingly -->
59+
{{- $onlyDisplayAlphaBetaFeature := or (in $includeValues "alpha") (in $includeValues "beta") -}}
60+
{{- $graduatedOrDeprecatedFlag := false -}}
61+
62+
<!-- Iterate through stages for current Feature gate to check for "stable" or "deprecated" stage -->
63+
{{- range $stage := $featureGateFile.Params.stages -}}
64+
{{- if or (eq ($stage).stage "stable") (eq ($stage).stage "deprecated") -}}
65+
{{- $graduatedOrDeprecatedFlag = true -}}
66+
{{- end -}}
67+
{{- end -}}
68+
69+
{{- if eq $onlyDisplayAlphaBetaFeature $graduatedOrDeprecatedFlag -}}
70+
{{- continue -}}
71+
{{- end -}}
72+
73+
{{- else -}}
74+
<!-- Check if 'removed' parameter is not specified, continue to the next iteration -->
75+
{{- if not $removedStatusForFeature -}}
76+
{{- continue -}}
77+
{{- end -}}
78+
{{- end -}}
79+
80+
{{- range $featureGate := $featureGateFile.Params.stages -}}
81+
<!-- Check if the 'stage' value is valid -->
82+
{{- $validStages := slice "alpha" "beta" "stable" "deprecated" -}}
83+
{{- $isValidStage := in $validStages $featureGate.stage -}}
84+
{{- if not $isValidStage -}}
85+
{{- errorf "Invalid 'stage' value '%s' specified for feature gate '%s' in %s (Valid values are: %s)" $featureGate.stage $featureGateName (print $featureGateFile.File.Lang "/" $featureGateFile.File.Path) $validStages -}}
86+
{{- end -}}
87+
88+
<!-- Parse and extract the numeric values in format x.y or x.y.z for comparison -->
89+
{{- $formattedFromVersion := printf "%s" $featureGate.fromVersion | replaceRE "(\\d+\\.\\d+(?:\\.\\d+)?)?.*" "$1" -}}
90+
{{- $formattedToVersion := printf "%s" $featureGate.toVersion | replaceRE "(\\d+\\.\\d+(?:\\.\\d+)?)?.*" "$1" -}}
91+
92+
<!-- Check for invalid 'fromVersion' value -->
93+
{{- if not (eq (printf "%s" $featureGate.fromVersion) $formattedFromVersion) -}}
94+
{{- errorf "Invalid 'fromVersion' value '%s' specified for feature gate '%s' in %s" $featureGate.fromVersion $featureGateName (print $featureGateFile.File.Lang "/" $featureGateFile.File.Path) -}}
95+
{{- end -}}
96+
97+
<!-- Check for invalid 'toVersion' value -->
98+
{{- if and $featureGate.toVersion (not (eq (printf "%s" $featureGate.toVersion) $formattedToVersion)) -}}
99+
{{- errorf "Invalid 'toVersion' value '%s' specified for feature gate '%s' in %s" $featureGate.toVersion $featureGateName (print $featureGateFile.File.Lang "/" $featureGateFile.File.Path) -}}
100+
{{- end -}}
101+
102+
<!-- Display feature gate information in table rows -->
103+
<tr>
104+
<td><code>{{- $featureGateName -}}</code></td>
105+
<td>{{- if isSet $featureGate "defaultValue" -}}<code>{{- $featureGate.defaultValue -}}</code>{{- else -}}–{{- end -}}</td>
106+
<td>{{- T (printf "feature_gate_stage_%s" $featureGate.stage) -}}</td>
107+
<td>{{- $featureGate.fromVersion -}}</td>
108+
<td>{{- if isSet $featureGate "toVersion" -}}{{- $featureGate.toVersion -}}{{- else -}}–{{- end -}}</td>
109+
</tr>
110+
{{- end -}}
111+
{{- end -}}
112+
{{- end -}}
113+
</tbody>
114+
</table>

0 commit comments

Comments
 (0)