Skip to content

Instantly share code, notes, and snippets.

@shannah
Last active July 22, 2020 13:22
Show Gist options
  • Save shannah/918950f937781616744c9db5fda80b23 to your computer and use it in GitHub Desktop.
Save shannah/918950f937781616744c9db5fda80b23 to your computer and use it in GitHub Desktop.
Sample output from ComponentImageGenerator
// Excerpt from https://github.com/shannah/ComponentImageGenerator/blob/master/src/com/codename1/compgen/MainTestRunner.java
// Project https://github.com/shannah/ComponentImageGenerator
public String generateHtml() {
HTMLBuilder sb = new HTMLBuilder();
sb.appendRaw("<!doctype html>").newLine()
.open("html")
.open("head")
.open("title").append("Codename One Components").close()
.close()
.open("body");
for (Test test : getTests()) {
sb.open("div")
.attr("class", "cn-test")
.attr("data-test-id", test.getId())
.open("h2").append(test.getId()).close();
for (File skinDir : baseDir.listFiles()) {
if (!skinDir.isDirectory()) {
continue;
}
String skinName = skinDir.getName();
for (File themeDir : skinDir.listFiles()) {
if (!themeDir.isDirectory()) {
continue;
}
String themeName = themeDir.getName();
File imgFile = new File(themeDir, getOutputFileName(test.getId()));
if (imgFile.exists()) {
sb.open("div").attr("class", "cn1-test-preview")
.attr("data-theme", themeName)
.attr("data-skin", skinName)
.open("img").attr("src", skinName+"/"+themeName+"/"+getOutputFileName(test.getId()))
.attr("style", "width:"+(imageWidth/2)+"px; height:"+(imageHeight/2)+"px; border:1px solid gray")
.close()
.close();
}
}
}
sb.close(); //cn-test
}
sb.close(); //body
sb.close(); //html
return sb.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment