Skip to content

Commit 2826897

Browse files
JSONGenerator for addons and docs.json improvements (#8116)
* init commit * add docs * add StructEvent docs * requested changes * fix default values for DocumentationGenerator * github why won't you work * attempt to fix getting skript version in generate-docs action * attempt to fix getting skript version in generate-docs action * requested changes * requested changes * requested changes * thx bbg burb * Update src/main/java/ch/njol/skript/doc/JSONGenerator.java Co-authored-by: Patrick Miller <apickledwalrus@icloud.com> --------- Co-authored-by: Patrick Miller <apickledwalrus@icloud.com>
1 parent db61a08 commit 2826897

7 files changed

Lines changed: 256 additions & 104 deletions

File tree

.github/workflows/docs/generate-docs/action.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ runs:
5252
find $1 -type f -exec sed -i -e "s/$2/$3/g" {} \;
5353
}
5454
55-
# this should be replaced with a more reliable jq command,
56-
# but it can't be right now because docs.json is actually not valid json.
5755
get_skript_version_of_directory() {
58-
grep skriptVersion "$1/docs.json" | cut -d\" -f 4
56+
jq ".source.version" "$1/docs.json"
5957
}
6058
6159
if [ -d "${DOCS_REPO_DIR}/docs/templates" ]

src/main/java/ch/njol/skript/SkriptCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
386386
outputDir.mkdirs();
387387

388388
Skript.info(sender, "Generating docs...");
389-
JSONGenerator jsonGenerator = new JSONGenerator(templateDir, outputDir);
390-
jsonGenerator.generate();
389+
390+
JSONGenerator.of(Skript.instance())
391+
.generate(outputDir.toPath().resolve("docs.json"));
391392

392393
if (!templateDir.exists()) {
393394
Skript.info(sender, "JSON-only documentation generated!");

src/main/java/ch/njol/skript/doc/DocumentationGenerator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package ch.njol.skript.doc;
22

33
import java.io.File;
4+
import java.nio.file.Path;
45

56
/**
6-
* Represents a class which generates a documentation format (like HTML or JSON)
7+
* @deprecated Use {@link JSONGenerator} instead.
78
*/
9+
@Deprecated(forRemoval = true, since = "INSERT VERSION")
810
public abstract class DocumentationGenerator {
911

1012
protected File templateDir;
@@ -16,8 +18,9 @@ public DocumentationGenerator(File templateDir, File outputDir) {
1618
}
1719

1820
/**
19-
* Generates the documentation file
21+
* Use {@link JSONGenerator#generate(Path)} instead.
2022
*/
23+
@Deprecated(forRemoval = true, since = "INSERT VERSION")
2124
public abstract void generate();
2225

2326
}

src/main/java/ch/njol/skript/doc/DocumentationIdProvider.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import ch.njol.skript.lang.function.Functions;
1313
import ch.njol.skript.registrations.Classes;
1414
import org.skriptlang.skript.lang.structure.Structure;
15+
import org.skriptlang.skript.registration.SyntaxInfo;
1516

1617
import java.util.Arrays;
1718
import java.util.Iterator;
@@ -62,7 +63,16 @@ private static <T> int calculateCollisionCount(Iterator<? extends T> potentialCo
6263
* @return the ID of the syntax element
6364
*/
6465
public static <T> String getId(SyntaxElementInfo<? extends T> syntaxInfo) {
65-
Class<?> syntaxClass = syntaxInfo.getElementClass();
66+
return getId((SyntaxInfo<?>) syntaxInfo);
67+
}
68+
69+
/**
70+
* Gets the documentation ID of a syntax element
71+
* @param syntaxInfo the SyntaxInfo to get the ID of
72+
* @return the ID of the syntax element
73+
*/
74+
public static <T> String getId(SyntaxInfo<? extends T> syntaxInfo) {
75+
Class<?> syntaxClass = syntaxInfo.type();
6676
Iterator<? extends SyntaxElementInfo<?>> syntaxElementIterator;
6777
if (Effect.class.isAssignableFrom(syntaxClass)) {
6878
syntaxElementIterator = Skript.getEffects().iterator();
@@ -79,7 +89,7 @@ public static <T> String getId(SyntaxElementInfo<? extends T> syntaxInfo) {
7989
}
8090
int collisionCount = calculateCollisionCount(syntaxElementIterator,
8191
elementInfo -> elementInfo.getElementClass() == syntaxClass,
82-
elementInfo -> Arrays.equals(elementInfo.getPatterns(), syntaxInfo.getPatterns()));
92+
elementInfo -> Arrays.equals(elementInfo.getPatterns(), syntaxInfo.patterns().toArray(new String[0])));
8393
DocumentationId documentationIdAnnotation = syntaxClass.getAnnotation(DocumentationId.class);
8494
if (documentationIdAnnotation == null) {
8595
return addCollisionSuffix(syntaxClass.getSimpleName(), collisionCount);

src/main/java/ch/njol/skript/doc/HTMLGenerator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
/**
3838
* Template engine, primarily used for generating Skript documentation
3939
* pages by combining data from annotations and templates.
40-
*
4140
*/
4241
public class HTMLGenerator extends DocumentationGenerator {
4342

0 commit comments

Comments
 (0)