rythm.~table.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of act Show documentation
Show all versions of act Show documentation
The ACT full stack MVC framework
@import act.util.DataTable, org.osgl.Lang, org.osgl.util.S
@args DataTable table
@for(table.heading()) {
@_
}
@def boolean isUrl(Object v) {
if (null == v) {return false;}
if (!(v instanceof String) && !(v instanceof Appendable)) {
return false;
}
String s = v.toString();
return s.startsWith("http://") || s.startsWith("https://");
}
@def String addHtmlTableAccept(Object v) {
if (null == v) return "";
String url = v.toString();
return url + (url.contains("?") ? "&" : "?") + "_accept=htmltable";
}
@def String toString(Object v) {
if (null == v) return "";
if (!Lang.isSimpleType(v.getClass())) {
String s = com.alibaba.fastjson.JSON.toJSONString(v, true);
s = S.strip(s).of(S.DOUBLE_QUOTES);
return "" + s + "
";
}
return v.toString();
}
@for(Object row: table) {
@for(String label: table.heading()) {
@{
Object v = table.val(row, label)
}
@if(isUrl(v)) {
@v
} else {
@toString(v).raw()
}
}
}