diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 5e156d936..5a493612d 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,7 +1,9 @@ import com.dfsek.terra.configureCommon +import com.github.javaparser.StaticJavaParser import com.github.javaparser.ast.body.FieldDeclaration import com.github.javaparser.ast.expr.StringLiteralExpr -import com.github.javaparser.StaticJavaParser +import com.github.javaparser.ast.type.PrimitiveType.Primitive +import com.github.javaparser.ast.type.Type plugins { `java-library` @@ -62,6 +64,12 @@ publishing { } } +sourceSets { + create("tectonic") { + + } +} + tasks.create("tectonicDocs") { group = "terra" println("Scanning sources...") @@ -81,7 +89,7 @@ tasks.create("tectonicDocs") { doc.append("${sanitizeJavadoc(it.toText())} \n") } declaration.extendedTypes.forEach { - if(!it.name.asString().equals("AbstractableTemplate")) { + if (!it.name.asString().equals("AbstractableTemplate")) { doc.append("Inherits from [${it.name}](./${it.name})\n") } } @@ -92,11 +100,11 @@ tasks.create("tectonicDocs") { unit.findAll(FieldDeclaration::class.java).filter { it.isAnnotationPresent("Value") }.forEach { fieldDeclaration -> doc.append("## ${(fieldDeclaration.getAnnotationByName("Value").get().childNodes[1] as StringLiteralExpr).asString()}\n") - if(fieldDeclaration.isAnnotationPresent("Default")) { + if (fieldDeclaration.isAnnotationPresent("Default")) { doc.append("* Default value: ${fieldDeclaration.variables[0]} \n") } - val type =fieldDeclaration.commonType.asString() - doc.append("* Type: [$type](./$type) \n") + val type = fieldDeclaration.commonType + doc.append("* Type: ${parseTypeLink(type)} \n") doc.append("\n") fieldDeclaration.javadoc.ifPresent { @@ -106,7 +114,9 @@ tasks.create("tectonicDocs") { applicable = true } val s = doc.toString() - if (s.isNotEmpty() && applicable) docs[name] = s + if (s.isNotEmpty() && applicable) { + docs[name] = s + } } } println("Done. Generated ${docs.size} files") @@ -119,8 +129,51 @@ tasks.create("tectonicDocs") { save.createNewFile() save.writeText(it.value) } + + sourceSets["tectonic"].resources.forEach { + it.copyTo(File(docsDir, it.name), true) + } } -fun sanitizeJavadoc(doc:String):String { - return doc.replace("

", "").replace("<", "\\<").replace(">", "\\>") +fun parseTypeLink(type: Type): String { + val st = parseType(type) + + if(st.contains('<')) { + val outer = type.childNodes[0] + + val builder = StringBuilder() + builder.append("[$outer](./$outer)\\<") + + for(i in 1 until type.childNodes.size) { + builder.append(parseTypeLink(type.childNodes[i] as Type)) + if(i != type.childNodes.size-1) builder.append(", ") + } + + builder.append("\\>") + + return builder.toString() + } + return "[$st](./$st)" +} + +fun parseType(type: Type): String { + if(type is com.github.javaparser.ast.type.PrimitiveType) { + return when(type.type) { + Primitive.BOOLEAN -> "Boolean" + Primitive.BYTE -> "Byte" + Primitive.DOUBLE -> "Double" + Primitive.INT -> "Integer" + Primitive.CHAR -> "Char" + Primitive.FLOAT -> "Float" + Primitive.SHORT -> "Short" + Primitive.LONG -> "Long" + else -> type.asString() + } + } + return type.asString() +} + +fun sanitizeJavadoc(doc: String): String { + return doc + .replace("

", "") } \ No newline at end of file diff --git a/common/src/tectonic/resources/Boolean.md b/common/src/tectonic/resources/Boolean.md new file mode 100644 index 000000000..90102184c --- /dev/null +++ b/common/src/tectonic/resources/Boolean.md @@ -0,0 +1,5 @@ +# Boolean + +A Boolean data type represents a logical boolean value, a value which can +be either `true` or `false`. + diff --git a/common/src/tectonic/resources/Double.md b/common/src/tectonic/resources/Double.md new file mode 100644 index 000000000..155e012f0 --- /dev/null +++ b/common/src/tectonic/resources/Double.md @@ -0,0 +1,10 @@ +# Double + +A Double type represents a double-precision floating point value. +Essentially, a Double is a decimal number. + +Examples: +* `5` +* `0.3` +* `-12.5` +* `100.3` \ No newline at end of file diff --git a/common/src/tectonic/resources/Integer.md b/common/src/tectonic/resources/Integer.md new file mode 100644 index 000000000..7b9e198ba --- /dev/null +++ b/common/src/tectonic/resources/Integer.md @@ -0,0 +1,10 @@ +# Integer + +An Integer data type represents a Java integer, a whole number with +a minimum value of -2^31, and a maximum value of 2^31-1. + +Examples: +* `0` +* `5` +* `-20` +* `123456` \ No newline at end of file diff --git a/common/src/tectonic/resources/List.md b/common/src/tectonic/resources/List.md new file mode 100644 index 000000000..b02e61e6a --- /dev/null +++ b/common/src/tectonic/resources/List.md @@ -0,0 +1,15 @@ +# List + +A List is an ordered collection of objects of a specific type. + +Examples: +* ```yml + - "thing" + - "thing 2" + - "thing 3" + ``` +* ```yml + - 1 + - 2 + - 3 + ``` diff --git a/common/src/tectonic/resources/String.md b/common/src/tectonic/resources/String.md new file mode 100644 index 000000000..cd0990866 --- /dev/null +++ b/common/src/tectonic/resources/String.md @@ -0,0 +1,13 @@ +# String + +A String data type represents a string of characters. + +Examples: +* `"Hello, World!"` +* ``` + A + Multi + Line + String + ``` +* `"Something"` \ No newline at end of file