Added basic HTML generation and response handling.
[jrw.git] / src / jrw / resp / Skeleton.java
CommitLineData
6e0043cc
FT
1package jrw.resp;
2
3import jrw.*;
4import jrw.sp.*;
5import java.util.*;
6import java.util.function.*;
7import static jrw.sp.cons.*;
8import static jrw.sp.xhtml.cons.*;
9
10public class Skeleton {
11 public static Environment.Variable<Supplier<? extends Skeleton>> defskel = new Environment.Variable<>(() -> Skeleton::new);
12 public List<String> styles = new ArrayList<>();
13 public Element body = xhtml.cons.body();
14 public String title;
15
16 public Skeleton(String title, Object... contents) {
17 this.title = title;
18 populate(body, contents);
19 }
20
21 public Skeleton() {
22 this("");
23 }
24
25 public Skeleton title(String title) {this.title = title; return(this);}
26 public Skeleton style(String... styles) {this.styles.addAll(Arrays.asList(styles)); return(this);}
27 public Skeleton body(Object... data) {populate(body, data); return(this);}
28
29 public Element head(Request req) {
30 Element head = xhtml.cons.head(xhtml.cons.title(title));
31 for(String style : styles)
32 populate(head, link($("rel", "stylesheet"), $("type", "text/css"), $("href", style)));
33 return(head);
34 }
35
36 public Element body(Request req) {
37 return(body);
38 }
39
40 public Element message(Request req) {
41 return(html(head(req), body(req)));
42 }
43
44 public Element error(Request req) {
45 return(message(req));
46 }
47}