hella-html is a library that makes it hella easy to generate dynamic HTML in vanilla Java.

Related tags

Utility hella-html
Overview

Hella easy HTML in Java

hella-html is a library that makes it hella easy to generate dynamic HTML in vanilla Java.

  • Very lightweight and fast, the primary logic is 10 lines of O(n) code
  • Requires no external dependencies
  • Supports all standard (and custom) HTML tags
  • Released under the MIT license and free for everyone

Getting started

Add the Maven dependency.

<dependency>
    <groupId>sh.hellagroupId>
    <artifactId>hella-htmlartifactId>
    <version>1.0.1version>
dependency>

or for Gradle users...

compile "sh.hella:hella-html:1.0.1"

And finally the static import.

import static sh.hella.html.Html.*;

Example usage

Java code

html(
    head(
        title(text("Hello World"))
    ),
    body(
        div(clazz("container"),
            h1(text("Hello world, HTML edition!")),
            p(text("Made hella easy in Java")),
            a(href("https://hella.sh/"), text("Visit our homepage!"))
        )
    )
).toString();

HTML output

Hello world, HTML edition!

Made hella easy in Java

Visit our homepage!
">
>
<html>
<head>
    <title>Hello Worldtitle>
head>
<body>
<div class="container">
    <h1>Hello world, HTML edition!h1>
    <p>Made hella easy in Javap>
    <a href="https://www.hella.sh/">Visit our homepage!a>
div> body> html>

Note: formatted for readability, generated HTML will not have newlines or tabs.

Add and remove tags dynamically

Add and remove tags with the add and remove methods. Use them conditionally, inside loops, or however else you want.

Dynamic text!
contentDiv.remove(textSpan); contentDiv.toString(); //
">
Element contentDiv = div(clazz("content"));
Element textSpan = span(text("Dynamic text!"));
        
contentDiv.add(textSpan);
contentDiv.toString(); // 
   
Dynamic text!
contentDiv.remove(textSpan); contentDiv.toString(); //

Custom tags and attributes

Add custom tags with tag(name, children...) and custom attributes with attr(name, value).

Java code

tag("myCustomTag", 
    div(attr("foo", "bar"),
        text("Hello, custom tags and attributes!")
    )
)

HTML output

Hello, custom tags and attributes!
">
<myCustomTag><div foo="bar">Hello, custom tags and attributes!div>myCustomTag>

Inlining content

Inline data directly from files with fromFile(path) and from resources with fromResource(path).

Java code

style(fromResource("style.css")))

HTML output

<style>
    (contents of style.css)
style>
You might also like...

High performance I/O library for Java using io_uring under the hood

nio_uring nio_uring is an I/O library for Java that uses io_uring under the hood, which aims to be: A simple and flexible API Super fast and efficient

Dec 18, 2022

archifacts is a library to extract your architectural concepts out of your application's code

archifacts is a free (Apache 2.0 license) library for describing and detecting architectural building blocks and their relationships in your Java appl

Nov 29, 2022

Java lib for monitoring directories or individual files via java.nio.file.WatchService

ch.vorburger.fswatch Java lib for monitoring directories or individual files based on the java.nio.file.WatchService. Usage Get it from Maven Central

Jan 7, 2022

Tencent Kona JDK11 is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-Term Support(LTS) with quarterly updates. Tencent Kona JDK11 is certified as compatible with the Java SE standard.

Tencent Kona JDK11 is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-Term Support(LTS) with quarterly updates. Tencent Kona JDK11 is certified as compatible with the Java SE standard.

Tencent Kona JDK11 Tencent Kona JDK11 is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-Term Support(LTS) w

Dec 16, 2022

This repository contains Java programs to become zero to hero in Java.

This repository contains Java programs to become zero to hero in Java. Data Structure programs topic wise are also present to learn data structure problem solving in Java. Programs related to each and every concep are present from easy to intermidiate level

Oct 9, 2022

Java Constraint Programming solver

https://maven-badges.herokuapp.com/maven-central/org.jacop/jacop/badge.svg [] (https://maven-badges.herokuapp.com/maven-central/org.jacop/jacop/) JaCo

Dec 30, 2022

Java Constraint Solver to solve vehicle routing, employee rostering, task assignment, conference scheduling and other planning problems.

OptaPlanner www.optaplanner.org Looking for Quickstarts? OptaPlanner’s quickstarts have moved to optaplanner-quickstarts repository. Quick development

Jan 2, 2023

Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas

Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas

