turbo-rails 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +44 -11
  3. data/lib/turbo/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff983944887ba8b8d1e4a8d57ade9136c0cd90c2976fe8782f230171e230d336
4
- data.tar.gz: 2ef010d91c693bc7a7b2303ca3c33f846ab9afbaca256fc81867900ac9c6c23d
3
+ metadata.gz: 28c080e3a84615eaf3dde1933e936c3441dc46dbc640ecf085339a09d92200b8
4
+ data.tar.gz: 8935d3bd821b8003e86f72d544608906b157e4c98c13dfe7bf2208c97738b715
5
5
  SHA512:
6
- metadata.gz: 768102dbc9f24bfe7cc1b6b4ae82b4f807daf572a3236921e6a835af1ce2d0f4799785d7e584de423e54b6b85938fa46b94db7e0b61391a9ae1d709811b11797
7
- data.tar.gz: d10cebaf8f52440567f0d1ca106fd07734e54c409d87da091ec9f0f4a8f4af47452e9ea8011f8ca3e02b4c2f847f2fbc4bb268410a5c85383c729f366548e407
6
+ metadata.gz: 80e07d3e9e22ab1e9b365aa3ac71ae7da180a8be2180bed8d2f67fcb7e4afc0503e2faec852e58c5dc45979c8733ec7eca41f73d76488cc0aea6bee72f05b7cb
7
+ data.tar.gz: 0731ac4e6b1faa44fedd7dc2bfe5602cdeafec1669941f42dd46af9e9cda0bcd8e898b7d6823aa1c41f031fb5204091394ba9203845629d065daa213eb9dbf58
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
- # Turbo
1
+ # <img src="assets/logo.png?sanitize=true" width="24" height="24" alt="Turbo"> Turbo
2
2
 
