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
|
* 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.
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
* Array - массивы
|
* Array - массивы
|
||||||
* Map - объекты (ассоциативные массивы)
|
* Map - объекты (ассоциативные массивы)
|
||||||
* Function - функции
|
* Function - функции
|
||||||
|
* Class - классы
|
||||||
|
|
||||||
Поскольку OwnLang - динамически типизируемый язык программирования, это значит, что явно объявлять типы не нужно.
|
Поскольку OwnLang - динамически типизируемый язык программирования, это значит, что явно объявлять типы не нужно.
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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()) {
|
||||||
|
@ -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) {
|
||||||
|
@ -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"],
|
||||||
|
Loading…
Reference in New Issue
Block a user