https://github.com/grace-plugins/grace-htmx
Grace Plugin for using Grace with htmx
https://github.com/grace-plugins/grace-htmx
grace graceframework grails htmx spring-boot
Last synced: about 2 months ago
JSON representation
Grace Plugin for using Grace with htmx
- Host: GitHub
- URL: https://github.com/grace-plugins/grace-htmx
- Owner: grace-plugins
- License: apache-2.0
- Created: 2024-02-02T05:07:39.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-07-05T07:56:00.000Z (9 months ago)
- Last Synced: 2025-07-05T08:38:10.242Z (9 months ago)
- Topics: grace, graceframework, grails, htmx, spring-boot
- Language: JavaScript
- Homepage: https://plugins.graceframework.org/grace-htmx/latest/
- Size: 1.67 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/grace-plugins/grace-htmx/actions?query=workflow%3A%Grace+CI%22)
[](https://opensource.org/licenses/Apache-2.0)
[](https://search.maven.org/search?q=g:org.graceframework.plugins)
[](https://plugins.graceframework.org/grace-htmx/0.9.x/)
[](https://x.com/graceframework)
[](https://groovy-lang.org/releasenotes/groovy-3.0.html)
[](https://github.com/graceframework/grace-framework/releases/tag/v2022.2.8)
# Grace with Htmx
Grace Plugin for using Grace/Grails app with htmx.
## Ducumentation
* [0.9.x](https://plugins.graceframework.org/grace-htmx/0.9.x/)
## Usage
Add dependency to the `build.gradle`,
```gradle
repositories {
mavenCentral()
}
dependencies {
implementation "org.graceframework.plugins:htmx:VERSION"
}
```
Htmx plugin supports controller-specific `withFormat()` method,
```groovy
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,
```groovy
// 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'
```
If you use [`respond`](https://grails.github.io/legacy-grails-doc/4.0.0/ref/Controllers/respond.html) method introduced in Grails 2.3. The respond method tries to produce the most appropriate response for the requested content type (JSON, XML, HTML etc.)
You can [configure mime types](https://grails.github.io/legacy-grails-doc/4.0.0/guide/theWebLayer.html#contentNegotiation) for Htmx.
Update the `app/conf/application.yml`:
```yml
grails:
mime:
types:
htmx: text/html
```
For example given the show action:
```groovy
def show(Book book) {
respond book
}
```
You could supply a `show.htmx.gsp` file to render the HTMX:
```html
${book.title}
${book.description}
```
If you use `asset-pipeline` plugin, this plugin already includes `htmx.js`, `hyperscript.js`,
so you can add `htmx.js` to the `app/assets/application.js`,
```javascript
//= require hyperscript
//= require htmx
//= require_self
```
Also, you can use `asset` tag in the GSP,
```HTML
```
> [!TIP]
> Add `hyperscript.js` to `assets.minifyOptions.excludes` If your app has an error when compiling assets.
```bash
hyperscript.unminified.js:85:24: ERROR - [JSC_PARSE_ERROR] Parse error. '(' expected
85| static OP_TABLE = {
^
1 error(s), 0 warning(s)
Closure uglify JS Exception
asset.pipeline.processors.MinifyException: [JSC_PARSE_ERROR. Parse error. '(' expected at hyperscript.unminified.js line 85 : 24]
at asset.pipeline.processors.ClosureCompilerProcessor.process(ClosureCompilerProcessor.groovy:81)
at asset.pipeline.processors.ClosureCompilerProcessor$process.call(Unknown Source)
at asset.pipeline.AssetCompiler$_compile_closure4.doCall(AssetCompiler.groovy:171)
```
```gradle
assets {
minifyJs = true
minifyCss = true
minifyOptions = [
excludes: ['hyperscript.js'],
languageMode: 'ES6',
targetLanguage: 'ES6', //Can go from ES6 to ES5 for those bleeding edgers
optimizationLevel: 'SIMPLE' //Or ADVANCED or WHITESPACE_ONLY
]
}
```
## Example
* [Grace Htmx TodoMVC](https://github.com/grace-guides/gs-htmx-todomvc)
## Development
### Build from source
```
git clone https://github.com/grace-plugins/grace-htmx.git
cd grace-htmx
./gradlew publishToMavenLocal
```
## Support Version
### Versions
To make it easier for users to use and upgrade, Plugin adopts a version policy consistent with the [Grace Framework](https://github.com/graceframework/grace-framework).
| Plugin Version | Grace Version |
|----------------|---------------|
| 1.0.x | 2023.0+ |
| 0.9.x | 2022.0+ |
## License
This plugin is available as open source under the terms of the [APACHE LICENSE, VERSION 2.0](http://apache.org/Licenses/LICENSE-2.0)
## Links
- [Grace Framework](https://github.com/graceframework/grace-framework)
- [Grace Plugins](https://github.com/grace-plugins)
- [Grace Htmx Plugin](https://github.com/grace-plugins/grace-htmx)
- [Grace Htmx TodoMVC](https://github.com/grace-guides/gs-htmx-todomvc)
- [Grails Htmx TodoMVC](https://github.com/rainboyan/grails-htmx-todomvc)