Skip to content

Instantly share code, notes, and snippets.

View jeshan's full-sized avatar
🏠
Working from home

Jeshan Giovanni BABOOA jeshan

🏠
Working from home
  • Independent
  • Mauritius
View GitHub Profile
public class Meta {
private final String name, content;
private final Head head;
public Head head() { return head; }
}
public class Head
extends Container<Head> {
public Html html() {
return (Html) parent();
}
}
html
.body()
.heading(Heading.Level.ONE, "Hello h1")
.paragraph("Some text in a paragraph goes here")
.heading(Heading.Level.TWO, "level 2")
.paragraph("Give me a second paragraph");
/*
<html>
<body>
public Body div() {
divs.add(Div.create(this));
return this;
}
public Body heading(Heading.Level level, String content) {
Heading heading = Heading.create(level, content, this);
headers.get(level).add(heading);
return this;
}
html()
.head()
.title("Insert page title here.");
/*
<html>
<head>
<title>Insert page title here.</title>
</head>
</html>
import static com.methodicalprogrammer.fluent.htmlgenerator.Html.html;
public class Html {
private Body body = Body.create(this);
private Head head = Head.create(this);
public static Html html() { return new Html(); }
public Head head() { return head; }
public Body body() { return body; }
// .get() because meta(String) returns an Optional<Meta>
// and since null references suck
html
.head()
.meta("charset").get()
.head()
.html(); // back to the html object reference!
// Creating the document, with some headings and a paragraph
html
.body()
.heading(Heading.Level.ONE, "Hello h1")
.heading(Heading.Level.TWO, "level 2")
.paragraph("Some text in a paragraph goes here");
/*
<html>
<body>
// keep the reference which will allow us to walk through the structure
Html html = html();
// creating a meta tag and navigating down the tree
html
.head()
.meta("charset", "UTF-8");
/*
<html>