Notice: This project has been archived as of [2025-05-06].
This repository is no longer actively developed or maintained.
What this means:
- No new features, updates, or bug fixes will be implemented.
- Issues and pull requests will not be reviewed or merged.
- Support for this project has ended.
The code remains available for historical and educational purposes. Feel free to browse, fork, and adapt it for your own needs, but understand that it comes with no guarantees or ongoing support.
RenderSnake is a Java library for creating components and pages that produce HTML using only Java. Its purpose is to support the creation of Web applications that are better maintainable, allows for easier reuse, have testable UI components and produces compact HTML in an efficient way.
Hello example
HtmlCanvas html = new HtmlCanvas();
html
.html()
.body()
.h1().content("Hello Coder")
._body()
._html();
System.out.println(html.toHtml());
Example of a complex Form element to pick one of four options
html.div(dataRole("fieldcontain"))
.fieldset(dataRole("controlgroup").dataType("horizontal"))
.legend().content("Method")
.input(type("radio").name("method").id("radio-get").value("method-get").checked("checked").onChange("clickedMethod(this.value);"))
.label(for_("radio-get")).content("GET")
.input(type("radio").name("method").id("radio-post").value("method-post").onChange("clickedMethod(this.value);"))
.label(for_("radio-post")).content("POST")
.input(type("radio").name("method").id("radio-put").value("method-put").onChange("clickedMethod(this.value);"))
.label(for_("radio-put")).content("PUT")
.input(type("radio").name("method").id("radio-delete").value("method-delete").onChange("clickedMethod(this.value);"))
.label(for_("radio-delete")).content("DELETE")
._fieldset()
._div();
Example of a HTML5 page wrapper and JQuery Mobile
public class MobileSiteLayoutWrapper extends RenderableWrapper {
public MobileSiteLayoutWrapper(Renderable component) {
super(component);
}
@Override
public void renderOn(HtmlCanvas html) throws IOException {
html
.render(DocType.HTML5)
.html()
.head()
.title().content("renderSnake - Mobile")
.render(JQueryLibrary.mobileTheme("1.0"))
.render(JQueryLibrary.core("1.6.4"))
.render(JQueryLibrary.mobile("1.0"))
._head()
.body()
.div(dataRole("page"))
.div(dataRole("header").dataTheme("b"))
.render(new PageHeader())
._div()
.div(dataRole("content").dataTheme("b"))
.render(this.component)
._div()
.div(dataRole("footer").dataTheme("b"))
.render(new PageFooter())
._div()
._div()
._body()
._html();
}
}
Example of a login component
public class LoginPageContent implements Renderable {
@Override
public void renderOn(HtmlCanvas html) throws IOException {// @formatter:off
html.form(action("/login").method("post").id("login-form"))
.fieldset()
.div(dataRole("fieldcontain"))
.label(for_("name")).content("Username")
.input(type("text").name("name").id("name"))
._div()
.div(dataRole("fieldcontain"))
.label(for_("password")).content("Password")
.input(type("password").name("password").id("password"))
._div()
.input(type("submit").value("Login"))
._fieldset()
._form();
}
}
Maven Installation (available in Maven Central)
<properties>
<rendersnake.version>1.9.0</rendersnake.version>
</properties>
<dependency>
<groupId>org.rendersnake</groupId>
<artifactId>rendersnake</artifactId>
<version>${rendersnake.version}</version>
</dependency>
```