3
3
  [Turbo](https://turbo.hotwired.dev) gives you the speed of a single-page web application without having to write any JavaScript. Turbo accelerates links and form submissions without requiring you to change your server-side generated HTML. It lets you carve up a page into independent frames, which can be lazy-loaded and operate as independent components. And finally, helps you make partial page updates using just HTML and a set of CRUD-like container tags. These three techniques reduce the amount of custom JavaScript that many web applications need to write by an order of magnitude. And for the few dynamic bits that are left, you're invited to finish the job with [Stimulus](https://github.com/hotwired/stimulus).
4
4
 
5
- On top of accelerating web applications, Turbo was built from the ground-up to form the foundation of hybrid native applications. Write the navigational shell of your Android or iOS app using the standard platform tooling, then seamlessly fill in features from the web, following native navigation patterns. Not every mobile screen needs to be written in Swift or Kotlin to feel native. With Turbo, you spend less time wrangling JSON, waiting on app stores to approve updates, or reimplementing features you've already created in HTML.
5
+ On top of accelerating web applications, Turbo was built from the ground-up to form the foundation of hybrid native applications. Write the navigational shell of your [Android](https://github.com/hotwired/turbo-android) or [iOS](https://github.com/hotwired/turbo-ios) app using the standard platform tooling, then seamlessly fill in features from the web, following native navigation patterns. Not every mobile screen needs to be written in Swift or Kotlin to feel native. With Turbo, you spend less time wrangling JSON, waiting on app stores to approve updates, or reimplementing features you've already created in HTML.
6
6
 
7
7
  Turbo is a language-agnostic framework written in TypeScript, but this gem builds on top of those basics to make the integration with Rails as smooth as possible. You can deliver turbo updates via model callbacks over Action Cable, respond to controller actions with native navigation or standard redirects, and render turbo frames with helpers and layout-free responses.
8
8
 
9
9
 
10
- ## Turbo Drive
10
+ ## Navigate with Turbo Drive
11
11
 
12
- Turbo is a continuation of the ideas from the previous Turbolinks framework, and the heart of that past approach lives on as Turbo Drive. When installed, Turbo automatically intercepts all clicks on `<a href>` links to the same domain. When you click an eligible link, Turbo prevents the browser from following it. Instead, Turbo changes the browser’s URL using the History API, requests the new page using `fetch`, and then renders the HTML response.
12
+ Turbo is a continuation of the ideas from the previous [Turbolinks](https://github.com/turbolinks/turbolinks) framework, and the heart of that past approach lives on as Turbo Drive. When installed, Turbo automatically intercepts all clicks on `<a href>` links to the same domain. When you click an eligible link, Turbo prevents the browser from following it. Instead, Turbo changes the browser’s URL using the History API, requests the new page using `fetch`, and then renders the HTML response.
13
13
 
14
14
  During rendering, Turbo replaces the current `<body>` element outright and merges the contents of the `<head>` element. The JavaScript window and document objects, and the HTML `<html>` element, persist from one rendering to the next.
15
15
 
@@ -24,31 +24,64 @@ Turbo.session.drive = false
24
24
 
25
25
  Then you can use `data-turbo="true"` to enable Drive on a per-element basis.
26
26
 
27
+ [See documentation](https://turbo.hotwired.dev/handbook/drive).
27
28
 
28
- ## Turbo Frames
29
+ ## Decompose with Turbo Frames
29
30
 
30
- Turbo reinvents the old HTML technique of frames without any of the drawbacks that lead to developers abandoning it. With Turbo Frames, you can treat a subset of the page as its own component, where links and form submissions replace only that part. This removes an entire class of problems around partial interactivity that before would have required custom JavaScript.
31
+ Turbo reinvents the old HTML technique of frames without any of the drawbacks that lead to developers abandoning it. With Turbo Frames, **you can treat a subset of the page as its own component**, where links and form submissions **replace only that part**. This removes an entire class of problems around partial interactivity that before would have required custom JavaScript.
31
32
 
32
- It also makes it dead easy to carve a single page into smaller pieces that can all live on their own cache timeline. While the bulk of the page might easily be cached between users, a small personalized toolbar perhaps cannot. With Turbo::Frames, you can designate the toolbar as a frame, which will be lazy-loaded automatically by the publicly-cached root page. This means simpler pages, easier caching schemes with fewer dependent keys, and all without needing to write a lick of custom JavaScript.
33
+ It also makes it dead easy to carve a single page into smaller pieces that can all live on their own cache timeline. While the bulk of the page might easily be cached between users, a small personalized toolbar perhaps cannot. With Turbo::Frames, you can designate the toolbar as a frame, which will be **lazy-loaded automatically** by the publicly-cached root page. This means simpler pages, easier caching schemes with fewer dependent keys, and all without needing to write a lick of custom JavaScript.
33
34
 
35
+ This gem provides a `turbo_frame_tag` helper to create those frame.
34
36
 
35
- ## Turbo Streams
37
+ For instance:
38
+ ```erb
39
+ <%# app/views/todos/show.html.erb %>
40
+ <%= turbo_frame_tag @todo do %>
41
+ <p><%= @todo.description %></p>
36
42
 
37
- Partial page updates that are delivered asynchronously over a web socket connection is the hallmark of modern, reactive web applications. With Turbo Streams, you can get all of that modern goodness using the existing server-side HTML you're already rendering to deliver the first page load. With a set of simple CRUD container tags, you can send HTML fragments over the web socket (or in response to direct interactions), and see the page change in response to new data. Again, no need to construct an entirely separate API, no need to wrangle JSON, no need to reimplement the HTML construction in JavaScript. Take the HTML you're already making, wrap it in an update tag, and, voila, your page comes alive.
43
+ <%= link_to 'Edit this todo', edit_todo_path(@todo) %>
44
+ <% end %>
45
+
46
+ <%# app/views/todos/edit.html.erb %>
47
+ <%= turbo_frame_tag @todo do %>
48
+ <%= render "form" %>
49
+
50
+ <%= link_to 'Cancel', todo_path(@todo) %>
51
+ <% end %>
52
+ ```
53
+
54
+ When the user will click on the `Edit this todo` link, as direct response to this direct user interaction, the turbo frame will be replaced with the one in the `edit.html.erb` page automatically.
55
+
56
+ [See documentation](https://turbo.hotwired.dev/handbook/frames).
57
+
58
+ ## Come Alive with Turbo Streams
59
+
60
+ Partial page updates that are **delivered asynchronously over a web socket connection** is the hallmark of modern, reactive web applications. With Turbo Streams, you can get all of that modern goodness using the existing server-side HTML you're already rendering to deliver the first page load. With a set of simple CRUD container tags, you can send HTML fragments over the web socket (or in response to direct interactions), and see the page change in response to new data. Again, **no need to construct an entirely separate API**, **no need to wrangle JSON**, **no need to reimplement the HTML construction in JavaScript**. Take the HTML you're already making, wrap it in an update tag, and, voila, your page comes alive.
38
61
 
39
62
  With this Rails integration, you can create these asynchronous updates directly in response to your model changes. Turbo uses Active Jobs to provide asynchronous partial rendering and Action Cable to deliver those updates to subscribers.
40
63
 
64
+ This gem provides a `turbo_stream_from` helper to create a turbo stream.
65
+
66
+ ```erb
67
+ <%# app/views/todos/show.html.erb %>
68
+ <%= turbo_stream_from dom_id(@todo) %>
69
+
70
+ <%# Rest of show here %>
71
+ ```
72
+
73
+ [See documentation](https://turbo.hotwired.dev/handbook/streams).
41
74
 
42
75
  ## Installation
43
76
 
44
- The JavaScript for Turbo can either be run through the asset pipeline, which is included with this gem, or through the package that lives on NPM, through Webpacker.
77
+ This gem is automatically configured for applications made with Rails 7+ (unless --skip-hotwire is passed to the generator). But if you're on Rails 6, you can install it manually:
45
78
 
46
79
  1. Add the `turbo-rails` gem to your Gemfile: `gem 'turbo-rails'`
47
80
  2. Run `./bin/bundle install`
48
81
  3. Run `./bin/rails turbo:install`
49
82
  4. Run `./bin/rails turbo:install:redis` to change the development Action Cable adapter from Async (the default one) to Redis. The Async adapter does not support Turbo Stream broadcasting.
50
83
 
51
- Running `turbo:install` will install through NPM if Webpacker is installed in the application. Otherwise the asset pipeline version is used. To use the asset pipeline version, you must have `importmap-rails` installed first and listed higher in the Gemfile.
84
+ Running `turbo:install` will install through NPM if Node.js is used in the application. Otherwise the asset pipeline version is used. To use the asset pipeline version, you must have `importmap-rails` installed first and listed higher in the Gemfile.
52
85
 
53
86
  If you're using node and need to use the cable consumer, you can import [`cable`](https://github.com/hotwired/turbo-rails/blob/main/app/javascript/turbo/cable.js) (`import { cable } from "@hotwired/turbo-rails"`), but ensure that your application actually *uses* the members it `import`s when using this style (see [turbo-rails#48](https://github.com/hotwired/turbo-rails/issues/48)).
54
87
 
data/lib/turbo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Turbo
2
- VERSION = "0.9.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson