Skip to content

🚀 Add Structure Support to Docs #5523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ public boolean check(final @Nullable ExpressionInfo<?, ?> i) {
// ================ EVENTS ================

private static final List<StructureInfo<? extends Structure>> structures = new ArrayList<>(10);

/**
* Registers an event.
*
Expand Down Expand Up @@ -1469,7 +1469,7 @@ public static <E extends SkriptEvent> SkriptEventInfo<E> registerEvent(String na

String[] transformedPatterns = new String[patterns.length];
for (int i = 0; i < patterns.length; i++)
transformedPatterns[i] = "[on] " + SkriptEvent.fixPattern(patterns[i]) + " [with priority (lowest|low|normal|high|highest|monitor)]";
transformedPatterns[i] = "[on] " + SkriptEvent.fixPattern(patterns[i]) + SkriptEventInfo.EVENT_PRIORITY_SYNTAX;

SkriptEventInfo<E> r = new SkriptEventInfo<>(name, transformedPatterns, c, originClassPath, events);
structures.add(r);
Expand Down
49 changes: 48 additions & 1 deletion src/main/java/ch/njol/skript/doc/HTMLGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.WordUtils;
import org.eclipse.jdt.annotation.Nullable;
import org.skriptlang.skript.lang.entry.EntryData;
import org.skriptlang.skript.lang.entry.EntryValidator;
import org.skriptlang.skript.lang.structure.StructureInfo;

import java.io.File;
import java.io.IOException;
Expand All @@ -50,6 +52,7 @@
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Template engine, primarily used for generating Skript documentation
Expand Down Expand Up @@ -274,6 +277,21 @@ else if (!filesInside.getName().matches("(?i)(.*)\\.(html?|js|css|json)")) {
String genType = genParams[0];
boolean isDocsPage = genType.equals("docs");

if (genType.equals("structures") || isDocsPage) {

for (Iterator<StructureInfo<?>> it = sortedAnnotatedIterator(
(Iterator) Skript.getStructures().stream().filter(structure -> structure.getClass() == StructureInfo.class).iterator());
it.hasNext(); ) {

StructureInfo<?> info = it.next();
assert info != null;
if (info.c.getAnnotation(NoDoc.class) != null)
continue;
String desc = generateAnnotated(descTemp, info, generated.toString(), "Structure");
generated.append(desc);
}
}

if (genType.equals("expressions") || isDocsPage) {
for (Iterator<ExpressionInfo<?,?>> it = sortedAnnotatedIterator((Iterator) Skript.getExpressions()); it.hasNext(); ) {
ExpressionInfo<?,?> info = it.next();
Expand Down Expand Up @@ -496,6 +514,25 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo<?> info, @Nu
// New Elements
desc = handleIf(desc, "${if new-element}", NEW_TAG_PATTERN.matcher((since != null ? since.value() : "")).find());

// Structure - EntryData
if (info instanceof StructureInfo) {
EntryValidator entryValidator = ((StructureInfo<?>) info).entryValidator;
List<EntryData<?>> entryDataList = new ArrayList<>();
if (entryValidator != null)
entryDataList.addAll(entryValidator.getEntryData());

// TODO add type of entrydata like boolean/string/section etc.
desc = handleIf(desc, "${if structure-optional-entrydata}", entryValidator != null);
desc = desc.replace("${element.structure-optional-entrydata}", entryValidator == null ? "" : Joiner.on(", ").join(entryDataList.stream().filter(EntryData::isOptional).map(EntryData::getKey).collect(Collectors.toList())));

desc = handleIf(desc, "${if structure-required-entrydata}", entryValidator != null);
desc = desc.replace("${element.structure-required-entrydata}", entryValidator == null ? "" : Joiner.on(", ").join(entryDataList.stream().filter(entryData -> !entryData.isOptional()).map(EntryData::getKey).collect(Collectors.toList())));
} else {
desc = handleIf(desc, "${if structure-optional-entrydata}", false);
desc = handleIf(desc, "${if structure-required-entrydata}", false);

}

// Type
desc = desc.replace("${element.type}", type);

Expand Down Expand Up @@ -604,6 +641,9 @@ private String generateEvent(String descTemp, SkriptEventInfo<?> info, @Nullable
// Return Type
desc = handleIf(desc, "${if return-type}", false);

desc = handleIf(desc, "${if structure-optional-entrydata}", false);
desc = handleIf(desc, "${if structure-required-entrydata}", false);

// Generate Templates
List<String> toGen = Lists.newArrayList();
int generate = desc.indexOf("${generate");
Expand All @@ -623,6 +663,7 @@ private String generateEvent(String descTemp, SkriptEventInfo<?> info, @Nullable
for (String line : getDefaultIfNullOrEmpty(info.patterns, "Missing patterns.")) {
assert line != null;
line = cleanPatterns(line);
line = line.replace(SkriptEventInfo.EVENT_PRIORITY_SYNTAX, ""); // replace priority syntax in event syntaxes
String parsed = pattern.replace("${element.pattern}", line);
patterns.append(parsed);
}
Expand Down Expand Up @@ -704,6 +745,9 @@ private String generateClass(String descTemp, ClassInfo<?> info, @Nullable Strin
// Return Type
desc = handleIf(desc, "${if return-type}", false);

desc = handleIf(desc, "${if structure-optional-entrydata}", false);
desc = handleIf(desc, "${if structure-required-entrydata}", false);

// Generate Templates
List<String> toGen = Lists.newArrayList();
int generate = desc.indexOf("${generate");
Expand Down Expand Up @@ -788,6 +832,9 @@ private String generateFunction(String descTemp, JavaFunction<?> info) {
// Type
desc = desc.replace("${element.type}", "Function");

desc = handleIf(desc, "${if structure-optional-entrydata}", false);
desc = handleIf(desc, "${if structure-required-entrydata}", false);

// Generate Templates
List<String> toGen = Lists.newArrayList();
int generate = desc.indexOf("${generate");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ch/njol/skript/lang/SkriptEventInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import ch.njol.skript.SkriptAPIException;

public final class SkriptEventInfo<E extends SkriptEvent> extends StructureInfo<E> {

public static final String EVENT_PRIORITY_SYNTAX = " [with priority (lowest|low|normal|high|highest|monitor)]";

public Class<? extends Event>[] events;
public final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
@Examples({
"function sayMessage(message: text):",
"\tbroadcast {_message} # our message argument is available in '{_message}'",
"",
"local function giveApple(amount: number) :: item:",
"\treturn {_amount} of apple"
})
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ch/njol/skript/structures/StructOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
@Examples({
"options:",
"\tno_permission: You're missing the required permission to execute this command!",
"",
"command /ping:",
"\tpermission: command.ping",
"\tpermission message: {@no_permission}",
"\ttrigger:",
"\t\tmessage \"Pong!\"",
"",
"command /pong:",
"\tpermission: command.pong",
"\tpermission message: {@no_permission}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"variables:",
"\t{joins} = 0",
"\t{balance::%player%} = 0",
"",
"on join:",
"\tadd 1 to {joins}",
"\tmessage \"Your balance is %{balance::%player%}%\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
* The values of these entries can be obtained by parsing the Structure's sub{@link Node}s
* through registered {@link EntryData}.
*/
// TODO STRUCTURE add Structures to docs
public abstract class Structure implements SyntaxElement, Debuggable {

/**
Expand Down