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
* Map - objects (an associative arrays)
* Function - functions
* Class
Since OwnLang is dynamic programming language, which means that explicitly declare the types is not necessary.

View File

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

View File

@ -136,12 +136,7 @@ def writeFunctions(f, functions, lang, level = 2) {
writeDescription(f, info, lang, " — %s")
writeLine(f, "")
example = getValue(info, "example", lang)
if (length(example ?? "")) {
writeLine(f, "\n```own")
writeLine(f, example)
writeLine(f, "```")
}
writeExample(f, info, lang)
}
}
@ -155,6 +150,7 @@ def writeTypes(f, types, lang) {
writeDescription(f, info, lang, "%s\n")
writeFunctions(f, info.functions ?? [], lang, 4);
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
def getValue(object, key, lang = "en") {
newKey = (lang != "en") ? (key + "_" + lang) : key

View File

@ -20,6 +20,10 @@ public class ModuleInfo {
types = new ArrayList<>();
}
public String name() {
return name;
}
public List<Map<String, Object>> functions() {
return functions.stream().sorted()
.map(f -> {
@ -62,8 +66,8 @@ public class ModuleInfo {
public Map<String, Object> info() {
final Map<String, Object> result = new LinkedHashMap<>();
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("scope", "both");
result.put("constants", constants());
result.put("functions", functions());
if (!types.isEmpty()) {

View File

@ -48,11 +48,16 @@ public final class ModulesInfoCreator {
options.setIndent(2);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
final List<Map<String, Object>> infos = new ArrayList<>();
final Yaml yaml = new Yaml(options);
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) {

View File

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