X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fjrw%2Fresp%2FSkeleton.java;fp=src%2Fjrw%2Fresp%2FSkeleton.java;h=75655bc8d756fdd660acee61050f6ed070d2b00d;hb=6e0043cc3f99a31bac74d6d0c7399e4c0b60d3fb;hp=0000000000000000000000000000000000000000;hpb=ad84ba3b456f1a9858fcfe1fee28b81197654c8d;p=jrw.git diff --git a/src/jrw/resp/Skeleton.java b/src/jrw/resp/Skeleton.java new file mode 100644 index 0000000..75655bc --- /dev/null +++ b/src/jrw/resp/Skeleton.java @@ -0,0 +1,47 @@ +package jrw.resp; + +import jrw.*; +import jrw.sp.*; +import java.util.*; +import java.util.function.*; +import static jrw.sp.cons.*; +import static jrw.sp.xhtml.cons.*; + +public class Skeleton { + public static Environment.Variable> defskel = new Environment.Variable<>(() -> Skeleton::new); + public List styles = new ArrayList<>(); + public Element body = xhtml.cons.body(); + public String title; + + public Skeleton(String title, Object... contents) { + this.title = title; + populate(body, contents); + } + + public Skeleton() { + this(""); + } + + public Skeleton title(String title) {this.title = title; return(this);} + public Skeleton style(String... styles) {this.styles.addAll(Arrays.asList(styles)); return(this);} + public Skeleton body(Object... data) {populate(body, data); return(this);} + + public Element head(Request req) { + Element head = xhtml.cons.head(xhtml.cons.title(title)); + for(String style : styles) + populate(head, link($("rel", "stylesheet"), $("type", "text/css"), $("href", style))); + return(head); + } + + public Element body(Request req) { + return(body); + } + + public Element message(Request req) { + return(html(head(req), body(req))); + } + + public Element error(Request req) { + return(message(req)); + } +}