Skip to content

Commit d06e414

Browse files
committed
Update README
1 parent 158c47d commit d06e414

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,136 @@
1414
This plugin will help you to develop Grace app with Hotwire Turo and Stimulus.
1515

1616

17+
## Usage
18+
19+
Add dependency to the `build.gradle`,
20+
21+
```gradle
22+
23+
repositories {
24+
mavenCentral()
25+
}
26+
27+
dependencies {
28+
implementation "org.graceframework.plugins:stimulus:VERSION"
29+
implementation "org.graceframework.plugins:turbo:VERSION"
30+
}
31+
```
32+
33+
Turbo plugin supports controller-specific `withFormat()` method,
34+
35+
```groovy
36+
class BookController {
37+
38+
def list() {
39+
def books = Book.list()
40+
41+
withFormat {
42+
turbo_stream {
43+
render(template: "book", model: [bookList: books])
44+
}
45+
json {
46+
render books as JSON
47+
}
48+
}
49+
}
50+
}
51+
```
52+
53+
Also, this plugin supports extendsions for Grails Request and Response,
54+
55+
```groovy
56+
// You can get Turbo request headers from Grails Request
57+
58+
request.turboFrameId == request.getHeader('Turbo-Frame')
59+
request.turboRequestId == request.getHeader('X-Turbo-Request-ID')
60+
61+
// Check if Turbo Request?
62+
if (request.isTurboRequest()) {
63+
template = 'book-detail'
64+
}
65+
66+
// Check if Turbo Frame?
67+
if (request.isTurboFrame()) {
68+
template = 'book-detail'
69+
}
70+
71+
// Check if Turbo Stream?
72+
if (request.isTurboStream()) {
73+
template = 'book-detail'
74+
}
75+
```
76+
77+
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.)
78+
79+
This plugin already provides [Mime Types](https://grails.github.io/legacy-grails-doc/4.0.0/guide/theWebLayer.html#contentNegotiation) for Turbo Stream.
80+
81+
For example given the show action:
82+
83+
```groovy
84+
def show(Book book) {
85+
respond book
86+
}
87+
```
88+
89+
You could supply a `show.turbo_stream.gsp` file to render the Turbo Stream:
90+
91+
```html
92+
<turbo-stream action="append" target="books">
93+
<template>
94+
...
95+
</template>
96+
</turbo-stream>
97+
```
98+
99+
If you use `asset-pipeline` plugin, this plugin already includes `stimulus.js`, `turbo.js`,
100+
so you can add `stimulus.js` to the `app/assets/application.js`,
101+
102+
```javascript
103+
//= require stimulus
104+
//= require turbo
105+
//= require_self
106+
```
107+
108+
Also, you can use `asset` tag in the GSP,
109+
110+
```HTML
111+
<asset:javascript src="stimulus.js"/>
112+
<asset:javascript src="turbo.js"/>
113+
```
114+
115+
## Development
116+
117+
### Build from source
118+
119+
```
120+
git clone https://github.com/grace-plugins/grace-hotwire.git
121+
cd grace-hotwire
122+
./gradlew publishToMavenLocal
123+
```
124+
125+
## Support Version
126+
127+
* Grace 2022.0.0+
128+
* Grails 3.0+
129+
130+
## Roadmap
131+
132+
### 1.x
133+
134+
* Stimulus 3.2.2
135+
* Turbo 8.0.4
136+
137+
## License
138+
139+
This plugin is available as open source under the terms of the [APACHE LICENSE, VERSION 2.0](http://apache.org/Licenses/LICENSE-2.0)
140+
17141
## Links
18142

19143
- [Grace Framework](https://github.com/graceframework/grace-framework)
144+
- [Grace Plugins](https://github.com/grace-plugins)
145+
- [Grace Hotwire Plugin](https://github.com/grace-plugins/grace-hotewire)
146+
- [Grace Stimulus Gudie](https://github.com/grace-guides/gs-stimuls)
147+
- [Grace Turbo Guide](https://github.com/grace-guides/gs-turbo)
20148
- [Hotwire Turbo](https://turbo.hotwired.dev)
21149
- [Hotwire Stimulus](https://stimulus.hotwired.dev)

0 commit comments

Comments
 (0)