Skip to content

Commit 1559855

Browse files
vnickolovjjaderberg
authored andcommitted
Fix documentation syntax tests
1 parent 780a1df commit 1559855

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.doc.syntax;
21+
22+
import org.asciidoctor.ast.Document;
23+
import org.asciidoctor.extension.IncludeProcessor;
24+
import org.asciidoctor.extension.PreprocessorReader;
25+
26+
import java.io.BufferedReader;
27+
import java.io.File;
28+
import java.io.FileReader;
29+
import java.io.IOException;
30+
import java.io.UncheckedIOException;
31+
import java.nio.charset.StandardCharsets;
32+
import java.nio.file.Paths;
33+
import java.util.Map;
34+
import java.util.stream.Collectors;
35+
36+
final class PartialsIncludeProcessor extends IncludeProcessor {
37+
38+
@Override
39+
public boolean handles(String target) {
40+
return target.contains("partial$");
41+
}
42+
43+
@Override
44+
public void process(Document document, PreprocessorReader reader, String target, Map<String, Object> attributes) {
45+
var base_dir = document.getOptions().get("base_dir").toString();
46+
var relativePathToPartialFile = target.replace("partial$", "partials");
47+
var partialFile = Paths.get(base_dir, relativePathToPartialFile).toFile();
48+
try(var partialFileReader = new BufferedReader(new FileReader(partialFile, StandardCharsets.UTF_8))) {
49+
var partialFileContent = partialFileReader
50+
.lines()
51+
.collect(Collectors.joining(System.lineSeparator()));
52+
53+
reader.push_include(
54+
partialFileContent,
55+
target,
56+
new File(".").getAbsolutePath(),
57+
1,
58+
attributes
59+
);
60+
61+
} catch (IOException e) {
62+
throw new UncheckedIOException(e);
63+
}
64+
}
65+
}

doc/src/main/java/org/neo4j/gds/doc/syntax/SyntaxTestBase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
@ExtendWith(SoftAssertionsExtension.class)
4646
public abstract class SyntaxTestBase {
4747

48-
private static final Path ASCIIDOC_PATH = Paths.get("asciidoc");
48+
private static final Path ASCIIDOC_PATH = Paths.get("modules/ROOT/pages");
4949

5050
private Asciidoctor asciidoctor;
5151

@@ -61,11 +61,14 @@ void tearDown() {
6161

6262
@Test
6363
void runSyntaxTest(SoftAssertions softAssertions, @TempDir File outputDirectory) {
64+
asciidoctor.javaExtensionRegistry().includeProcessor(new PartialsIncludeProcessor());
6465
asciidoctor.javaExtensionRegistry().postprocessor(syntaxPostProcessor(softAssertions));
6566

6667
var docFile = ASCIIDOC_PATH.resolve(adocFile()).toFile();
6768
assertThat(docFile).exists().canRead();
69+
6870
var options = OptionsBuilder.options()
71+
.baseDir(ASCIIDOC_PATH.toFile())
6972
.toDir(outputDirectory) // Make sure we don't write anything in the project.
7073
.safe(SafeMode.UNSAFE); // By default we are forced to use relative path which we don't want.
7174

0 commit comments

Comments
 (0)