org.rendersnake:rendersnake

fast HTML generation libary for Web applications

License

License

GroupId

GroupId

org.rendersnake
ArtifactId

ArtifactId

rendersnake
Last Version

Last Version

1.9.0
Release Date

Release Date

Type

Type

bundle
Description

Description

fast HTML generation libary for Web applications
Source Code Management

Source Code Management

https://github.com/emicklei/rendersnake.git

Download rendersnake

Dependencies

compile (8)

Group / Artifact Type Version
junit : junit jar 4.8.2
javax.servlet : servlet-api jar 2.4
org.apache.commons : commons-lang3 jar 3.1
commons-io : commons-io jar 2.0.1
org.springframework : spring-webmvc jar 4.1.6.RELEASE
net.sf.jtidy : jtidy jar r938
com.google.inject : guice jar 3.0
javax.inject : javax.inject jar 1

Project Modules

There are no modules declared in this project.

rendersnake

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>
```

Versions

Version
1.9.0
1.8