turbo
turbo
This shard provides the server-side Turbo component of Hotwire
Installation
-
Add the dependency to your
shard.yml
:dependencies: turbo: github: jgaskins/turbo
-
Run
shards install
Usage
There are several components to choose from:
turbo.js
: the client-side JavaScript bindings to tell the browser how to interpret the server-side functionalityTurbo
: Basic server-side bindings for rendering Turbo frames and streamsCable
: ActionCable-compliant server-side library for propagating Turbo frames and streams to browser clients
Feature | turbo.js | Turbo | Cable |
---|---|---|---|
Basic Turbo Frames | Necessary | Helpful | Unnecessary |
|
require "turbo"
Load client-side JavaScript
Turbo's client-side JavaScript is what tells the browser how to interpret what we're rendering on the server side. If you have a JavaScript build tool, it's as simple as:
import * as Turbo from "@hotwired/turbo"
If not, you can simply load it with a <script>
tag:
<script src="https://unpkg.com/@hotwired/turbo"></script>
Rendering Turbo Frames into HTML
Turbo Frames are the basic building block of a Turbo-enhanced UI.
Rendering to a raw response
The Turbo::Frames.render_turbo_frame
helper allows you to render to a basic IO
object (such as an HTTP::Server::Response
)
With the Lucky framework
Write a Lucky component and include Lucky::Turbo
into it:
class LastRenderedAt < BaseComponent
def render
span "Last rendered at #{time}"
end
end
Then from inside your Page
, mount the component within a turbo_frame
:
require "turbo/lucky"
class Home::IndexPage < MainLayout
include Lucky::Turbo
def content
div do
turbo_frame "stuff" { mount LastRenderedAt }
end
end
end
Contributing
- Fork it (https://github.com/jgaskins/turbo/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Jamie Gaskins - creator and maintainer
turbo
- 19
- 4
- 1
- 0
- 0
- about 1 year ago
- February 4, 2021
MIT License
Sun, 17 Nov 2024 10:05:56 GMT