6 package com.google.appinventor.components.scripts;
8 import java.io.BufferedWriter;
9 import java.io.IOException;
10 import java.io.Writer;
11 import java.util.Collection;
12 import java.util.HashMap;
14 import java.util.TreeMap;
18 private static final String COLOR_TYPE =
"color";
23 Map<String, String> categoryNames =
new HashMap<>();
24 Map<String, StringBuilder> categoryDocs =
new HashMap<>();
25 Map<String, Map<String, ComponentInfo>> sortedComponents =
new HashMap<>();
33 sortedComponents.put(component.
getCategoryString(),
new TreeMap<String, ComponentInfo>());
39 for (String category : categoryDocs.keySet()) {
40 try (BufferedWriter out =
41 new BufferedWriter(getOutputWriter(category.toLowerCase() +
".md"))) {
42 out.write(
"---\nlayout: documentation\ntitle: ");
43 out.write(categoryNames.get(category));
44 out.write(
"\n---\n\n");
45 out.write(
"[« Back to index](index.html)\n");
47 out.write(categoryNames.get(category));
48 out.write(
"\n\nTable of Contents:\n");
49 for (Map.Entry<String,
ComponentInfo> entry : sortedComponents.get(category).entrySet()) {
51 out.write(entry.getKey());
54 out.write(entry.getKey());
57 for (Map.Entry<String,
ComponentInfo> entry : sortedComponents.get(category).entrySet()) {
58 String name = entry.getKey();
61 out.write(
" {#" + name +
"}\n\n");
63 out.write(info.getLongDescription(info));
65 outputProperties(name, info, out);
66 outputEvents(name, info, out);
67 outputMethods(name, info, out);
74 private void outputProperties(String name, ComponentInfo info, Writer out)
throws IOException {
75 out.write(String.format(
"%n%n### Properties {#%s-Properties}%n%n{:.properties}", name));
76 boolean didOutput =
false;
77 for (Property property : info.properties.values()) {
78 if (isPropertyHidden(info, property)) {
81 out.write(String.format(
"%n%n{:id=\"%s.%s\" %s} *%s*%n: ", name, property.name,
82 getPropertyClass(info, property), property.name));
83 out.write(property.getLongDescription(info));
87 out.write(
"\nNone\n");
91 private boolean isPropertyHidden(ComponentInfo info, Property property) {
92 return (isFeatureHidden(info, property) && !info.designerProperties.containsKey(property.name))
93 || (info.displayName.equals(
"Screen") &&
property.name.equals(
"ActionBar"))
94 || (info.displayName.equals(
"FirebaseDB") &&
property.name.equals(
"DefaultURL"))
95 || (info.displayName.equals(
"CloudDB") &&
property.name.equals(
"DefaultRedisServer"));
98 private boolean isFeatureHidden(ComponentInfo info, Feature feature) {
99 return !feature.isUserVisible() || feature.isDeprecated();
102 private String getPropertyClass(ComponentInfo info, Property property) {
103 String cls =
property.isColor() ? COLOR_TYPE : javaTypeToYailType(property.getType());
104 if (!property.isWritable()) {
107 if (!property.isReadable()) {
110 if (!info.designerProperties.containsKey(property.name)) {
113 if (!property.isUserVisible() && info.designerProperties.containsKey(property.name)) {
119 private void outputEvents(String name, ComponentInfo info, Writer out)
throws IOException {
120 out.write(String.format(
"%n%n### Events {#%s-Events}%n%n{:.events}", name));
121 boolean didOutput =
false;
122 for (Event event : info.events.values()) {
123 if (isFeatureHidden(info, event)) {
126 out.write(String.format(
"%n%n{:id=\"%s.%s\"} %s(%s)%n: ", name, event.name, event.name,
127 formatParameters(event.parameters)));
128 out.write(event.getLongDescription(info));
132 out.write(
"\nNone\n");
136 private void outputMethods(String name, ComponentInfo info, Writer out)
throws IOException {
137 out.write(String.format(
"%n%n### Methods {#%s-Methods}%n%n{:.methods}", name));
138 boolean didOutput =
false;
139 for (Method method : info.methods.values()) {
140 if (isFeatureHidden(info, method)) {
143 String returnType =
"";
144 if (method.getReturnType() !=
null) {
145 returnType = method.isColor() ? COLOR_TYPE : javaTypeToYailType(method.getReturnType());
146 returnType =
" returns " + returnType;
148 out.write(String.format(
"%n%n{:id=\"%s.%s\" class=\"method%s\"} <i/> %s(%s)%n: ", name,
149 method.name, returnType, method.name, formatParameters(method.parameters)));
150 out.write(method.getLongDescription(info));
154 out.write(
"\nNone\n");
158 private String formatParameters(Collection<Parameter> parameters) {
159 StringBuilder sb =
new StringBuilder();
160 String separator =
"";
161 for (Parameter param : parameters) {
162 sb.append(separator);
163 sb.append(String.format(
"*%s*{:.%s}", param.name,
164 param.color ? COLOR_TYPE : javaTypeToYailType(param.type)));
167 return sb.toString();