Skip to content

Commit 0967d95

Browse files
committed
592: checking for correct assembly metadata
1 parent fe4adb0 commit 0967d95

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; Vale configuration file to test the `AssemblyContainsRequiredMetadata` rule
2+
StylesPath = ../../../styles
3+
MinAlertLevel = suggestion
4+
[*.adoc]
5+
OpenShiftAsciiDoc.AssemblyContainsRequiredMetadata = YES
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//vale-fixture
2+
:context: <unique-context-for-assembly>
3+
= title
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//vale-fixture
2+
:_content-type: ASSEMBLY
3+
[id="<unique-heading-for-assembly>"]
4+
= Assembly title
5+
include::_attributes/input-attributes-file
6+
:context: <unique-context-for-assembly>
7+
8+
toc::[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
extends: script
3+
message: "Assembly is missing required metadata."
4+
level: error
5+
link: https://github.com/openshift/openshift-docs/blob/main/contributing_to_docs/doc_guidelines.adoc#assembly-file-metadata
6+
scope: raw
7+
script: |
8+
text := import("text")
9+
matches := []
10+
11+
//trim extra whitespace
12+
scope = text.trim_space(scope)
13+
//add a newline, it might be missing
14+
scope += "\n"
15+
16+
attribute_regex := "include::_attributes/"
17+
toc_regex := "toc::\\[\\]"
18+
matchAttribute := false
19+
matchToc := false
20+
21+
//Check if context declaration is on any line
22+
for line in text.split(scope, "\n") {
23+
if text.re_match(attribute_regex, line){
24+
matchAttribute = true
25+
} else if text.re_match(toc_regex, line){
26+
matchToc = true
27+
}
28+
}
29+
30+
//Highlight first line if context declaration not found in file
31+
if !matchAttribute || !matchToc {
32+
matches = append(matches, {begin: 1, end: 10})
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Tengo Language
3+
Checks that lines are not hard-wrapped.
4+
$ tengo HardWrappedLines.tengo <asciidoc_file_to_validate>
5+
*/
6+
7+
fmt := import("fmt")
8+
os := import("os")
9+
text := import("text")
10+
11+
input := os.args()
12+
scope := os.read_file(input[2])
13+
matches := []
14+
15+
//trim extra whitespace
16+
scope = text.trim_space(scope)
17+
//add a newline, it might be missing
18+
scope += "\n"
19+
20+
attribute_regex := "include::_attributes/"
21+
toc_regex := "toc::\\[\\]"
22+
matchAttribute := false
23+
matchToc := false
24+
25+
//Check if context declaration is on any line
26+
for line in text.split(scope, "\n") {
27+
if text.re_match(attribute_regex, line){
28+
matchAttribute = true
29+
fmt.println("Found attribute declaration.")
30+
} else if text.re_match(toc_regex, line){
31+
matchToc = true
32+
fmt.println("Found toc declaration")
33+
}
34+
}
35+
36+
//Highlight first line if context declaration not found in file
37+
if !matchAttribute || !matchToc {
38+
matches = append(matches, {begin: 1, end: 10})
39+
fmt.println("Did not find correct metadata")
40+
fmt.println(matches)
41+
}

0 commit comments

Comments
 (0)