Permalink
Browse files

Continue with improvements. Some tests still fail.

  • Loading branch information...
LadyCailin committed Oct 19, 2016
1 parent d34f271 commit a8d77a4d97c3f9da8757357d98317e50dd88fb0f
View
@@ -42,4 +42,6 @@ explained in the SPECIAL_LICENSE.txt file, which is attached.
For details about code formatting standards, and other basic information for
contributors, please see the CONTRIBUTING.txt file.
Portions of CommandHelper are copyright by various contributors.
Portions of CommandHelper are copyright by various contributors.
This project uses BrowserStack (https://www.browserstack.com) for testing the website.
@@ -717,7 +717,11 @@ public boolean doesClassExtend(ClassMirror<?> subClass, Class<?> superClass) {
mirrors.add((ClassMirror<T>) c);
}
}
mirrors.add(new ClassMirror<T>(superClass));
if(superClass.getAnnotation(annotation) != null) {
// The mechanism above won't automatically add this class, so we need to add it
// ourselves here.
mirrors.add(new ClassMirror<T>(superClass));
}
return mirrors;
}
@@ -87,7 +87,7 @@ public String generate(String... args) throws GenerateException {
}
});
g.putAll(DocGenTemplates.GetGenerators());
String t = "<%PRE|<%B%>%>";
String t = "<%SYNTAX|html|\n<%MySQL_CREATE_TABLE_QUERY%>\n%>";
StreamUtils.GetSystemOut().println(DoTemplateReplacement(t, g));
}
@@ -283,6 +283,9 @@ public static String DoTemplateReplacement(String template, Map<String, Generato
return templateBuilder.toString();
}
/**
* Returns a wiki table of the data source modifier list, along with the docs for each one.
*/
public static Generator data_source_modifiers = new Generator() {
@Override
@@ -296,6 +299,9 @@ public String generate(String... args) {
}
};
/**
* Returns a wiki table with documentation for each supported persistence data type.
*/
public static Generator persistence_connections = new Generator() {
@Override
@@ -347,6 +353,9 @@ public String generate(String... args) {
};
/**
* Returns header listing of all the compiler optimization types
*/
public static Generator optimization_explanations = new Generator() {
@Override
@@ -379,6 +388,9 @@ public String generate(String... args) {
}
};
/**
* Returns a header list of all known exception types, along with their docs
*/
public static Generator EXCEPTION_TYPES = new Generator() {
@Override
@@ -408,7 +420,7 @@ public int compare(Class<? extends CREThrowable> o1, Class<? extends CREThrowabl
/**
* Returns the fully qualified (and github linked) class name, given the package regex and complete class name. For
* instance: %%GET_CLASS|.*|DocGenTemplates%% would (likely) return [http://url.to.github.com/path/to/file/
* com.laytonsmith.tools.docgen.DocGenTemplates]
* com/laytonsmith/tools/docgen/DocGenTemplates]
*/
public static Generator GET_CLASS = new Generator() {
@@ -580,17 +592,49 @@ public String generate(String... args) throws GenerateException {
};
/**
* Creates a &lt;pre&gt; block, escaping all special characters within it.
*/
public static Generator PRE = new Generator() {
@Override
public String generate(String... args) {
String code = StringUtils.Join(args, "|");
String out = code.replaceAll("<", "&lt;");
out = out.replaceAll(">", "&gt;");
out = escapeWiki(out);
if(out.startsWith("\n")) {
out = out.substring(1);
}
if(out.endsWith("\n")) {
out = out.substring(0, out.length() - 1);
}
return "<pre class=\"pre\">" + out + "</pre>";
}
};
/**
* Creates a syntax highlighting block. The first argument is the type, and the second
* argument is the code itself.
*/
public static Generator SYNTAX = new Generator() {
@Override
public String generate(String... args) {
String code = StringUtils.Join(ArrayUtils.slice(args, 1, args.length - 1), "|");
String out = code.replaceAll("<", "&lt;");
out = out.replaceAll(">", "&gt;");
out = escapeWiki(out);
if(out.startsWith("\n")) {
out = out.substring(1);
}
return "<pre><code class=\"" + args[0] + "\">" + out + "</code></pre>";
}
};
/**
* Creates a special "warning" section, to draw attention to that message.
*/
public static Generator NOTE = new Generator() {
@Override
public String generate(String... args) {
@@ -621,6 +665,19 @@ public String generate(String... args) {
};
/**
* Returns the value of a constant defined in a java class. Given the following java class:
*
* <code>
* package foo.bar;
*
* class Baz {
* public static int BING = 42;
* }
* </code>
*
* then the following would return 42: %%CONST|foo.bar.Baz.BING%%
*/
public static Generator CONST = new Generator() {
@Override
@@ -656,6 +713,9 @@ public String generate(String... args) {
}
};
/**
* Returns the current date. This accepts a template in the same structure as simple_date()
*/
public static Generator DATE = new Generator() {
@Override
@@ -665,6 +725,11 @@ public String generate(String... args) {
}
};
/**
* Returns a wikified version to link to the given doc page. Optionally, you may include
* the text for the link, otherwise the link itself is used as the text.
* arg 0 is the documentation page, arg 1 is the text
*/
public static Generator DOCLINK = new Generator() {
@Override
@@ -674,10 +739,13 @@ public String generate(String... args) {
if (args.length >= 2) {
text = args[1];
}
return "[[CommandHelper/Staged/" + page + (text != null ? "|" + text : "") + "]]";
return "[[" + page + (text != null ? "|" + text : "") + "]]";
}
};
/**
* Equivalent to %%NOTE%%
*/
public static Generator TAKENOTE = new Generator() {
@Override
public String generate(String... args) throws GenerateException {
@@ -686,6 +754,9 @@ public String generate(String... args) throws GenerateException {
};
/**
* Answers the question: WHAT YEAR IS IT?
*/
public static Generator CURRENTYEAR = new Generator() {
@Override
public String generate(String... args) throws GenerateException {
@@ -1,6 +1,8 @@
package com.laytonsmith.tools.docgen.sitedeploy;
import com.laytonsmith.PureUtilities.ClassLoading.ClassDiscovery;
import com.laytonsmith.PureUtilities.Common.GNUErrorMessageFormat;
import com.laytonsmith.PureUtilities.Common.ReflectionUtils;
import com.laytonsmith.PureUtilities.Common.StreamUtils;
import com.laytonsmith.PureUtilities.Common.StringUtils;
import com.laytonsmith.PureUtilities.DaemonManager;
@@ -12,13 +14,17 @@
import com.laytonsmith.PureUtilities.ZipReader;
import com.laytonsmith.abstraction.Implementation;
import com.laytonsmith.abstraction.enums.MCChatColor;
import com.laytonsmith.annotations.api;
import com.laytonsmith.core.CHVersion;
import com.laytonsmith.core.MethodScriptFileLocations;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.exceptions.CRE.CREThrowable;
import com.laytonsmith.core.functions.Function;
import com.laytonsmith.persistence.DataSourceException;
import com.laytonsmith.persistence.PersistenceNetwork;
import com.laytonsmith.persistence.ReadOnlyException;
import com.laytonsmith.persistence.io.ConnectionMixinFactory;
import com.laytonsmith.tools.docgen.DocGen;
import com.laytonsmith.tools.docgen.DocGenTemplates;
import com.laytonsmith.tools.docgen.DocGenTemplates.Generator;
import com.laytonsmith.tools.docgen.DocGenTemplates.Generator.GenerateException;
@@ -40,6 +46,7 @@
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -360,6 +367,39 @@ public String generate(String... args) {
return SiteDeploy.this.docsBase;
}
});
/**
* The cacheBuster template is meant to make it easier to deal with caching of resources. The
* template allows you to specify the resource, and it creates a path to the resource using
* resourceBase, but it also appends a hash of the file, so that as the file changes, so does the
* hash (using a ?v=hash query string). Most resources live in /siteDeploy/resources/*, and so the
* shorthand is to use %%cacheBuster|path/to/resource.css%%. However, this isn't always correct,
* because resources can live all over the place. In that case, you should use the following format:
* %%cacheBuster|/absolute/path/to/resource.css|path/to/resource/in/html.css%%
*/
g.put("cacheBuster", new Generator() {
@Override
public String generate(String... args) {
String resourceLoc = SiteDeploy.this.resourceBase + args[0];
String loc = args[0];
if (!loc.startsWith("/")) {
loc = "/siteDeploy/resources/" + loc;
} else {
resourceLoc = SiteDeploy.this.resourceBase + args[1];
}
String hash = "0";
try {
InputStream in = SiteDeploy.class.getResourceAsStream(loc);
if (in == null) {
throw new RuntimeException("Could not find " + loc + " in resources folder for cacheBuster template");
}
hash = getLocalMD5(in);
} catch (IOException ex) {
Logger.getLogger(SiteDeploy.class.getName()).log(Level.SEVERE, null, ex);
}
return resourceLoc + "?v=" + hash;
}
});
final Generator learningTrailGen = new Generator() {
@Override
public String generate(String... args) {
@@ -437,14 +477,14 @@ public String generate(String... args) throws GenerateException {
}
private void deploy() throws InterruptedException, IOException {
// deployResources();
deployResources();
deployFrontPages();
deployLearningTrail();
// deployAPI();
// deployEventAPI();
// deployFunctions();
// deployEvents();
// deployAPIJSON();
deployAPI();
deployEventAPI();
deployFunctions();
deployEvents();
deployAPIJSON();
generateQueue.submit(new Runnable() {
@Override
public void run() {
@@ -750,39 +790,6 @@ public String generate(String... args) {
return title;
}
});
/**
* The cacheBuster template is meant to make it easier to deal with caching of resources. The
* template allows you to specify the resource, and it creates a path to the resource using
* resourceBase, but it also appends a hash of the file, so that as the file changes, so does the
* hash (using a ?v=hash query string). Most resources live in /siteDeploy/resources/*, and so the
* shorthand is to use %%cacheBuster|path/to/resource.css%%. However, this isn't always correct,
* because resources can live all over the place. In that case, you should use the following format:
* %%cacheBuster|/absolute/path/to/resource.css|path/to/resource/in/html.css%%
*/
g.put("cacheBuster", new Generator() {
@Override
public String generate(String... args) {
String resourceLoc = SiteDeploy.this.resourceBase + args[0];
String loc = args[0];
if (!loc.startsWith("/")) {
loc = "/siteDeploy/resources/" + loc;
} else {
resourceLoc = SiteDeploy.this.resourceBase + args[1];
}
String hash = "0";
try {
InputStream in = SiteDeploy.class.getResourceAsStream(loc);
if (in == null) {
throw new RuntimeException("Could not find " + loc + " in resources folder for cacheBuster template");
}
hash = getLocalMD5(in);
} catch (IOException ex) {
Logger.getLogger(SiteDeploy.class.getName()).log(Level.SEVERE, null, ex);
}
return resourceLoc + "?v=" + hash;
}
});
g.put("useHttps", new Generator() {
@Override
public String generate(String... args) {
@@ -881,7 +888,40 @@ private void deployLearningTrail() throws IOException {
}
private void deployAPI() {
Set<Class<? extends Function>> functionClasses = ClassDiscovery.getDefaultInstance().loadClassesWithAnnotationThatExtend(api.class, Function.class);
// A map of where it maps the enclosing class to the list of function rows, which contains a list of
// table cells.
Map<Class<?>, List<List<String>>> data = new HashMap<>();
for(Class<? extends Function> functionClass : functionClasses) {
if(!data.containsKey(functionClass.getEnclosingClass())) {
data.put(functionClass.getEnclosingClass(), new ArrayList<List<String>>());
}
List<List<String>> d = data.get(functionClass.getEnclosingClass());
List<String> c = new ArrayList<>();
// function name, returns, arguments, throws, description, since, restricted
Function f;
try {
f = ReflectionUtils.instantiateUnsafe(functionClass);
} catch(ReflectionUtils.ReflectionException ex) {
throw new RuntimeException("While trying to construct " + functionClass + ", got the following", ex);
}
DocGen.DocInfo di = new DocGen.DocInfo(f.docs());
c.add(f.getName());
c.add(di.ret);
c.add(di.args);
List<String> exc = new ArrayList<>();
if(f.thrown() != null) {
for(Class<? extends CREThrowable> e : f.thrown()) {
CREThrowable ct = ReflectionUtils.instantiateUnsafe(e);
exc.add("{{object|" + ct.getName() + "}}");
}
}
c.add(StringUtils.Join(exc, "<br>"));
StringBuilder desc = new StringBuilder();
c.add(desc.toString());
d.add(c);
}
}
private void deployEventAPI() {
Oops, something went wrong.

0 comments on commit a8d77a4

Please sign in to comment.