Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sangupta/html-gen

Strongly typed HTML generation library in Java
https://github.com/sangupta/html-gen

Last synced: 4 days ago
JSON representation

Strongly typed HTML generation library in Java

Awesome Lists containing this project

README

        

html-gen
========

Strongly typed HTML generation library for Java.

`html-gen` helps you create HTML code snippets using Java objects. It is useful in situations where
using templating engines may be an overkill. Support all HTML5 elements as listed by Mozilla
Developer Network at https://developer.mozilla.org/en/docs/Web/Guide/HTML/HTML5/HTML5_element_list

`html-gen` is an extremely lightweight and independent library - no external dependencies. `JDK 1.6+ compatible`.

Usage
-----

Generating a complete HTML file:

```java
// create new HTML object
Html html = new Html().docType(DocType.HTML5);

// write values to head
html.head()
.title("Sample title page").meta("charset", "utf8")
.meta("charset", "utf8")
.meta("another meta tag", "some value");

// generate the body
html.body().div().addClass("bold").text("Sample Heading");

// Build HTML
System.out.println(html.asString());
```

This will generate the HTML output as

```html
```

### Generating a table

```java
Html html = new Html();
html.body().table()
.thead()
.tr().th("head1").th("head2").th("head3")
.parentTable().tbody()
.tr().td("1").td("2").td("3")
.newRow().td("a").td("b").td("c");

System.out.println(html.asString());
```
generating HTML code as:
```html








head1


head2


head3






1


2


3




a


b


c




```

Changelog
---------

**Current Development**

* Iniital support for all HTML elements

Downloads
---------

The library can be downloaded from Maven Central using:

```xml

com.sangupta
html-gen
0.0.1-SNAPSHOT

```

Versioning
----------

For transparency and insight into our release cycle, and for striving to maintain backward compatibility,
`html-gen` will be maintained under the Semantic Versioning guidelines as much as possible.

Releases will be numbered with the follow format:

..

And constructed with the following guidelines:

* Breaking backward compatibility bumps the major
* New additions without breaking backward compatibility bumps the minor
* Bug fixes and misc changes bump the patch

For more information on SemVer, please visit http://semver.org/.

License
-------

```
html-gen - HTML generation library
Copyright (c) 2014, Sandeep Gupta

http://sangupta.com/projects/htmlgen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```