Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Latest commit

 

History

History
110 lines (72 loc) · 2.19 KB

README.md

File metadata and controls

110 lines (72 loc) · 2.19 KB

Announcement

In order to support both Grails and Grace, reduce maintenance costs, and focus on developing new features, this repository is no longer being updated!

Please use grace-plugins/grace-htmx, it supports both Grails 3+ and Grace 2022!

Grails with Htmx

Grails Plugin for using Grails with htmx.

Usage

Add dependency to the build.gradle,

repositories {
    mavenCentral()
}

dependencies {

    // Grails 4
    compile "org.rainboyan.plugins:grails-plugin-htmx:0.0.2"

    // Grails 5+
    implementation "org.rainboyan.plugins:grails-plugin-htmx:0.0.2"
}

Htmx plugin supports controller-specific withFormat() method,

class BookController {

    def list() {
        def books = Book.list()

        withFormat {
            htmx {
                render(template: "book", model: [bookList: books])
            }
            json {
                render books as JSON
            }
        }
    }
}

Also, this plugin supports extendsions for Grails Request and Response,

// You can get htmx request headers from Grails Request

request.htmx.boosted == request.getHeader('HX-Boosted')
request.htmx.target  == request.getHeader('HX-Target')

// Check htmx request?
if (request.htmx as boolean) { // or use request.isHtmx()
    template = 'book-detail'
}

// You can set htmx response headers in Grails

response.htmx.trigger = 'itemAdded'

Example

Development

Build from source

git clone https://github.com/rainboyan/grails-htmx.git
cd grails-htmx
./gradlew publishToMavenLocal

Support Grails Version

  • Grails 4.0, 4.1
  • Grails 5.0, 5.1, 5.2, 5.3
  • Grails 6.0

Roadmap

1.x

  • Htmx 1.9

2.x

  • Htmx 2.0

License

This plugin is available as open source under the terms of the APACHE LICENSE, VERSION 2.0

Links