This shard provides the server-side Turbo component of Hotwire
-
Add the dependency to your
shard.yml
:dependencies: turbo: github: jgaskins/turbo
-
Run
shards install
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"
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>
Turbo Frames are the basic building block of a Turbo-enhanced UI.
The Turbo::Frames.render_turbo_frame
helper allows you to render to a basic IO
object (such as an HTTP::Server::Response
)
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
- 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
- Jamie Gaskins - creator and maintainer