Improve docs generators

This commit is contained in:
aNNiMON 2023-12-11 18:04:32 +02:00 committed by Victor Melnik
parent 9d9fdd1574
commit f772173df1
6 changed files with 27 additions and 11 deletions

View File

@ -7,6 +7,7 @@ OwnLang types are:
* Array - arrays * Array - arrays
* Map - objects (an associative arrays) * Map - objects (an associative arrays)
* Function - functions * Function - functions
* Class
Since OwnLang is dynamic programming language, which means that explicitly declare the types is not necessary. Since OwnLang is dynamic programming language, which means that explicitly declare the types is not necessary.

View File

@ -7,6 +7,7 @@
* Array - массивы * Array - массивы
* Map - объекты (ассоциативные массивы) * Map - объекты (ассоциативные массивы)
* Function - функции * Function - функции
* Class - классы
Поскольку OwnLang - динамически типизируемый язык программирования, это значит, что явно объявлять типы не нужно. Поскольку OwnLang - динамически типизируемый язык программирования, это значит, что явно объявлять типы не нужно.

View File

@ -136,12 +136,7 @@ def writeFunctions(f, functions, lang, level = 2) {
writeDescription(f, info, lang, " — %s") writeDescription(f, info, lang, " — %s")
writeLine(f, "") writeLine(f, "")
example = getValue(info, "example", lang) writeExample(f, info, lang)
if (length(example ?? "")) {
writeLine(f, "\n```own")
writeLine(f, example)
writeLine(f, "```")
}
} }
} }
@ -155,6 +150,7 @@ def writeTypes(f, types, lang) {
writeDescription(f, info, lang, "%s\n") writeDescription(f, info, lang, "%s\n")
writeFunctions(f, info.functions ?? [], lang, 4); writeFunctions(f, info.functions ?? [], lang, 4);
writeLine(f, "") writeLine(f, "")
writeExample(f, info, lang)
} }
} }
@ -179,6 +175,15 @@ def writeSince(f, version, lang, isInline = false) {
} }
} }
def writeExample(f, info, lang) {
example = getValue(info, "example", lang)
if (length(example ?? "")) {
writeLine(f, "\n```own")
writeLine(f, example)
writeLine(f, "```")
}
}
// -- utils // -- utils
def getValue(object, key, lang = "en") { def getValue(object, key, lang = "en") {
newKey = (lang != "en") ? (key + "_" + lang) : key newKey = (lang != "en") ? (key + "_" + lang) : key

View File

@ -20,6 +20,10 @@ public class ModuleInfo {
types = new ArrayList<>(); types = new ArrayList<>();
} }
public String name() {
return name;
}
public List<Map<String, Object>> functions() { public List<Map<String, Object>> functions() {
return functions.stream().sorted() return functions.stream().sorted()
.map(f -> { .map(f -> {
@ -62,8 +66,8 @@ public class ModuleInfo {
public Map<String, Object> info() { public Map<String, Object> info() {
final Map<String, Object> result = new LinkedHashMap<>(); final Map<String, Object> result = new LinkedHashMap<>();
result.put("name", name); result.put("name", name);
result.put("scope", "both");
result.put("since", "%d.%d.%d".formatted(Version.VERSION_MAJOR, Version.VERSION_MINOR, Version.VERSION_PATCH)); result.put("since", "%d.%d.%d".formatted(Version.VERSION_MAJOR, Version.VERSION_MINOR, Version.VERSION_PATCH));
result.put("scope", "both");
result.put("constants", constants()); result.put("constants", constants());
result.put("functions", functions()); result.put("functions", functions());
if (!types.isEmpty()) { if (!types.isEmpty()) {

View File

@ -48,11 +48,16 @@ public final class ModulesInfoCreator {
options.setIndent(2); options.setIndent(2);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
final List<Map<String, Object>> infos = new ArrayList<>(); final Yaml yaml = new Yaml(options);
for (ModuleInfo moduleInfo : moduleInfos) { for (ModuleInfo moduleInfo : moduleInfos) {
infos.add(moduleInfo.info()); final String separator = "-".repeat(moduleInfo.name().length() + 12);
System.out.println(separator);
System.out.print("--- ");
System.out.print(moduleInfo.name() + ".yml");
System.out.println(" ---");
System.out.println(separator);
System.out.println(yaml.dump(moduleInfo.info()));
} }
System.out.println(new Yaml(options).dump(infos));
} }
private static List<String> listValues(Class<?> moduleClass) { private static List<String> listValues(Class<?> moduleClass) {

View File

@ -227,7 +227,7 @@ types:
desc: returns an User-Agent header desc: returns an User-Agent header
desc_ru: возвращает заголовок User-Agent desc_ru: возвращает заголовок User-Agent
- name: Config - name: Config
desc: |- example: |-
{ {
"webjars": true, "webjars": true,
"classpathDirs": ["dir1", "dir2"], "classpathDirs": ["dir1", "dir2"],