From f772173df1cf9bb6b27105c89020b7e26309029c Mon Sep 17 00:00:00 2001 From: aNNiMON Date: Mon, 11 Dec 2023 18:04:32 +0200 Subject: [PATCH] Improve docs generators --- docs/docs/en/basics/types.md | 1 + docs/docs/ru/basics/types.md | 1 + docs/src/docgen-md.own | 17 +++++++++++------ .../com/annimon/ownlang/docs/ModuleInfo.java | 6 +++++- .../ownlang/docs/ModulesInfoCreator.java | 11 ++++++++--- docs/src/modules/server.yml | 2 +- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/docs/docs/en/basics/types.md b/docs/docs/en/basics/types.md index ec4e3b2..c7b5b11 100644 --- a/docs/docs/en/basics/types.md +++ b/docs/docs/en/basics/types.md @@ -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. diff --git a/docs/docs/ru/basics/types.md b/docs/docs/ru/basics/types.md index 088844d..0d0f55c 100644 --- a/docs/docs/ru/basics/types.md +++ b/docs/docs/ru/basics/types.md @@ -7,6 +7,7 @@ * Array - массивы * Map - объекты (ассоциативные массивы) * Function - функции + * Class - классы Поскольку OwnLang - динамически типизируемый язык программирования, это значит, что явно объявлять типы не нужно. diff --git a/docs/src/docgen-md.own b/docs/src/docgen-md.own index 4c33e54..53e61ab 100644 --- a/docs/src/docgen-md.own +++ b/docs/src/docgen-md.own @@ -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 diff --git a/docs/src/main/java/com/annimon/ownlang/docs/ModuleInfo.java b/docs/src/main/java/com/annimon/ownlang/docs/ModuleInfo.java index bc3f522..d47f0fe 100644 --- a/docs/src/main/java/com/annimon/ownlang/docs/ModuleInfo.java +++ b/docs/src/main/java/com/annimon/ownlang/docs/ModuleInfo.java @@ -20,6 +20,10 @@ public class ModuleInfo { types = new ArrayList<>(); } + public String name() { + return name; + } + public List> functions() { return functions.stream().sorted() .map(f -> { @@ -62,8 +66,8 @@ public class ModuleInfo { public Map info() { final Map 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()) { diff --git a/docs/src/main/java/com/annimon/ownlang/docs/ModulesInfoCreator.java b/docs/src/main/java/com/annimon/ownlang/docs/ModulesInfoCreator.java index d54982e..8c06991 100644 --- a/docs/src/main/java/com/annimon/ownlang/docs/ModulesInfoCreator.java +++ b/docs/src/main/java/com/annimon/ownlang/docs/ModulesInfoCreator.java @@ -48,11 +48,16 @@ public final class ModulesInfoCreator { options.setIndent(2); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - final List> 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 listValues(Class moduleClass) { diff --git a/docs/src/modules/server.yml b/docs/src/modules/server.yml index d8f4a38..cb317e1 100644 --- a/docs/src/modules/server.yml +++ b/docs/src/modules/server.yml @@ -227,7 +227,7 @@ types: desc: returns an User-Agent header desc_ru: возвращает заголовок User-Agent - name: Config - desc: |- + example: |- { "webjars": true, "classpathDirs": ["dir1", "dir2"],