turbo-rails 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +24 -0
- data/.gitignore +2 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +147 -0
- data/MIT-LICENSE +20 -0
- data/README.md +66 -0
- data/Rakefile +11 -0
- data/app/assets/javascripts/turbo.js +3161 -0
- data/app/channels/turbo/streams/broadcasts.rb +66 -0
- data/app/channels/turbo/streams/stream_name.rb +24 -0
- data/app/channels/turbo/streams_channel.rb +17 -0
- data/app/controllers/turbo/frames/frame_request.rb +24 -0
- data/app/controllers/turbo/native/navigation.rb +49 -0
- data/app/controllers/turbo/native/navigation_controller.rb +13 -0
- data/app/controllers/turbo/streams/turbo_streams_tag_builder.rb +22 -0
- data/app/helpers/turbo/drive_helper.rb +16 -0
- data/app/helpers/turbo/frames_helper.rb +23 -0
- data/app/helpers/turbo/includes_helper.rb +5 -0
- data/app/helpers/turbo/streams/action_helper.rb +25 -0
- data/app/helpers/turbo/streams_helper.rb +22 -0
- data/app/javascript/turbo/cable.js +16 -0
- data/app/javascript/turbo/cable_stream_source_element.js +27 -0
- data/app/javascript/turbo/index.js +3 -0
- data/app/jobs/turbo/streams/action_broadcast_job.rb +6 -0
- data/app/jobs/turbo/streams/broadcast_job.rb +7 -0
- data/app/models/concerns/turbo/broadcastable.rb +236 -0
- data/app/models/turbo/streams/tag_builder.rb +127 -0
- data/config/routes.rb +6 -0
- data/lib/install/turbo.rb +11 -0
- data/lib/tasks/turbo_tasks.rake +6 -0
- data/lib/turbo-rails.rb +17 -0
- data/lib/turbo/engine.rb +65 -0
- data/lib/turbo/test_assertions.rb +22 -0
- data/lib/turbo/version.rb +3 -0
- data/package.json +42 -0
- data/rollup.config.js +23 -0
- data/test/drive/drive_helper_test.rb +8 -0
- data/test/dummy/.babelrc +18 -0
- data/test/dummy/.gitignore +3 -0
- data/test/dummy/.postcssrc.yml +3 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +2 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +80 -0
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/controllers/messages_controller.rb +12 -0
- data/test/dummy/app/controllers/trays_controller.rb +17 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/javascript/packs/application.js +0 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailboxes/application_mailbox.rb +2 -0
- data/test/dummy/app/mailboxes/messages_mailbox.rb +4 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/models/message.rb +29 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/app/views/messages/_message.html.erb +1 -0
- data/test/dummy/app/views/messages/_message.turbo_stream.erb +1 -0
- data/test/dummy/app/views/messages/show.turbo_stream.erb +9 -0
- data/test/dummy/app/views/trays/index.html.erb +3 -0
- data/test/dummy/app/views/trays/show.html.erb +3 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +36 -0
- data/test/dummy/bin/update +31 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +22 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +34 -0
- data/test/dummy/config/environments/production.rb +96 -0
- data/test/dummy/config/environments/test.rb +38 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +14 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/content_security_policy.rb +22 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +34 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/config/webpack/development.js +3 -0
- data/test/dummy/config/webpack/environment.js +3 -0
- data/test/dummy/config/webpack/production.js +3 -0
- data/test/dummy/config/webpack/test.js +3 -0
- data/test/dummy/config/webpacker.yml +65 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/frames/frame_request_controller_test.rb +21 -0
- data/test/frames/frames_helper_test.rb +15 -0
- data/test/native/navigation_controller_test.rb +42 -0
- data/test/streams/broadcastable_test.rb +80 -0
- data/test/streams/streams_channel_test.rb +105 -0
- data/test/streams/streams_controller_test.rb +29 -0
- data/test/turbo_test.rb +10 -0
- data/turbo-rails.gemspec +16 -0
- data/yarn.lock +282 -0
- metadata +254 -0
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class MessagesController < ApplicationController
|
|
2
|
+
def show
|
|
3
|
+
@message = Message.new(record_id: 1, content: "My message")
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def create
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
format.html { redirect_to message_url(id: 1) }
|
|
9
|
+
format.turbo_stream { render turbo_stream: turbo_stream.append(:messages, "message_1") }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class TraysController < ApplicationController
|
|
2
|
+
def show
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
def create
|
|
6
|
+
case params[:return_to]
|
|
7
|
+
when "recede_or_redirect" then recede_or_redirect_to tray_url(id: 1)
|
|
8
|
+
when "resume_or_redirect" then resume_or_redirect_to tray_url(id: 1)
|
|
9
|
+
when "refresh_or_redirect" then refresh_or_redirect_to tray_url(id: 1)
|
|
10
|
+
when "recede_or_redirect_back" then recede_or_redirect_back_or_to tray_url(id: 5)
|
|
11
|
+
when "resume_or_redirect_back" then resume_or_redirect_back_or_to tray_url(id: 5)
|
|
12
|
+
when "refresh_or_redirect_back" then refresh_or_redirect_back_or_to tray_url(id: 5)
|
|
13
|
+
else
|
|
14
|
+
raise "Supply return_to to direct response"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class Message
|
|
2
|
+
include Turbo::Broadcastable
|
|
3
|
+
|
|
4
|
+
attr_reader :record_id, :content
|
|
5
|
+
|
|
6
|
+
def initialize(record_id:, content:)
|
|
7
|
+
@record_id, @content = record_id, content
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def to_key
|
|
11
|
+
[ record_id ]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_param
|
|
15
|
+
"message:#{record_id}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_partial_path
|
|
19
|
+
"messages/message"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_s
|
|
23
|
+
content
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def model_name
|
|
27
|
+
ActiveModel::Name.new(self.class)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= yield %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<p><%= message %></p>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= turbo_stream.replace "message_1" do %>Goodbye!<% end %>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%= turbo_stream.remove @message %>
|
|
2
|
+
<%= turbo_stream.replace @message %>
|
|
3
|
+
<%= turbo_stream.replace @message, "Something else" %>
|
|
4
|
+
<%= turbo_stream.replace "message_5", "Something fifth" %>
|
|
5
|
+
<%= turbo_stream.replace "message_5", partial: "messages/message", locals: { message: Message.new(record_id: 5, content: "OLLA!") } %>
|
|
6
|
+
<%= turbo_stream.append "messages", @message %>
|
|
7
|
+
<%= turbo_stream.append "messages", partial: "messages/message", locals: { message: Message.new(record_id: 5, content: "OLLA!") } %>
|
|
8
|
+
<%= turbo_stream.prepend "messages", @message %>
|
|
9
|
+
<%= turbo_stream.prepend "messages", partial: "messages/message", locals: { message: Message.new(record_id: 5, content: "OLLA!") } %>
|
data/test/dummy/bin/rake
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
include FileUtils
|
|
4
|
+
|
|
5
|
+
# path to your application root.
|
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
|
7
|
+
|
|
8
|
+
def system!(*args)
|
|
9
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
chdir APP_ROOT do
|
|
13
|
+
# This script is a starting point to setup your application.
|
|
14
|
+
# Add necessary setup steps to this file.
|
|
15
|
+
|
|
16
|
+
puts '== Installing dependencies =='
|
|
17
|
+
system! 'gem install bundler --conservative'
|
|
18
|
+
system('bundle check') || system!('bundle install')
|
|
19
|
+
|
|
20
|
+
# Install JavaScript dependencies if using Yarn
|
|
21
|
+
# system('bin/yarn')
|
|
22
|
+
|
|
23
|
+
# puts "\n== Copying sample files =="
|
|
24
|
+
# unless File.exist?('config/database.yml')
|
|
25
|
+
# cp 'config/database.yml.sample', 'config/database.yml'
|
|
26
|
+
# end
|
|
27
|
+
|
|
28
|
+
puts "\n== Preparing database =="
|
|
29
|
+
system! 'bin/rails db:setup'
|
|
30
|
+
|
|
31
|
+
puts "\n== Removing old logs and tempfiles =="
|
|
32
|
+
system! 'bin/rails log:clear tmp:clear'
|
|
33
|
+
|
|
34
|
+
puts "\n== Restarting application server =="
|
|
35
|
+
system! 'bin/rails restart'
|
|
36
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
include FileUtils
|
|
4
|
+
|
|
5
|
+
# path to your application root.
|
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
|
7
|
+
|
|
8
|
+
def system!(*args)
|
|
9
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
chdir APP_ROOT do
|
|
13
|
+
# This script is a way to update your development environment automatically.
|
|
14
|
+
# Add necessary update steps to this file.
|
|
15
|
+
|
|
16
|
+
puts '== Installing dependencies =='
|
|
17
|
+
system! 'gem install bundler --conservative'
|
|
18
|
+
system('bundle check') || system!('bundle install')
|
|
19
|
+
|
|
20
|
+
# Install JavaScript dependencies if using Yarn
|
|
21
|
+
# system('bin/yarn')
|
|
22
|
+
|
|
23
|
+
puts "\n== Updating database =="
|
|
24
|
+
system! 'bin/rails db:migrate'
|
|
25
|
+
|
|
26
|
+
puts "\n== Removing old logs and tempfiles =="
|
|
27
|
+
system! 'bin/rails log:clear tmp:clear'
|
|
28
|
+
|
|
29
|
+
puts "\n== Restarting application server =="
|
|
30
|
+
system! 'bin/rails restart'
|
|
31
|
+
end
|
data/test/dummy/bin/yarn
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
|
3
|
+
Dir.chdir(APP_ROOT) do
|
|
4
|
+
begin
|
|
5
|
+
exec "yarnpkg", *ARGV
|
|
6
|
+
rescue Errno::ENOENT
|
|
7
|
+
$stderr.puts "Yarn executable was not detected in the system."
|
|
8
|
+
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
|
|
9
|
+
exit 1
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require_relative 'boot'
|
|
2
|
+
|
|
3
|
+
require "action_controller/railtie"
|
|
4
|
+
require "action_cable/engine"
|
|
5
|
+
require "active_job/railtie"
|
|
6
|
+
require "active_model/railtie"
|
|
7
|
+
require "sprockets/railtie"
|
|
8
|
+
|
|
9
|
+
Bundler.require(*Rails.groups)
|
|
10
|
+
|
|
11
|
+
module Dummy
|
|
12
|
+
class Application < Rails::Application
|
|
13
|
+
# Initialize configuration defaults for originally generated Rails version.
|
|
14
|
+
config.load_defaults 6.0
|
|
15
|
+
|
|
16
|
+
# Settings in config/environments/* take precedence over those specified here.
|
|
17
|
+
# Application configuration can go into files in config/initializers
|
|
18
|
+
# -- all .rb files in that directory are automatically loaded after loading
|
|
19
|
+
# the framework and any gems in your application.
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Rails.application.configure do
|
|
2
|
+
# Verifies that versions and hashed value of the package contents in the project's package.json
|
|
3
|
+
# config.webpacker.check_yarn_integrity = true
|
|
4
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
|
5
|
+
|
|
6
|
+
# In the development environment your application's code is reloaded on
|
|
7
|
+
# every request. This slows down response time but is perfect for development
|
|
8
|
+
# since you don't have to restart the web server when you make code changes.
|
|
9
|
+
config.cache_classes = false
|
|
10
|
+
|
|
11
|
+
# Do not eager load code on boot.
|
|
12
|
+
config.eager_load = false
|
|
13
|
+
|
|
14
|
+
# Show full error reports.
|
|
15
|
+
config.consider_all_requests_local = true
|
|
16
|
+
|
|
17
|
+
# Enable/disable caching. By default caching is disabled.
|
|
18
|
+
# Run rails dev:cache to toggle caching.
|
|
19
|
+
if Rails.root.join('tmp', 'caching-dev.txt').exist?
|
|
20
|
+
config.action_controller.perform_caching = true
|
|
21
|
+
|
|
22
|
+
config.cache_store = :memory_store
|
|
23
|
+
config.public_file_server.headers = {
|
|
24
|
+
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
config.action_controller.perform_caching = false
|
|
28
|
+
|
|
29
|
+
config.cache_store = :null_store
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Print deprecation notices to the Rails logger.
|
|
33
|
+
config.active_support.deprecation = :log
|
|
34
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Rails.application.configure do
|
|
2
|
+
# Verifies that versions and hashed value of the package contents in the project's package.json
|
|
3
|
+
config.webpacker.check_yarn_integrity = false
|
|
4
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
|
5
|
+
|
|
6
|
+
# Code is not reloaded between requests.
|
|
7
|
+
config.cache_classes = true
|
|
8
|
+
|
|
9
|
+
# Eager load code on boot. This eager loads most of Rails and
|
|
10
|
+
# your application in memory, allowing both threaded web servers
|
|
11
|
+
# and those relying on copy on write to perform better.
|
|
12
|
+
# Rake tasks automatically ignore this option for performance.
|
|
13
|
+
config.eager_load = true
|
|
14
|
+
|
|
15
|
+
# Full error reports are disabled and caching is turned on.
|
|
16
|
+
config.consider_all_requests_local = false
|
|
17
|
+
config.action_controller.perform_caching = true
|
|
18
|
+
|
|
19
|
+
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
|
|
20
|
+
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
|
|
21
|
+
# config.require_master_key = true
|
|
22
|
+
|
|
23
|
+
# Disable serving static files from the `/public` folder by default since
|
|
24
|
+
# Apache or NGINX already handles this.
|
|
25
|
+
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
|
26
|
+
|
|
27
|
+
# Compress JavaScripts and CSS.
|
|
28
|
+
config.assets.js_compressor = :uglifier
|
|
29
|
+
# config.assets.css_compressor = :sass
|
|
30
|
+
|
|
31
|
+
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
|
32
|
+
config.assets.compile = false
|
|
33
|
+
|
|
34
|
+
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
|
|
35
|
+
|
|
36
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
|
37
|
+
# config.action_controller.asset_host = 'http://assets.example.com'
|
|
38
|
+
|
|
39
|
+
# Specifies the header that your server uses for sending files.
|
|
40
|
+
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
|
41
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
|
42
|
+
|
|
43
|
+
# Store uploaded files on the local file system (see config/storage.yml for options)
|
|
44
|
+
config.active_storage.service = :local
|
|
45
|
+
|
|
46
|
+
# Mount Action Cable outside main process or domain
|
|
47
|
+
# config.action_cable.mount_path = nil
|
|
48
|
+
# config.action_cable.url = 'wss://example.com/cable'
|
|
49
|
+
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
|
|
50
|
+
|
|
51
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
|
52
|
+
# config.force_ssl = true
|
|
53
|
+
|
|
54
|
+
# Use the lowest log level to ensure availability of diagnostic information
|
|
55
|
+
# when problems arise.
|
|
56
|
+
config.log_level = :debug
|
|
57
|
+
|
|
58
|
+
# Prepend all log lines with the following tags.
|
|
59
|
+
config.log_tags = [ :request_id ]
|
|
60
|
+
|
|
61
|
+
# Use a different cache store in production.
|
|
62
|
+
# config.cache_store = :mem_cache_store
|
|
63
|
+
|
|
64
|
+
# Use a real queuing backend for Active Job (and separate queues per environment)
|
|
65
|
+
# config.active_job.queue_adapter = :resque
|
|
66
|
+
# config.active_job.queue_name_prefix = "dummy_#{Rails.env}"
|
|
67
|
+
|
|
68
|
+
config.action_mailer.perform_caching = false
|
|
69
|
+
|
|
70
|
+
# Ignore bad email addresses and do not raise email delivery errors.
|
|
71
|
+
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
|
72
|
+
# config.action_mailer.raise_delivery_errors = false
|
|
73
|
+
|
|
74
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
|
75
|
+
# the I18n.default_locale when a translation cannot be found).
|
|
76
|
+
config.i18n.fallbacks = true
|
|
77
|
+
|
|
78
|
+
# Send deprecation notices to registered listeners.
|
|
79
|
+
config.active_support.deprecation = :notify
|
|
80
|
+
|
|
81
|
+
# Use default logging formatter so that PID and timestamp are not suppressed.
|
|
82
|
+
config.log_formatter = ::Logger::Formatter.new
|
|
83
|
+
|
|
84
|
+
# Use a different logger for distributed setups.
|
|
85
|
+
# require 'syslog/logger'
|
|
86
|
+
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
|
87
|
+
|
|
88
|
+
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
|
89
|
+
logger = ActiveSupport::Logger.new(STDOUT)
|
|
90
|
+
logger.formatter = config.log_formatter
|
|
91
|
+
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Do not dump schema after migrations.
|
|
95
|
+
config.active_record.dump_schema_after_migration = false
|
|
96
|
+
end
|