This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Meta { | |
private final String name, content; | |
private final Head head; | |
public Head head() { return head; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Head | |
extends Container<Head> { | |
public Html html() { | |
return (Html) parent(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html() | |
.head() | |
.title("Insert page title here."); | |
/* | |
<html> | |
<head> | |
<title>Insert page title here.</title> | |
</head> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.methodicalprogrammer.fluent.htmlgenerator.Html.html; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |