mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Improve docs generators
This commit is contained in:
parent
9d9fdd1574
commit
f772173df1
@ -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.
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
* Array - массивы
|
||||
* Map - объекты (ассоциативные массивы)
|
||||
* Function - функции
|
||||
* Class - классы
|
||||
|
||||
Поскольку OwnLang - динамически типизируемый язык программирования, это значит, что явно объявлять типы не нужно.
|
||||
|
||||
|
@ -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
|
||||
|
@ -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()) {
|
||||
|
@ -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) {
|
||||
|
@ -227,7 +227,7 @@ types:
|
||||
desc: returns an User-Agent header
|
||||
desc_ru: возвращает заголовок User-Agent
|
||||
- name: Config
|
||||
desc: |-
|
||||
example: |-
|
||||
{
|
||||
"webjars": true,
|
||||
"classpathDirs": ["dir1", "dir2"],
|
||||
|
Loading…
Reference in New Issue
Block a user