Arthas Arthas is a Java Diagnostic tool open sourced by Alibaba. Arthas allows developers to troubleshoot production issues for Java applications with

Jan 4, 2023

Object-Oriented Java primitives, as an alternative to Google Guava and Apache Commons

Project architect: @victornoel ATTENTION: We're still in a very early alpha version, the API may and will change frequently. Please, use it at your ow

Dec 27, 2022
Comments
  • RPC Functionality

    RPC Functionality

    We should add an RPC system that operates over WebSocket for event handlers, which will let people trigger Java code dynamically. Should probably switch to using it as default, because the current run-at-render-time implementation may be confusing to some.

    enhancement 
    opened by bbeaupain 0
  • Maven plugin for pre-rendering static assets

    Maven plugin for pre-rendering static assets

    Some users may want to pre-render static assets during build time. Let's add a Maven plugin that facilitates this.

    Some considerations:

    • We should identify the best way to mark types for pre-rendering during build time. An annotation is probably the most straightforward way for the end user.
    • Input and output directories are probably desirable
    enhancement 
    opened by bbeaupain 0
  • Dynamic Event Handling

    Dynamic Event Handling

    Instead of relying on inline JS with onclick attributes, we should add facilities that inject JavaScriptSections dynamically for any event type. We can support either inlining a <script> tag containing the code, or dynamically generate a JS file that the document can link to (no need to save to disk, just use path tricks and respond with the JS directly from memory).

    enhancement 
    opened by bbeaupain 0
  • Perceived Latency Improvements - Pre-rendering and injecting state changes

    Perceived Latency Improvements - Pre-rendering and injecting state changes

    We can add optional functionality that pre-renders state changes and generates JavaScript that injects those rendered elements when JS event handlers are triggered. Should accomplish perceived latency improvements at the cost of pre-rendering all possible state changes, but that should be okay with our render times.

    enhancement 
    opened by bbeaupain 0
Releases(v1.0.1)
Discord4J is a fast, powerful, unopinionated, reactive library to enable quick and easy development of Discord bots for Java, Kotlin, and other JVM languages using the official Discord Bot API.

Discord4J is a fast, powerful, unopinionated, reactive library to enable quick and easy development of Discord bots for Java, Kotlin, and other JVM languages using the official Discord Bot API.

null 1.5k Jan 4, 2023
Java regular expressions made easy.

JavaVerbalExpressions VerbalExpressions is a Java library that helps to construct difficult regular expressions. Getting Started Maven Dependency: <de

null 2.6k Dec 30, 2022
Diff Utils library is an OpenSource library for performing the comparison / diff operations between texts or some kind of data: computing diffs

Diff Utils library is an OpenSource library for performing the comparison / diff operations between texts or some kind of data: computing diffs, applying patches, generating unified diffs or parsing them, generating diff output for easy future displaying (like side-by-side view) and so on.

null 951 Jan 5, 2023
An open-source Java library for Constraint Programming

Documentation, Support and Issues Contributing Download and installation Choco-solver is an open-source Java library for Constraint Programming. Curre

null 607 Jan 3, 2023
Java rate limiting library based on token/leaky-bucket algorithm.

Java rate-limiting library based on token-bucket algorithm. Advantages of Bucket4j Implemented on top of ideas of well known algorithm, which are by d

Vladimir Bukhtoyarov 1.7k Jan 8, 2023
A Java library for designing good error messages

JDoctor, a Java library for good error messages Designing good error messages is hard. In Java, most often, developers just rely on throwing exception

Cédric Champeau 125 Oct 24, 2022
Ta4j is an open source Java library for technical analysis

Ta4j is an open source Java library for technical analysis. It provides the basic components for creation, evaluation and execution of trading strategies.

null 1.7k Dec 31, 2022
documents4j is a Java library for converting documents into another document format

documents4j is a Java library for converting documents into another document format. This is achieved by delegating the conversion to any

documents4j 455 Dec 23, 2022
java common utils library

java-common-utils java common utils library 一个简单的Java通用工具类,目前的设想,包括简化异常处理工具、简易限流处理工具等 ExceptionHandler, 目标简化try catch的代码冗余度

xuangy 2 Jan 21, 2022
A Java API for checking if text contains profanity via the alt-profanity-checker Python library.

ProfanityCheckerAPI A Java API for checking if text contains profanity via the alt-profanity-checker Python library. It uses jep to run and interpret

William 2 Feb 19, 2022