Implementing documentation generator

This commit is contained in:
Luca Frosini 2022-12-12 10:24:05 +01:00
parent 45d5a3a131
commit b5e7f8e685
2 changed files with 76 additions and 2 deletions

View File

@ -6,21 +6,92 @@ import java.util.Set;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.utils.discovery.Discovery;
import org.gcube.informationsystem.utils.documentation.rst.Section;
import org.gcube.informationsystem.utils.documentation.rst.Section.SectionType;
import org.gcube.informationsystem.utils.documentation.rst.table.Cell;
import org.gcube.informationsystem.utils.documentation.rst.table.Row;
import org.gcube.informationsystem.utils.documentation.rst.table.RowType;
import org.gcube.informationsystem.utils.documentation.rst.table.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class DocumentationGenerator {
private static final Logger logger = LoggerFactory.getLogger(DocumentationGenerator.class);
protected File baseDirectory;
public DocumentationGenerator(File baseDirectory) {
this.baseDirectory = baseDirectory;
}
public void generatePropertySection(Type type) {
/*
* E.g. GCubeProperty extends Property
*/
protected Row getTypeDeclaration(Type type) {
Row row = new Row(RowType.NORMAL);
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("**");
stringBuffer.append(type.getName());
stringBuffer.append("**");
stringBuffer.append(" *extends* ");
boolean first = true;
for(String superClass : type.getSuperClasses()) {
if(!first) {
stringBuffer.append(", ");
}else {
first = false;
}
stringBuffer.append("**");
stringBuffer.append(superClass);
stringBuffer.append("**");
}
Cell cell = new Cell();
cell.setText(stringBuffer.toString());
row.appendCell(cell);
row.appendCell(cell);
row.appendCell(cell);
row.appendCell(cell);
return row;
}
public Row getPropertyHeadingRow() {
Row row = new Row(RowType.HEADING);
Cell name = new Cell();
name.setText("Name");
row.appendCell(name);
Cell type = new Cell();
type.setText("Type");
row.appendCell(type);
Cell attributes = new Cell();
attributes.setText("Attributes");
row.appendCell(attributes);
Cell description = new Cell();
description.setText("Description");
row.appendCell(description);
return row;
}
public StringBuffer generatePropertySection(Type type) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("\n");
String name = type.getName();
Section section = new Section();
stringBuffer.append(section.generateSection(SectionType.HEADING_3, name));
stringBuffer.append(type.getDescription());
stringBuffer.append("\n");
Table table = new Table();
table.appendRow(getTypeDeclaration(type));
table.appendRow(getPropertyHeadingRow());
stringBuffer.append(table.generateTable());
logger.info(stringBuffer.toString());
return stringBuffer;
}
public void generate() throws Exception {

View File

@ -8,7 +8,7 @@ public class Section {
public enum SectionType {
HEADING_1(true, "*"),
HEADING_2(false, "="),
HEADING_3(false, "_"),
HEADING_3(false, "-"),
HEADING_4(false, "^");
boolean both;
@ -33,9 +33,12 @@ public class Section {
int lenght = sectionTitle.length();
if(sectionType.both) {
stringBuffer.append(getSectionSeparation(sectionType.separator, lenght));
stringBuffer.append("\n");
}
stringBuffer.append(sectionTitle);
stringBuffer.append("\n");
stringBuffer.append(getSectionSeparation(sectionType.separator, lenght));
stringBuffer.append("\n\n");
return stringBuffer;
}