Skip to content

Commit

Permalink
Since (annotation) - support multiple lines (#7381)
Browse files Browse the repository at this point in the history
* Since - support multiple lines

* HTMLGenerator - add back empty since thingy

* HTMLGenerator - remove some extra lines

* HTMLGenerator - add "pre" to pattern

* HTMLGenerator - jk jk

* HTMLGenerator - fix "new" thingy in docs

* HTMLGenerator - change useless matcher to false

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

Co-authored-by: Patrick Miller <[email protected]>

* HTMLGenerator - only check the last value of a "since"

---------

Co-authored-by: Patrick Miller <[email protected]>
  • Loading branch information
ShaneBeee and APickledWalrus authored Jan 4, 2025
1 parent 57e8fe5 commit 0ea39ac
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/doc/Documentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static void insertSyntaxElement(final PrintWriter pw, final SyntaxElemen
return;
}
final String desc = validateHTML(StringUtils.join(elementClass.getAnnotation(Description.class).value(), "<br/>"), type + "s");
final String since = validateHTML(elementClass.getAnnotation(Since.class).value(), type + "s");
final String since = validateHTML(StringUtils.join(elementClass.getAnnotation(Since.class).value(), "<br/>"), type + "s");
if (desc == null || since == null) {
Skript.warning("" + elementClass.getSimpleName() + "'s description or 'since' is invalid");
return;
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/ch/njol/skript/doc/HTMLGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
*/
public class HTMLGenerator extends DocumentationGenerator {

private static final String SKRIPT_VERSION = Skript.getVersion().toString().replaceAll("-(dev|alpha|beta)\\d*", ""); // Filter branches
private static final Pattern NEW_TAG_PATTERN = Pattern.compile(SKRIPT_VERSION + "(?!\\.)"); // (?!\\.) to avoid matching 2.6 in 2.6.1 etc.
private static final String SKRIPT_VERSION = Skript.getVersion().toString().replaceAll("-(dev|alpha|beta|pre)\\d*", "").replace(".0", ""); // Filter branches
private static final Pattern NEW_TAG_PATTERN = Pattern.compile(SKRIPT_VERSION + "(?!\\.[1-9])"); // (?!\\.) to avoid matching 2.6 in 2.6.1 etc.
private static final Pattern RETURN_TYPE_LINK_PATTERN = Pattern.compile("( ?href=\"(classes\\.html|)#|)\\$\\{element\\.return-type-linkcheck}");

private final String skeleton;
Expand Down Expand Up @@ -434,7 +434,7 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo<?> info, @Nu

// Since
Since since = c.getAnnotation(Since.class);
desc = desc.replace("${element.since}", getDefaultIfNullOrEmpty((since != null ? since.value() : null), "Unknown"));
desc = desc.replace("${element.since}", Joiner.on("<br/>").join(getDefaultIfNullOrEmpty((since != null ? since.value() : null), "Unknown")));

Keywords keywords = c.getAnnotation(Keywords.class);
desc = desc.replace("${element.keywords}", keywords == null ? "" : Joiner.on(", ").join(keywords.value()));
Expand Down Expand Up @@ -488,7 +488,13 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo<?> info, @Nu
desc = handleIf(desc, "${if by-addon}", false);

// New Elements
desc = handleIf(desc, "${if new-element}", NEW_TAG_PATTERN.matcher((since != null ? since.value() : "")).find());
if (since != null) {
String[] value = since.value();
String s = value[value.length - 1];
desc = handleIf(desc, "${if new-element}", NEW_TAG_PATTERN.matcher(s).find());
} else {
desc = handleIf(desc, "${if new-element}", false);
}

// Structure - EntryData
if (info instanceof StructureInfo) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/doc/JSONGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public JSONGenerator(File templateDir, File outputDir) {
syntaxJsonObject.addProperty("name", nameAnnotation.value());

Since sinceAnnotation = syntaxClass.getAnnotation(Since.class);
syntaxJsonObject.addProperty("since", sinceAnnotation == null ? null : sinceAnnotation.value());
syntaxJsonObject.add("since", sinceAnnotation == null ? null : convertToJsonArray(sinceAnnotation.value()));

Description descriptionAnnotation = syntaxClass.getAnnotation(Description.class);
if (descriptionAnnotation != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/doc/Since.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
@Documented
public @interface Since {

public String value();
public String[] value();
}
7 changes: 6 additions & 1 deletion src/main/java/ch/njol/skript/expressions/ExprName.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@
"\tset the player's tab list name to \"&lt;green&gt;%player's name%\"",
"set the name of the player's tool to \"Legendary Sword of Awesomeness\""
})
@Since("before 2.1, 2.2-dev20 (inventory name), 2.4 (non-living entity support, changeable inventory name), 2.7 (worlds)")
@Since({
"before 2.1",
"2.2-dev20 (inventory name)",
"2.4 (non-living entity support, changeable inventory name)",
"2.7 (worlds)"
})
public class ExprName extends SimplePropertyExpression<Object, String> {

@Nullable
Expand Down

0 comments on commit 0ea39ac

Please sign in to comment.