Extension developers spend a lot of time in making extension but even after that they need to work on documentation which is sometimes a big job.
So, this tutorial will surely help you, if you are one of them, like me.
Let’s get started.
1.Get component.json
file
- Open aix using any Zip software
- Navigate to package name until you saw some files
- Double click on
component.json
file and copy contents of it
2.Open any Java IDE [Intellij IDEA or Eclipse](Shouldn’t be online one)
- Create a class
- Add these imports
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
- Add
main
method - Add following variables
public static String docs = "component.json content";
public static StringBuilder builder = new StringBuilder();
- Add following code in
main
method
try {
addEvents();
addMethods();
addProperties();
StringSelection stringSelection =
new StringSelection(builder.toString());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
} catch (ParseException e) {
e.printStackTrace();
}
Type 1: List Form
- Add following methods
public void addEvents() throws ParseException {
JSONObject object = (JSONObject) new JSONParser().parse(text);
JSONArray array = (JSONArray) object.get("events");
if (!array.isEmpty()) {
for (Object item : array) {
JSONObject ob = (JSONObject) item;
builder.append("> <h3>");
builder.append(ob.get("name"));
builder.append("</h3>");
builder.append(ob.get("description"));
JSONArray arr = (JSONArray) ob.get("params");
if (!arr.isEmpty()) {
builder.append("\n" +
"Params | []() \n" +
"---------------- | ------- \n" +
"\n");
for (Object value : arr) {
JSONObject o = (JSONObject) value;
builder.append("```` ").append(o.get("name")).append(" | ");
builder.append(o.get("type")).append("````\n");
}
}
builder.append("\n ____________________________________\n\n");
}
}
}
public void addMethods() throws ParseException {
JSONObject object = (JSONObject) new JSONParser().parse(text);
JSONArray array = (JSONArray) object.get("methods");
if (!array.isEmpty()) {
for (Object item : array) {
JSONObject ob = (JSONObject) item;
builder.append("> <h3>");
builder.append(ob.get("name"));
builder.append("</h3>");
builder.append(ob.get("description"));
JSONArray arr = (JSONArray) ob.get("params");
if (!arr.isEmpty()) {
builder.append("\n" +
"Params | []() \n" +
"---------------- | ------- \n" +
"\n");
for (Object value : arr) {
JSONObject o = (JSONObject) value;
builder.append("```` ").append(o.get("name")).append(" | ");
builder.append(o.get("type")).append("````<br>\n");
}
}
if (ob.containsKey("returnType")){
builder.append("\n<i>Return type : ").append(ob.get("returnType")).append("</i>\n");
}
builder.append("\n____________________________________\n\n");
}
}
}
public void addProperties() throws ParseException {
JSONObject object = (JSONObject) new JSONParser().parse(text);
JSONArray array = (JSONArray) object.get("blockProperties");
if (!array.isEmpty()) {
for (Object item : array) {
JSONObject ob = (JSONObject) item;
builder.append("> <h3>");
builder.append(ob.get("name"));
builder.append("</h3>");
builder.append(ob.get("description"));
if (ob.containsKey("rw")){
builder.append("\n<i>Property Type : ").append(ob.get("rw")).append("</i>");
}
if (ob.containsKey("type")){
builder.append("<br><i>Accepts : ").append(ob.get("type")).append("</i>");
}
builder.append("\n____________________________________\n\n");
}
}
}
Type 2: Tabular Form
- Add following methods
public void addEvents(int index) throws ParseException {
JSONObject object = (JSONObject) array.get(index);
JSONArray array = (JSONArray) object.get("events");
if (!array.isEmpty()) {
for (Object item : array) {
JSONObject ob = (JSONObject) item;
builder.append("<tr><td><img class=\"wp-image-97\" style=\"width: 250px;\" src=\"https://sunnythedeveloper.in/wp-content/uploads/2023/06/Pasted.jpg\" alt=\"\"></td><td>");
builder.append(ob.get("description"));
JSONArray arr = (JSONArray) ob.get("params");
if (!arr.isEmpty()) {
builder.append("<br><em><sub>");
for (Object value : arr) {
JSONObject o = (JSONObject) value;
builder.append("<code>").append(o.get("name")).append(" | ");
builder.append(o.get("type")).append("</code><br>");
}
builder.append("</sub></em>");
}
builder.append("</td></tr>");
}
}
}
public void addMethods(int index) throws ParseException {
JSONObject object = (JSONObject)array.get(index);
JSONArray array = (JSONArray) object.get("methods");
if (!array.isEmpty()) {
for (Object item : array) {
JSONObject ob = (JSONObject) item;
builder.append("<tr><td><img class=\"wp-image-97\" style=\"width: 250px;\" src=\"https://sunnythedeveloper.in/wp-content/uploads/2023/06/Pasted.jpg\" alt=\"\"></td><td>");
builder.append(ob.get("description"));
JSONArray arr = (JSONArray) ob.get("params");
if (!arr.isEmpty()) {
builder.append("<br><em><sub>");
for (Object value : arr) {
JSONObject o = (JSONObject) value;
builder.append("<code>").append(o.get("name")).append(" | ");
builder.append(o.get("type")).append("</code><br>");
}
builder.append("</sub></em>");
}
/*if (ob.containsKey("returnType")){
String rType = String.valueOf(ob.get("returnType"));
builder.append("\n<i>Return type : ").append(rType.equalsIgnoreCase("any") ? "object":rType).append("</i>\n");
}*/
builder.append("</td></tr>");
}
}
}
public void addProperties(int index) throws ParseException {
JSONObject object = (JSONObject)array.get(index);
JSONArray array = (JSONArray) object.get("blockProperties");
if (!array.isEmpty()) {
for (Object item : array) {
JSONObject ob = (JSONObject) item;
builder.append("<tr><td><img class=\"wp-image-97\" style=\"width: 250px;\" src=\"https://sunnythedeveloper.in/wp-content/uploads/2023/06/Pasted.jpg\" alt=\"\"></td><td>");
builder.append(ob.get("description")).append("<br>");
if (ob.containsKey("rw")){
builder.append("<b>Property Type : ").append("</b>").append(ob.get("rw")).append("<br>");
}
if (ob.containsKey("type")){
builder.append("<b>Accepts : ").append("</b>").append(ob.get("type")).append("<br>");
}
builder.append("</td></tr>");
}
}
}
Replace src , height and width according to your need.
Now run main method once and docs will get copied to clipboard.
It will look like this:
Hope it helps!
Thank you.