mavenize
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
//Java Code
|
||||
html().with(
|
||||
head().with(
|
||||
title("Title"),
|
||||
link().withRel("stylesheet").withHref("/css/main.css")
|
||||
),
|
||||
body().with(
|
||||
main().with(
|
||||
h1("Heading!")
|
||||
)
|
||||
)
|
||||
).render();
|
||||
|
||||
|
||||
/* Rendered HTML
|
||||
<html>
|
||||
<head>
|
||||
<title>Title</title>
|
||||
<link rel="stylesheet" href="/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Heading!</h1>
|
||||
</main>
|
||||
</body>
|
||||
<html>
|
||||
*/
|
||||
@@ -1,88 +0,0 @@
|
||||
public class MainTemplate {
|
||||
|
||||
public static String render(String title, Tag... tags) {
|
||||
return document().render() +
|
||||
html().with(
|
||||
head().with(
|
||||
title(title),
|
||||
link().withRel("stylesheet").withHref("/css/main.css")
|
||||
),
|
||||
body().with(
|
||||
header().with(
|
||||
h1(title)
|
||||
),
|
||||
main().with(
|
||||
tags //content from other template
|
||||
),
|
||||
footer().withText("Footer text"),
|
||||
script().withSrc("https://code.jquery.com/jquery-2.1.3.min.js")
|
||||
)
|
||||
).render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
MainTemplate.render(
|
||||
"Form test", //this is the "String title" parameter
|
||||
//Everything below here goes into the "Tag... tags" parameter
|
||||
// "..." means "varargs", which means you can add as many Tags as you like
|
||||
h2().withText("Please log in"),
|
||||
form().withMethod("post").with(
|
||||
emailInput("Email"), //see below for these three fields
|
||||
passwordInput("Password"),
|
||||
submitButton("Log in")
|
||||
)
|
||||
|
||||
|
||||
// you can create methods like these to return fully configured
|
||||
// HTML input fields/buttons (or any other kind of Tag)
|
||||
public static Tag emailInput(String placeholder) {
|
||||
return input()
|
||||
.withType("email")
|
||||
.withId("email")
|
||||
.withName("email")
|
||||
.withPlaceholder(placeholder)
|
||||
.isRequired();
|
||||
}
|
||||
|
||||
public static Tag passwordInput(String placeholder) {
|
||||
return input()
|
||||
.withType("password")
|
||||
.withId("password")
|
||||
.withName("password")
|
||||
.withPlaceholder(placeholder)
|
||||
.isRequired();
|
||||
}
|
||||
|
||||
public static Tag submitButton(String text) {
|
||||
return button()
|
||||
.withType("submit")
|
||||
.withText(text);
|
||||
}
|
||||
|
||||
// OUTPUT (unminified):
|
||||
|
||||
// <!DOCTYPE html>
|
||||
// <html>
|
||||
// <head>
|
||||
// <title>Form test</title>
|
||||
// <link rel="stylesheet" href="/css/main.css">
|
||||
// </head>
|
||||
//
|
||||
// <body>
|
||||
// <header>
|
||||
// <h1>Form test</h1>
|
||||
// </header>
|
||||
// <main>
|
||||
// <h2>Please log in</h2>
|
||||
// <form method="post">
|
||||
// <input type="email" id="email" name="email" placeholder="Email" required>
|
||||
// <input type="password" id="password" name="password" placeholder="Password" required>
|
||||
// <button type="submit">Log in</button>
|
||||
// </form>
|
||||
// </main>
|
||||
// <footer>Footer text</footer>
|
||||
// <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
|
||||
// </body>
|
||||
// </html>
|
||||
62
pom.xml
Normal file
62
pom.xml
Normal file
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.j2html</groupId>
|
||||
<artifactId>j2html</artifactId>
|
||||
<version>0.5.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<optimize>true</optimize>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-java</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireJavaVersion>
|
||||
<version>[1.8,)</version>
|
||||
</requireJavaVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.3</version>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,4 +1,4 @@
|
||||
package j2html.src.attributes;
|
||||
package j2html.attributes;
|
||||
|
||||
public class Attr {
|
||||
public static String HIDDEN = "hidden";
|
||||
@@ -1,6 +1,6 @@
|
||||
package j2html.src.attributes;
|
||||
package j2html.attributes;
|
||||
|
||||
import static j2html.src.htmlEscaper.HtmlEscaper.escape;
|
||||
import static j2html.utils.SimpleHtmlEscaper.escape;
|
||||
|
||||
public class Attribute {
|
||||
private String name;
|
||||
@@ -1,6 +1,6 @@
|
||||
package j2html.src.tags;
|
||||
package j2html.tags;
|
||||
|
||||
import j2html.src.attributes.Attr;
|
||||
import j2html.attributes.Attr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -29,8 +29,8 @@ public class ContainerTag extends Tag {
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a list of tags to the end of this element
|
||||
* @param children tags to be appended
|
||||
* Appends a list of j2html.tags to the end of this element
|
||||
* @param children j2html.tags to be appended
|
||||
* @return itself for easy chaining
|
||||
*/
|
||||
public ContainerTag with(List<Tag> children) {
|
||||
@@ -41,8 +41,8 @@ public class ContainerTag extends Tag {
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the tags to the end of this element
|
||||
* @param children tags to be appended
|
||||
* Appends the j2html.tags to the end of this element
|
||||
* @param children j2html.tags to be appended
|
||||
* @return itself for easy chaining
|
||||
*/
|
||||
public ContainerTag with(Tag... children) {
|
||||
@@ -1,7 +1,7 @@
|
||||
package j2html.src.tags;
|
||||
package j2html.tags;
|
||||
|
||||
import j2html.src.attributes.Attr;
|
||||
import j2html.src.attributes.Attribute;
|
||||
import j2html.attributes.Attr;
|
||||
import j2html.attributes.Attribute;
|
||||
|
||||
public class EmptyTag extends Tag {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package j2html.src.tags;
|
||||
package j2html.tags;
|
||||
|
||||
import j2html.src.attributes.Attribute;
|
||||
import j2html.attributes.Attribute;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package j2html.src.tags;
|
||||
package j2html.tags;
|
||||
|
||||
public class TagCreator {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package j2html.src.tags;
|
||||
package j2html.tags;
|
||||
|
||||
import static j2html.src.htmlEscaper.HtmlEscaper.escape;
|
||||
|
||||
import static j2html.utils.SimpleHtmlEscaper.escape;
|
||||
|
||||
public class Text extends Tag {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package j2html.src.tags;
|
||||
package j2html.tags;
|
||||
|
||||
public class UnescapedText extends Tag {
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package j2html.src.htmlEscaper;
|
||||
package j2html.utils;
|
||||
|
||||
public class HtmlEscaper {
|
||||
public class SimpleHtmlEscaper {
|
||||
|
||||
/**
|
||||
* Simple approach from http://stackoverflow.com/a/25228492/4893160 ... good enough ?
|
||||
* Apache StringEscapeUtils is extremely slow compared (probably because it's a lot safer!)
|
||||
* @param s the string to be escaped
|
||||
* @return the escaped string
|
||||
*/
|
||||
public static String escape(String s) {
|
||||
if("".equals(s)){ return ""; }
|
||||
if(s == null) { return null; }
|
||||
@@ -1,10 +1,9 @@
|
||||
package j2html.test.attributes;
|
||||
package j2html.attributes;
|
||||
|
||||
import j2html.src.attributes.Attribute;
|
||||
import j2html.src.tags.ContainerTag;
|
||||
import org.junit.Test;
|
||||
import j2html.tags.ContainerTag;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
public class AttributeTest {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package j2html.test.tags;
|
||||
package j2html.tags;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static j2html.src.tags.TagCreator.*;
|
||||
import static j2html.src.tags.TagCreator.script;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static j2html.tags.TagCreator.*;
|
||||
|
||||
public class ComplexRenderTest {
|
||||
private String renderTest() {
|
||||
@@ -1,9 +1,9 @@
|
||||
package j2html.test.tags;
|
||||
package j2html.tags;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static j2html.src.tags.TagCreator.*;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static j2html.tags.TagCreator.*;
|
||||
|
||||
public class ConvenienceMethodTest {
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
package j2html.test.tags;
|
||||
package j2html.tags;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static j2html.src.tags.TagCreator.*;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static j2html.tags.TagCreator.*;
|
||||
|
||||
public class TagCreatorTest {
|
||||
|
||||
@Test
|
||||
public void testAllTags() throws Exception {
|
||||
//yea, this is generated from http://www.w3schools.com/tags/
|
||||
|
||||
//Special Tags
|
||||
|
||||
assertTrue(tag("tagname").render().equals("<tagname></tagname>"));
|
||||
assertTrue(emptyTag("tagname").render().equals("<tagname>"));
|
||||
assertTrue(text("text").render().equals("text"));
|
||||
assertTrue(text("<script>").render().equals("<script>"));
|
||||
assertTrue(unsafeHtml("<script>").render().equals("<script>"));
|
||||
assertTrue(text("text").render().equals("text"));
|
||||
|
||||
//EmptyTags
|
||||
assertTrue(document().render().equals("<!DOCTYPE html>"));
|
||||
@@ -1,10 +1,9 @@
|
||||
package j2html.test.tags;
|
||||
package j2html.tags;
|
||||
|
||||
import j2html.src.tags.ContainerTag;
|
||||
import org.junit.Test;
|
||||
|
||||
import static j2html.src.tags.TagCreator.*;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static j2html.tags.TagCreator.*;
|
||||
|
||||
public class TagTest {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package j2html.test.testPerformance;
|
||||
package performancetester;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static j2html.src.tags.TagCreator.*;
|
||||
import static j2html.tags.TagCreator.*;
|
||||
|
||||
public class RenderSpeed {
|
||||
|
||||
Reference in New Issue
Block a user