com.blade.mvc.ui.HtmlCreator Maven / Gradle / Ivy
package com.blade.mvc.ui;
import com.blade.mvc.Const;
import java.util.List;
public class HtmlCreator {
private static final String HTML_FOOTER = "
Copyright © Blade-" + Const.VERSION + "
";
private StringBuilder html = new StringBuilder();
public HtmlCreator() {
html.append("");
html.append("");
html.append("");
html.append("");
}
public HtmlCreator title(String title) {
html.append("").append(title).append(" ");
return this;
}
public HtmlCreator h1(String heading) {
html.append("");
html.append("");
html.append("").append(heading).append("
");
return this;
}
public HtmlCreator h2(String heading) {
html.append("").append(heading).append("
");
return this;
}
public HtmlCreator paragraph(String paragraph) {
html.append("").append(paragraph).append("
");
return this;
}
public HtmlCreator startP() {
html.append("");
return this;
}
public HtmlCreator startP(String className) {
html.append("
");
return this;
}
public HtmlCreator addBold(String text) {
html.append("").append(text).append("");
return this;
}
public HtmlCreator endP() {
html.append("
");
return this;
}
public HtmlCreator hr() {
html.append("
");
return this;
}
public HtmlCreator br() {
html.append("
");
return this;
}
public HtmlCreator addTableWithHeaders(List headers) {
html.append("");
html.append("");
headers.forEach((h) -> html.append("").append(h).append(" "));
html.append(" ");
return this;
}
public HtmlCreator addRowToTable(List rowElements) {
html.append("");
rowElements.forEach((re) -> html.append("").append(re).append(" "));
html.append(" ");
return this;
}
public HtmlCreator endTable() {
html.append("
");
return this;
}
public HtmlCreator startStyle() {
html.append("");
return this;
}
public HtmlCreator centerHeadings() {
html.append("h1, h2 { text-align: center; }");
return this;
}
public HtmlCreator add(String text) {
html.append(text);
return this;
}
public HtmlCreator styleTables() {
html.append("table, th, td { margin: 0 auto; border: 1px solid black; border-collapse: collapse; text-align: center; }");
return this;
}
public HtmlCreator center(String text) {
html.append("").append(text).append(" ");
return this;
}
@Override
public String toString() {
return html.toString();
}
public String html() {
html.append(HTML_FOOTER);
html.append("");
return html.toString();
}
}