Grace Plugin for using Grace/Grails app with Unpoly.js.
Add dependency to the build.gradle
,
repositories {
mavenCentral()
}
dependencies {
implementation "org.graceframework.plugins:unpoly:VERSION"
}
Unpoly plugin supports controller-specific withFormat()
method,
class BookController {
def list() {
def books = Book.list()
withFormat {
unpoly {
render(template: "book", model: [bookList: books])
}
json {
render books as JSON
}
}
}
}
Also, this plugin supports extendsions for Grails Request and Response,
// You can get unpoly request headers from Grails Request
request.unpoly.version == request.getHeader('X-UP-Version')
request.unpoly.target == request.getHeader('X-UP-Target')
// Check Unpoly request?
if (request.unpoly as boolean) { // or use request.isUnpoly()
template = 'book-detail'
}
// You can set Unpoly response headers in Grails
response.unpoly.target = '.content'
response.unpoly.events = JsonOutput.toJson([["type": "itemDeleted"]])
If you use respond
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 for Unpoly.
Update the app/conf/application.yml
:
grails:
mime:
types:
up: text/html
For example given the show action:
def show(Book book) {
respond book
}
You could supply a show.up.gsp
file to render the Unpoly:
<div id="${book.id}">
<h1>${book.title}</h1>
<p>${book.description}</p>
</div>
git clone https://github.com/grace-plugins/grace-unpoly.git
cd grace-unpoly
./gradlew publishToMavenLocal
- Grace 2022.0.0+
- Grails 3.0+
- Unpoly 3.x
This plugin is available as open source under the terms of the APACHE LICENSE, VERSION 2.0