├── test ├── helpers │ ├── .keep │ ├── frames_helper_test.rb │ └── streams_helper_test.rb ├── mailers │ └── .keep ├── models │ └── .keep ├── controllers │ ├── .keep │ └── streams_controller_test.rb ├── dummy │ ├── log │ │ └── .keep │ ├── lib │ │ └── assets │ │ │ └── .keep │ ├── public │ │ ├── favicon.ico │ │ ├── apple-touch-icon.png │ │ ├── apple-touch-icon-precomposed.png │ │ ├── 500.html │ │ ├── 422.html │ │ └── 404.html │ ├── app │ │ ├── assets │ │ │ ├── images │ │ │ │ └── .keep │ │ │ ├── config │ │ │ │ └── manifest.js │ │ │ └── stylesheets │ │ │ │ └── application.css │ │ ├── models │ │ │ ├── concerns │ │ │ │ └── .keep │ │ │ ├── application_record.rb │ │ │ └── article.rb │ │ ├── controllers │ │ │ ├── concerns │ │ │ │ └── .keep │ │ │ ├── application_controller.rb │ │ │ └── articles_controller.rb │ │ ├── views │ │ │ ├── layouts │ │ │ │ ├── mailer.text.erb │ │ │ │ ├── mailer.html.erb │ │ │ │ └── application.html.erb │ │ │ └── articles │ │ │ │ ├── update.turbo_stream.erb │ │ │ │ ├── create.turbo_stream.erb │ │ │ │ ├── edit.html.erb │ │ │ │ ├── new.html.erb │ │ │ │ ├── _form.html.erb │ │ │ │ ├── index.html.erb │ │ │ │ ├── show.turbo_stream.erb │ │ │ │ └── _article.html.erb │ │ ├── helpers │ │ │ └── application_helper.rb │ │ ├── channels │ │ │ └── application_cable │ │ │ │ ├── channel.rb │ │ │ │ └── connection.rb │ │ ├── mailers │ │ │ └── application_mailer.rb │ │ ├── javascript │ │ │ └── application.js │ │ └── jobs │ │ │ └── application_job.rb │ ├── vendor │ │ └── javascript │ │ │ └── .keep │ ├── config │ │ ├── routes.rb │ │ ├── environment.rb │ │ ├── boot.rb │ │ ├── cable.yml │ │ ├── importmap.rb │ │ ├── initializers │ │ │ ├── filter_parameter_logging.rb │ │ │ ├── permissions_policy.rb │ │ │ ├── assets.rb │ │ │ ├── inflections.rb │ │ │ └── content_security_policy.rb │ │ ├── database.yml │ │ ├── application.rb │ │ ├── locales │ │ │ └── en.yml │ │ ├── storage.yml │ │ ├── puma.rb │ │ └── environments │ │ │ ├── test.rb │ │ │ ├── development.rb │ │ │ └── production.rb │ ├── bin │ │ ├── rake │ │ ├── importmap │ │ ├── rails │ │ └── setup │ ├── test │ │ ├── models │ │ │ └── article_test.rb │ │ └── fixtures │ │ │ └── articles.yml │ ├── config.ru │ ├── db │ │ ├── migrate │ │ │ └── 20220628203340_create_articles.rb │ │ └── schema.rb │ └── Rakefile ├── integration │ ├── .keep │ └── navigation_test.rb ├── fixtures │ └── files │ │ └── .keep ├── turbo_clone_test.rb ├── test_helper.rb └── channels │ └── broadcastable_test.rb ├── app ├── models │ ├── concerns │ │ ├── .keep │ │ └── turbo_clone │ │ │ └── broadcastable.rb │ └── turbo_clone │ │ ├── application_record.rb │ │ └── streams │ │ └── tag_builder.rb ├── controllers │ ├── concerns │ │ ├── .keep │ │ └── turbo_clone │ │ │ └── streams │ │ │ └── turbo_streams_tag_builder.rb │ └── turbo_clone │ │ └── application_controller.rb ├── assets │ ├── images │ │ └── turbo_clone │ │ │ └── .keep │ ├── config │ │ └── turbo_clone_manifest.js │ └── stylesheets │ │ └── turbo_clone │ │ └── application.css ├── jobs │ └── turbo_clone │ │ ├── application_job.rb │ │ └── streams │ │ └── action_broadcast_job.rb ├── mailers │ └── turbo_clone │ │ └── application_mailer.rb ├── helpers │ └── turbo_clone │ │ ├── frames_helper.rb │ │ ├── streams_helper.rb │ │ └── action_helper.rb ├── views │ └── layouts │ │ └── turbo_clone │ │ └── application.html.erb └── channels │ └── turbo_clone │ ├── streams_channel.rb │ └── streams │ ├── stream_name.rb │ └── broadcasts.rb ├── config └── routes.rb ├── lib ├── turbo_clone │ ├── version.rb │ ├── test_assertions.rb │ └── engine.rb ├── install │ ├── turbo_with_importmap.rb │ └── turbo_needs_redis.rb ├── turbo_clone.rb └── tasks │ └── turbo_clone_tasks.rake ├── .gitignore ├── Rakefile ├── Gemfile ├── turbo_clone.gemspec ├── bin └── rails ├── MIT-LICENSE ├── README.md └── Gemfile.lock /test/helpers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/lib/assets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/files/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/assets/images/turbo_clone/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/assets/images/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/public/apple-touch-icon.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/vendor/javascript/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | TurboClone::Engine.routes.draw do 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /lib/turbo_clone/version.rb: -------------------------------------------------------------------------------- 1 | module TurboClone 2 | VERSION = "0.1.0" 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/assets/config/turbo_clone_manifest.js: -------------------------------------------------------------------------------- 1 | //= link_directory ../stylesheets/turbo_clone .css 2 | -------------------------------------------------------------------------------- /test/dummy/app/views/articles/update.turbo_stream.erb: -------------------------------------------------------------------------------- 1 | <%= turbo_stream.replace @article %> 2 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | resources :articles 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/jobs/turbo_clone/application_job.rb: -------------------------------------------------------------------------------- 1 | module TurboClone 2 | class ApplicationJob < ActiveJob::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /test/dummy/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/bin/importmap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require_relative "../config/application" 4 | require "importmap/commands" 5 | -------------------------------------------------------------------------------- /test/dummy/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/controllers/turbo_clone/application_controller.rb: -------------------------------------------------------------------------------- 1 | module TurboClone 2 | class ApplicationController < ActionController::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/views/articles/create.turbo_stream.erb: -------------------------------------------------------------------------------- 1 | <%= turbo_stream.update Article.new, "" %> 2 | <%= turbo_stream.prepend "articles", @article %> 3 | -------------------------------------------------------------------------------- /test/dummy/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: "from@example.com" 3 | layout "mailer" 4 | end 5 | -------------------------------------------------------------------------------- /app/models/turbo_clone/application_record.rb: -------------------------------------------------------------------------------- 1 | module TurboClone 2 | class ApplicationRecord < ActiveRecord::Base 3 | self.abstract_class = true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/app/javascript/application.js: -------------------------------------------------------------------------------- 1 | // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails 2 | import "@hotwired/turbo-rails" 3 | -------------------------------------------------------------------------------- /test/dummy/test/models/article_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ArticleTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/integration/navigation_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class NavigationTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/mailers/turbo_clone/application_mailer.rb: -------------------------------------------------------------------------------- 1 | module TurboClone 2 | class ApplicationMailer < ActionMailer::Base 3 | default from: "from@example.com" 4 | layout "mailer" 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /test/dummy/test/fixtures/articles.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | content: MyText 5 | 6 | two: 7 | content: MyText 8 | -------------------------------------------------------------------------------- /test/turbo_clone_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class TurboCloneTest < ActiveSupport::TestCase 4 | test "it has a version number" do 5 | assert TurboClone::VERSION 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /doc/ 3 | /log/*.log 4 | /pkg/ 5 | /tmp/ 6 | /test/dummy/db/*.sqlite3 7 | /test/dummy/db/*.sqlite3-* 8 | /test/dummy/log/*.log 9 | /test/dummy/storage/ 10 | /test/dummy/tmp/ 11 | -------------------------------------------------------------------------------- /lib/install/turbo_with_importmap.rb: -------------------------------------------------------------------------------- 1 | say "Import Turbo" 2 | append_to_file "app/javascript/application.js", %(import "@hotwired/turbo-rails") 3 | 4 | say "Pin Turbo" 5 | run "importmap pin @hotwired/turbo-rails@7.1.1" 6 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | 3 | APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__) 4 | load "rails/tasks/engine.rake" 5 | 6 | load "rails/tasks/statistics.rake" 7 | 8 | require "bundler/gem_tasks" 9 | -------------------------------------------------------------------------------- /test/dummy/app/views/articles/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Edit article

2 | 3 | <%= link_to "Back", articles_path %> 4 | 5 | <%= turbo_frame_tag @article do %> 6 | <%= render "articles/form", article: @article %> 7 | <% end %> 8 | -------------------------------------------------------------------------------- /test/dummy/app/views/articles/new.html.erb: -------------------------------------------------------------------------------- 1 |

New article

2 | 3 | <%= link_to "Back", articles_path %> 4 | 5 | <%= turbo_frame_tag @article do %> 6 | <%= render "articles/form", article: @article %> 7 | <% end %> 8 | -------------------------------------------------------------------------------- /test/dummy/app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../stylesheets .css 3 | //= link turbo_clone_manifest.js 4 | //= link_tree ../../javascript .js 5 | //= link_tree ../../../vendor/javascript .js 6 | -------------------------------------------------------------------------------- /app/controllers/concerns/turbo_clone/streams/turbo_streams_tag_builder.rb: -------------------------------------------------------------------------------- 1 | module TurboClone::Streams::TurboStreamsTagBuilder 2 | private 3 | 4 | def turbo_stream 5 | TurboClone::Streams::TagBuilder.new(view_context) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/helpers/turbo_clone/frames_helper.rb: -------------------------------------------------------------------------------- 1 | module TurboClone::FramesHelper 2 | def turbo_frame_tag(resource, &block) 3 | id = resource.respond_to?(:to_key) ? dom_id(resource) : resource 4 | 5 | tag.turbo_frame(id: id, &block) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/app/views/articles/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_with model: article do |f| %> 2 | <%= article.errors.full_messages.to_sentence %> 3 | 4 | <%= f.label :content %> 5 | <%= f.text_field :content %> 6 | 7 | <%= f.submit "Save" %> 8 | <% end %> 9 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220628203340_create_articles.rb: -------------------------------------------------------------------------------- 1 | class CreateArticles < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :articles do |t| 4 | t.text :content 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | gemspec 5 | 6 | gem "sqlite3" 7 | 8 | gem "sprockets-rails" 9 | 10 | gem "puma" 11 | 12 | gem "importmap-rails" 13 | 14 | gem "redis" 15 | -------------------------------------------------------------------------------- /test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) 3 | 4 | require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) 5 | $LOAD_PATH.unshift File.expand_path("../../../lib", __dir__) 6 | -------------------------------------------------------------------------------- /test/dummy/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: redis 3 | url: redis://localhost:6379/1 4 | 5 | test: 6 | adapter: test 7 | 8 | production: 9 | adapter: redis 10 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 11 | channel_prefix: dummy_production 12 | -------------------------------------------------------------------------------- /test/dummy/app/models/article.rb: -------------------------------------------------------------------------------- 1 | class Article < ApplicationRecord 2 | validates :content, presence: true 3 | 4 | after_create_commit { broadcast_prepend_later_to "articles" } 5 | after_update_commit { broadcast_replace_later_to "articles" } 6 | after_destroy_commit { broadcast_remove_to "articles" } 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/views/layouts/turbo_clone/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Turbo clone 5 | <%= csrf_meta_tags %> 6 | <%= csp_meta_tag %> 7 | 8 | <%= stylesheet_link_tag "turbo_clone/application", media: "all" %> 9 | 10 | 11 | 12 | <%= yield %> 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/jobs/turbo_clone/streams/action_broadcast_job.rb: -------------------------------------------------------------------------------- 1 | class TurboClone::Streams::ActionBroadcastJob < ActiveJob::Base 2 | discard_on ActiveJob::DeserializationError 3 | 4 | def perform(stream, action:, target:, **rendering) 5 | TurboClone::StreamsChannel.broadcast_action_to(stream, action: action, target: target, **rendering) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/app/views/articles/index.html.erb: -------------------------------------------------------------------------------- 1 | <%= turbo_stream_from "articles" %> 2 | 3 |

Articles

4 | 5 | <%= link_to "New article", 6 | new_article_path, 7 | data: { turbo_frame: dom_id(Article.new) } %> 8 | 9 | <%= turbo_frame_tag Article.new %> 10 | 11 |
12 | <%= render @articles %> 13 |
14 | -------------------------------------------------------------------------------- /test/dummy/app/views/articles/show.turbo_stream.erb: -------------------------------------------------------------------------------- 1 | <%= turbo_stream.remove @article %> 2 | <%= turbo_stream.update @article, partial: "articles/article", locals: { article: @article } %> 3 | <%= turbo_stream.replace @article, "Something else" %> 4 | <%= turbo_stream.prepend "articles", @article %> 5 | <%= turbo_stream.prepend "articles" do %><%= render @article %><% end %> 6 | -------------------------------------------------------------------------------- /app/channels/turbo_clone/streams_channel.rb: -------------------------------------------------------------------------------- 1 | class TurboClone::StreamsChannel < ActionCable::Channel::Base 2 | extend TurboClone::Streams::StreamName, TurboClone::Streams::Broadcasts 3 | 4 | def subscribed 5 | if verified_stream_name = self.class.verified_stream_name(params[:signed_stream_name]) 6 | stream_from verified_stream_name 7 | else 8 | reject 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | 6 | <%= csrf_meta_tags %> 7 | <%= csp_meta_tag %> 8 | 9 | <%= stylesheet_link_tag "application" %> 10 | <%= javascript_importmap_tags %> 11 | 12 | 13 | 14 | <%= yield %> 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/dummy/config/importmap.rb: -------------------------------------------------------------------------------- 1 | # Pin npm packages by running ./bin/importmap 2 | 3 | pin "application", preload: true 4 | pin "@hotwired/turbo-rails", to: "https://ga.jspm.io/npm:@hotwired/turbo-rails@7.1.1/app/javascript/turbo/index.js" 5 | pin "@hotwired/turbo", to: "https://ga.jspm.io/npm:@hotwired/turbo@7.1.0/dist/turbo.es2017-esm.js" 6 | pin "@rails/actioncable/src", to: "https://ga.jspm.io/npm:@rails/actioncable@7.0.3/src/index.js" 7 | -------------------------------------------------------------------------------- /app/helpers/turbo_clone/streams_helper.rb: -------------------------------------------------------------------------------- 1 | module TurboClone::StreamsHelper 2 | def turbo_stream 3 | TurboClone::Streams::TagBuilder.new(self) 4 | end 5 | 6 | def turbo_stream_from(*streamables, **attributes) 7 | attributes[:channel] = "TurboClone::StreamsChannel" 8 | attributes[:"signed-stream-name"] = TurboClone::StreamsChannel.signed_stream_name(streamables) 9 | 10 | tag.turbo_cable_stream_source(**attributes) 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of 4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported 5 | # notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/permissions_policy.rb: -------------------------------------------------------------------------------- 1 | # Define an application-wide HTTP permissions policy. For further 2 | # information see https://developers.google.com/web/updates/2018/06/feature-policy 3 | # 4 | # Rails.application.config.permissions_policy do |f| 5 | # f.camera :none 6 | # f.gyroscope :none 7 | # f.microphone :none 8 | # f.usb :none 9 | # f.fullscreen :self 10 | # f.payment :self, "https://secure.example.com" 11 | # end 12 | -------------------------------------------------------------------------------- /test/dummy/app/views/articles/_article.html.erb: -------------------------------------------------------------------------------- 1 | <%= turbo_frame_tag article do %> 2 |
3 | Article <%= "##{article.id}" %> 4 | • 5 | <%= article.content %> 6 | • 7 | <%= link_to "Edit", 8 | edit_article_path(article) %> 9 | • 10 | <%= button_to "Delete", 11 | article_path(article), 12 | method: :delete, 13 | form: { style: "display: inline;" } %> 14 |
15 | <% end %> 16 | -------------------------------------------------------------------------------- /lib/turbo_clone.rb: -------------------------------------------------------------------------------- 1 | require "turbo_clone/version" 2 | require "turbo_clone/engine" 3 | 4 | module TurboClone 5 | class << self 6 | attr_writer :signed_stream_verifier_key 7 | 8 | def signed_stream_verifier 9 | @signed_stream_verifier ||= 10 | ActiveSupport::MessageVerifier.new(signed_stream_verifier_key, digest: "SHA256", serializer: JSON) 11 | end 12 | 13 | def signed_stream_verifier_key 14 | @signed_stream_verifier_key or raise ArgumentError, "Turbo requires a signed_stream_verifier_key" 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /turbo_clone.gemspec: -------------------------------------------------------------------------------- 1 | require_relative "lib/turbo_clone/version" 2 | 3 | Gem::Specification.new do |spec| 4 | spec.name = "turbo_clone" 5 | spec.version = TurboClone::VERSION 6 | spec.authors = ["Alexandre Ruban"] 7 | spec.email = ["alexandre@hey.com"] 8 | spec.summary = "Turbo-Rails clone" 9 | spec.license = "MIT" 10 | 11 | spec.files = Dir.chdir(File.expand_path(__dir__)) do 12 | Dir["{app,config,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] 13 | end 14 | 15 | spec.add_dependency "rails", ">= 7.0.0" 16 | end 17 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = "1.0" 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in the app/assets 11 | # folder are already added. 12 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) 13 | -------------------------------------------------------------------------------- /lib/turbo_clone/test_assertions.rb: -------------------------------------------------------------------------------- 1 | module TurboClone::TestAssertions 2 | extend ActiveSupport::Concern 3 | 4 | included do 5 | delegate :dom_id, to: ActionView::RecordIdentifier 6 | end 7 | 8 | def assert_turbo_stream(action:, target: nil, status: :ok) 9 | assert_response status 10 | assert_equal Mime[:turbo_stream], response.media_type 11 | 12 | selector = %(turbo-stream[action="#{action}"]) 13 | selector << %([target="#{target.respond_to?(:to_key) ? dom_id(target) : target}"]) if target 14 | 15 | assert_select selector, count: 1 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails gems 3 | # installed from the root of your application. 4 | 5 | ENGINE_ROOT = File.expand_path("..", __dir__) 6 | ENGINE_PATH = File.expand_path("../lib/turbo_clone/engine", __dir__) 7 | APP_PATH = File.expand_path("../test/dummy/config/application", __dir__) 8 | 9 | # Set up gems listed in the Gemfile. 10 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 11 | require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) 12 | 13 | require "rails/all" 14 | require "rails/engine/commands" 15 | -------------------------------------------------------------------------------- /app/helpers/turbo_clone/action_helper.rb: -------------------------------------------------------------------------------- 1 | module TurboClone::ActionHelper 2 | def turbo_stream_action_tag(action, target:, template:) 3 | template = action == :remove ? "" : "" 4 | 5 | if target = convert_to_turbo_stream_dom_id(target) 6 | %(#{template}).html_safe 7 | else 8 | raise ArgumentError, "target must be supplied" 9 | end 10 | end 11 | 12 | def convert_to_turbo_stream_dom_id(target) 13 | if target.respond_to?(:to_key) 14 | ActionView::RecordIdentifier.dom_id(target) 15 | else 16 | target 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/install/turbo_needs_redis.rb: -------------------------------------------------------------------------------- 1 | if (cable_config_path = Rails.root.join("config/cable.yml")).exist? 2 | say "Enable Redis in bundle" 3 | gemfile_content = File.read(Rails.root.join("Gemfile")) 4 | pattern = /gem ["']redis['"]/ 5 | 6 | if gemfile_content.match?(pattern) 7 | uncomment_lines "Gemfile", pattern 8 | else 9 | append_file "Gemfile", "\n# Use Redis for ActionCable" 10 | gem 'redis', '~> 4.0' 11 | end 12 | 13 | run_bundle 14 | 15 | say "Switch development cable to use Redis" 16 | gsub_file cable_config_path, /development:\n\s+adapter: async/, "development:\n adapter: redis\n url: redis://localhost:6379/1" 17 | else 18 | say "Turbo requires ActionCable to work" 19 | end 20 | -------------------------------------------------------------------------------- /app/channels/turbo_clone/streams/stream_name.rb: -------------------------------------------------------------------------------- 1 | module TurboClone::Streams::StreamName 2 | def verified_stream_name(signed_stream_name) 3 | TurboClone.signed_stream_verifier.verified signed_stream_name 4 | end 5 | 6 | def signed_stream_name(streamables) 7 | TurboClone.signed_stream_verifier.generate stream_name_from(streamables) 8 | end 9 | 10 | def stream_name_from(streamables) 11 | if streamables.is_a?(Array) 12 | streamables.map { |streamable| stream_name_from(streamable) }.join(":") 13 | else 14 | streamables.then do |streamable| 15 | streamable.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(streamable) : streamable 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /test/helpers/frames_helper_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class TurboClone::FramesHelperTest < ActionView::TestCase 4 | test "frame with a model" do 5 | article = Article.new id: 1, content: "not important" 6 | 7 | assert_dom_equal %[], turbo_frame_tag(article) 8 | end 9 | 10 | test "frame with a string" do 11 | assert_dom_equal %[], turbo_frame_tag("articles") 12 | end 13 | 14 | test "frame with a block" do 15 | article = Article.new id: 1, content: "not important" 16 | 17 | assert_dom_equal %[

hey

], 18 | turbo_frame_tag(article) { tag.p("hey") } 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /test/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite. Versions 3.8.0 and up are supported. 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem "sqlite3" 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /app/assets/stylesheets/turbo_clone/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /test/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails/all" 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | require "turbo_clone" 9 | 10 | module Dummy 11 | class Application < Rails::Application 12 | config.load_defaults Rails::VERSION::STRING.to_f 13 | 14 | # For compatibility with applications that use this config 15 | config.action_controller.include_all_helpers = false 16 | 17 | # Configuration for the application, engines, and railties goes here. 18 | # 19 | # These settings can be overridden in specific environments using the files 20 | # in config/environments, which are processed later. 21 | # 22 | # config.time_zone = "Central Time (US & Canada)" 23 | # config.eager_load_paths << Rails.root.join("extras") 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /test/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # "true": "foo" 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /lib/tasks/turbo_clone_tasks.rake: -------------------------------------------------------------------------------- 1 | def run_turbo_install_template(path) 2 | system "bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}" 3 | end 4 | 5 | def redis_installed? 6 | if Gem.win_platform? 7 | system "where redis-server > NUL 2>&1" 8 | else 9 | system "which redis-server > /dev/null" 10 | end 11 | end 12 | 13 | def switch_on_redis_if_available 14 | if redis_installed? 15 | Rake::Task["turbo_clone:install:redis"].invoke 16 | else 17 | puts "Run turbo_clone:install:redis to switch on Redis and use it in development" 18 | end 19 | end 20 | 21 | namespace :turbo_clone do 22 | desc "Install Turbo into the application" 23 | task :install do 24 | run_turbo_install_template "turbo_with_importmap" 25 | switch_on_redis_if_available 26 | end 27 | 28 | namespace :install do 29 | desc "Switch on Redis and use it in development" 30 | task :redis do 31 | run_turbo_install_template "turbo_needs_redis" 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /test/dummy/db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema[7.0].define(version: 2022_06_28_203340) do 14 | create_table "articles", force: :cascade do |t| 15 | t.text "content" 16 | t.datetime "created_at", null: false 17 | t.datetime "updated_at", null: false 18 | end 19 | 20 | end 21 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2022 Alexandre Ruban 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # Configure Rails Environment 2 | ENV["RAILS_ENV"] = "test" 3 | 4 | require_relative "../test/dummy/config/environment" 5 | ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)] 6 | ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__) 7 | require "rails/test_help" 8 | 9 | # Load fixtures from the engine 10 | if ActiveSupport::TestCase.respond_to?(:fixture_path=) 11 | ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__) 12 | ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path 13 | ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files" 14 | ActiveSupport::TestCase.fixtures :all 15 | end 16 | 17 | module ActionViewTestCaseExtensions 18 | def render(*arguments, **options, &block) 19 | ApplicationController.render(*arguments, **options, &block) 20 | end 21 | end 22 | 23 | class ActionDispatch::IntegrationTest 24 | include ActionViewTestCaseExtensions 25 | end 26 | 27 | class ActionCable::Channel::TestCase 28 | include ActionViewTestCaseExtensions 29 | end 30 | -------------------------------------------------------------------------------- /test/dummy/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("..", __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 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 | # puts "\n== Copying sample files ==" 21 | # unless File.exist?("config/database.yml") 22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 23 | # end 24 | 25 | puts "\n== Preparing database ==" 26 | system! "bin/rails db:prepare" 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! "bin/rails log:clear tmp:clear" 30 | 31 | puts "\n== Restarting application server ==" 32 | system! "bin/rails restart" 33 | end 34 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy. 4 | # See the Securing Rails Applications Guide for more information: 5 | # https://guides.rubyonrails.org/security.html#content-security-policy-header 6 | 7 | # Rails.application.configure do 8 | # config.content_security_policy do |policy| 9 | # policy.default_src :self, :https 10 | # policy.font_src :self, :https, :data 11 | # policy.img_src :self, :https, :data 12 | # policy.object_src :none 13 | # policy.script_src :self, :https 14 | # policy.style_src :self, :https 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | # 19 | # # Generate session nonces for permitted importmap and inline scripts 20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } 21 | # config.content_security_policy_nonce_directives = %w(script-src) 22 | # 23 | # # Report violations without enforcing the policy. 24 | # # config.content_security_policy_report_only = true 25 | # end 26 | -------------------------------------------------------------------------------- /test/helpers/streams_helper_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class TurboClone::StreamsHelperTest < ActionView::TestCase 4 | test "with a string streamable" do 5 | signed_stream_name = TurboClone::StreamsChannel.signed_stream_name("articles") 6 | 7 | assert_dom_equal \ 8 | %(), 9 | turbo_stream_from("articles") 10 | end 11 | 12 | test "with a model streamable" do 13 | article = Article.new(id: 1) 14 | signed_stream_name = TurboClone::StreamsChannel.signed_stream_name(article) 15 | 16 | assert_dom_equal \ 17 | %(), 18 | turbo_stream_from(article) 19 | end 20 | 21 | test "with multiple streamables" do 22 | article = Article.new(id: 1) 23 | signed_stream_name = TurboClone::StreamsChannel.signed_stream_name(["articles", article]) 24 | 25 | assert_dom_equal \ 26 | %(), 27 | turbo_stream_from("articles", article) 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /test/dummy/config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket-<%= Rails.env %> 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket-<%= Rails.env %> 23 | 24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name-<%= Rails.env %> 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rebuilding turbo-rails tutorial 2 | 3 | This is the source code for [the rebuilding turbo-rails tutorial][tutorial]. Each commit corresponds to one video of the course, so it's easy for you to follow along. 4 | 5 | In this tutorial, we will: 6 | 7 | - Learn to create Rails engines from scratch thanks to the `rails plugin new` command 8 | - Rebuild together all the backend [turbo-rails][turbo_rails] features 9 | - Learn how to test our engine both manually and with automated tests thanks to the `test/dummy` Rails application 10 | - Learn how to create installation rake tasks thanks to Rails templates 11 | - Test our finalized engine in a real Ruby on Rails application 12 | 13 | By the end of the tutorial, you will understand in-depth how [turbo-rails][turbo_rails] works under the hood and even be able to contribute to it yourself! You will also be able to create your own extensions to the Ruby on Rails framework. 14 | 15 | All the knowledge we will learn together applies to other Rails engines such as `ActionText` or `ActiveStorage`, for example. 16 | 17 | It will also teach you how to read the source code of a gem to understand it when the documentation is scarce. 18 | 19 | Let's [get started][tutorial]! 20 | 21 | [tutorial]: https://hotrails.podia.com/rebuilding-turbo-rails 22 | [turbo_rails]: https://github.com/hotwired/turbo-rails/ 23 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/articles_controller.rb: -------------------------------------------------------------------------------- 1 | class ArticlesController < ApplicationController 2 | before_action :set_article, only: [:show, :edit, :update, :destroy] 3 | 4 | def index 5 | @articles = Article.all 6 | end 7 | 8 | def show 9 | end 10 | 11 | def new 12 | @article = Article.new 13 | end 14 | 15 | def create 16 | @article = Article.new(article_params) 17 | 18 | if @article.save 19 | respond_to do |format| 20 | format.html { redirect_to articles_path } 21 | format.turbo_stream 22 | end 23 | else 24 | render :new 25 | end 26 | end 27 | 28 | def edit 29 | end 30 | 31 | def update 32 | if @article.update(article_params) 33 | respond_to do |format| 34 | format.html { redirect_to articles_path } 35 | format.turbo_stream 36 | end 37 | else 38 | render :edit 39 | end 40 | end 41 | 42 | def destroy 43 | @article.destroy 44 | 45 | respond_to do |format| 46 | format.html { redirect_to articles_path } 47 | format.turbo_stream { render turbo_stream: turbo_stream.remove(@article) } 48 | end 49 | end 50 | 51 | private 52 | 53 | def article_params 54 | params.require(:article).permit(:content) 55 | end 56 | 57 | def set_article 58 | @article = Article.find(params[:id]) 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /app/models/turbo_clone/streams/tag_builder.rb: -------------------------------------------------------------------------------- 1 | class TurboClone::Streams::TagBuilder 2 | include TurboClone::ActionHelper 3 | 4 | def initialize(view_context) 5 | @view_context = view_context 6 | @view_context.formats |= [:html] 7 | end 8 | 9 | def replace(target, content = nil, **rendering, &block) 10 | action :replace, target, content, **rendering, &block 11 | end 12 | 13 | def update(target, content = nil, **rendering, &block) 14 | action :update, target, content, **rendering, &block 15 | end 16 | 17 | def prepend(target, content = nil, **rendering, &block) 18 | action :prepend, target, content, **rendering, &block 19 | end 20 | 21 | def remove(target) 22 | action :remove, target 23 | end 24 | 25 | private 26 | 27 | def action(name, target, content = nil, **rendering, &block) 28 | template = render_template(target, content, **rendering, &block) unless name == :remove 29 | 30 | turbo_stream_action_tag(name, target: target, template: template) 31 | end 32 | 33 | def render_template(target, content = nil, **rendering, &block) 34 | if content 35 | content.respond_to?(:to_partial_path) ? @view_context.render(partial: content, formats: :html) : content 36 | elsif block_given? 37 | @view_context.capture(&block) 38 | elsif rendering.any? 39 | @view_context.render(**rendering, formats: :html) 40 | else 41 | @view_context.render(partial: target, formats: :html) 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /test/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /test/dummy/config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 9 | threads min_threads_count, max_threads_count 10 | 11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 12 | # terminating a worker in development environments. 13 | # 14 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 15 | 16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 17 | # 18 | port ENV.fetch("PORT") { 3000 } 19 | 20 | # Specifies the `environment` that Puma will run in. 21 | # 22 | environment ENV.fetch("RAILS_ENV") { "development" } 23 | 24 | # Specifies the `pidfile` that Puma will use. 25 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 26 | 27 | # Specifies the number of `workers` to boot in clustered mode. 28 | # Workers are forked web server processes. If using threads and workers together 29 | # the concurrency of the application would be max `threads` * `workers`. 30 | # Workers do not work on JRuby or Windows (both of which do not support 31 | # processes). 32 | # 33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 34 | 35 | # Use the `preload_app!` method when specifying a `workers` number. 36 | # This directive tells Puma to first boot the application and load code 37 | # before forking the application. This takes advantage of Copy On Write 38 | # process behavior so workers use less memory. 39 | # 40 | # preload_app! 41 | 42 | # Allow puma to be restarted by `bin/rails restart` command. 43 | plugin :tmp_restart 44 | -------------------------------------------------------------------------------- /app/channels/turbo_clone/streams/broadcasts.rb: -------------------------------------------------------------------------------- 1 | module TurboClone::Streams::Broadcasts 2 | include TurboClone::ActionHelper 3 | 4 | def broadcast_append_to(*streamables, **options) 5 | broadcast_action_to(*streamables, action: :append, **options) 6 | end 7 | 8 | def broadcast_prepend_to(*streamables, **options) 9 | broadcast_action_to(*streamables, action: :prepend, **options) 10 | end 11 | 12 | def broadcast_replace_to(*streamables, **options) 13 | broadcast_action_to(*streamables, action: :replace, **options) 14 | end 15 | 16 | def broadcast_remove_to(*streamables, **options) 17 | broadcast_action_to(*streamables, action: :remove, **options) 18 | end 19 | 20 | def broadcast_action_to(*streamables, action:, target: nil, **rendering) 21 | broadcast_stream_to *streamables, content: turbo_stream_action_tag( 22 | action, target: target, template: (rendering.any? ? render_format(:html, **rendering) : nil) 23 | ) 24 | end 25 | 26 | def broadcast_append_later_to(*streamables, **options) 27 | broadcast_action_later_to(*streamables, action: :append, **options) 28 | end 29 | 30 | def broadcast_prepend_later_to(*streamables, **options) 31 | broadcast_action_later_to(*streamables, action: :prepend, **options) 32 | end 33 | 34 | def broadcast_replace_later_to(*streamables, **options) 35 | broadcast_action_later_to(*streamables, action: :replace, **options) 36 | end 37 | 38 | def broadcast_action_later_to(*streamables, action:, target: nil, **rendering) 39 | TurboClone::Streams::ActionBroadcastJob.perform_later( 40 | stream_name_from(streamables), action: action, target: target, **rendering 41 | ) 42 | end 43 | 44 | def broadcast_stream_to(*streamables, content:) 45 | ActionCable.server.broadcast stream_name_from(streamables), content 46 | end 47 | 48 | private 49 | 50 | def render_format(format, **rendering) 51 | ApplicationController.render(formats: [format], **rendering) 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /lib/turbo_clone/engine.rb: -------------------------------------------------------------------------------- 1 | require "turbo_clone/test_assertions" 2 | 3 | module TurboClone 4 | class Engine < ::Rails::Engine 5 | isolate_namespace TurboClone 6 | 7 | config.turbo = ActiveSupport::OrderedOptions.new 8 | 9 | initializer "turbo.signed_stream_verifier_key" do 10 | TurboClone.signed_stream_verifier_key = config.turbo.signed_stream_verifier_key || 11 | Rails.application.key_generator.generate_key("turbo/signed_stream_verifier_key") 12 | end 13 | 14 | initializer "turbo.media_type" do 15 | Mime::Type.register "text/vnd.turbo-stream.html", :turbo_stream 16 | end 17 | 18 | initializer "turbo.helper" do 19 | ActiveSupport.on_load :action_controller_base do 20 | include TurboClone::Streams::TurboStreamsTagBuilder 21 | helper TurboClone::Engine.helpers 22 | end 23 | end 24 | 25 | initializer "turbo.broadcastable" do 26 | ActiveSupport.on_load :active_record do 27 | include TurboClone::Broadcastable 28 | end 29 | end 30 | 31 | initializer "turbo.renderer" do 32 | ActiveSupport.on_load :action_controller do 33 | ActionController::Renderers.add :turbo_stream do |turbo_streams_html, options| 34 | turbo_streams_html 35 | end 36 | end 37 | end 38 | 39 | initializer "turbo.test_assertions" do 40 | ActiveSupport.on_load :active_support_test_case do 41 | include TurboClone::TestAssertions 42 | end 43 | end 44 | 45 | initializer "turbo.integration_test_request_encoding" do 46 | ActiveSupport.on_load :action_dispatch_integration_test do 47 | class ActionDispatch::RequestEncoder 48 | class TurboStreamEncoder < IdentityEncoder 49 | header = [Mime[:turbo_stream], Mime[:html]].join(",") 50 | define_method(:accept_header) { header } 51 | end 52 | 53 | @encoders[:turbo_stream] = TurboStreamEncoder.new 54 | end 55 | end 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /test/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /test/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /test/controllers/streams_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class TurboClone::StreamsControllerTest < ActionDispatch::IntegrationTest 4 | test "create with respond to" do 5 | post articles_path, params: { article: { content: "something" } } 6 | assert_redirected_to articles_path 7 | 8 | post articles_path, params: { article: { content: "something" } }, as: :turbo_stream 9 | assert_turbo_stream action: "prepend", target: "articles" 10 | end 11 | 12 | test "update with respond to" do 13 | article = Article.create! content: "something" 14 | 15 | patch article_path(article), params: { article: { content: "something else" } } 16 | assert_redirected_to articles_path 17 | 18 | patch article_path(article), params: { article: { content: "something different" } }, as: :turbo_stream 19 | assert_turbo_stream action: "replace", target: article 20 | end 21 | 22 | test "destroy with respond to" do 23 | article = Article.create! content: "something" 24 | 25 | delete article_path(article) 26 | assert_redirected_to articles_path 27 | 28 | article = Article.create! content: "something else" 29 | 30 | delete article_path(article), as: :turbo_stream 31 | assert_turbo_stream action: "remove", target: article 32 | end 33 | 34 | test "show all turbo actions" do 35 | article = Article.create! content: "something" 36 | get article_path(article), as: :turbo_stream 37 | 38 | assert_dom_equal <<~HTML, @response.body 39 | 40 | 41 | 42 | 43 | 44 | HTML 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /app/models/concerns/turbo_clone/broadcastable.rb: -------------------------------------------------------------------------------- 1 | module TurboClone::Broadcastable 2 | extend ActiveSupport::Concern 3 | 4 | class_methods do 5 | def broadcast_target_default 6 | model_name.plural 7 | end 8 | end 9 | 10 | def broadcast_append_to(*streamables, target: broadcast_target_default, **rendering) 11 | TurboClone::StreamsChannel.broadcast_append_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering)) 12 | end 13 | 14 | def broadcast_prepend_to(*streamables, target: broadcast_target_default, **rendering) 15 | TurboClone::StreamsChannel.broadcast_prepend_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering)) 16 | end 17 | 18 | def broadcast_replace_to(*streamables, target: self, **rendering) 19 | TurboClone::StreamsChannel.broadcast_replace_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering)) 20 | end 21 | 22 | def broadcast_remove_to(*streamables, target: self) 23 | TurboClone::StreamsChannel.broadcast_remove_to(*streamables, target: target) 24 | end 25 | 26 | def broadcast_append_later_to(*streamables, target: broadcast_target_default, **rendering) 27 | TurboClone::StreamsChannel.broadcast_append_later_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering)) 28 | end 29 | 30 | def broadcast_prepend_later_to(*streamables, target: broadcast_target_default, **rendering) 31 | TurboClone::StreamsChannel.broadcast_prepend_later_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering)) 32 | end 33 | 34 | def broadcast_replace_later_to(*streamables, target: self, **rendering) 35 | TurboClone::StreamsChannel.broadcast_replace_later_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering)) 36 | end 37 | 38 | private 39 | 40 | def broadcast_rendering_with_defaults(rendering) 41 | rendering.tap do |r| 42 | r[:locals] = (r[:locals] || {}).reverse_merge!(model_name.element.to_sym => self) 43 | r[:partial] ||= to_partial_path 44 | end 45 | end 46 | 47 | def broadcast_target_default 48 | self.class.broadcast_target_default 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /test/channels/broadcastable_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class TurboClone::BroadcastableTest < ActionCable::Channel::TestCase 4 | include TurboClone::ActionHelper 5 | include ActiveJob::TestHelper 6 | 7 | test "#broadcast_append_to" do 8 | article = Article.create! content: "Something" 9 | 10 | assert_broadcast_on "stream", turbo_stream_action_tag(:append, target: "articles", template: render(article)) do 11 | article.broadcast_append_to "stream" 12 | end 13 | end 14 | 15 | test "#broadcast_append_later_to" do 16 | article = Article.create! content: "Something" 17 | 18 | assert_broadcast_on "stream", turbo_stream_action_tag(:append, target: "articles", template: render(article)) do 19 | perform_enqueued_jobs do 20 | article.broadcast_append_later_to "stream" 21 | end 22 | end 23 | end 24 | 25 | test "#broadcast_prepend_to" do 26 | article = Article.create! content: "Something" 27 | 28 | assert_broadcast_on "stream", turbo_stream_action_tag(:prepend, target: "board_articles", template: render(article)) do 29 | article.broadcast_prepend_to "stream", target: "board_articles" 30 | end 31 | end 32 | 33 | test "#broadcast_prepend_later_to" do 34 | article = Article.create! content: "Something" 35 | 36 | assert_broadcast_on "stream", turbo_stream_action_tag(:prepend, target: "board_articles", template: render(article)) do 37 | perform_enqueued_jobs do 38 | article.broadcast_prepend_later_to "stream", target: "board_articles" 39 | end 40 | end 41 | end 42 | 43 | test "#broadcast_replace_to" do 44 | article = Article.create! content: "Something" 45 | 46 | assert_broadcast_on "stream", turbo_stream_action_tag(:replace, target: article, template: render(article)) do 47 | article.broadcast_replace_to "stream" 48 | end 49 | end 50 | 51 | test "#broadcast_replace_later_to" do 52 | article = Article.create! content: "Something" 53 | 54 | assert_broadcast_on "stream", turbo_stream_action_tag(:replace, target: article, template: render(article)) do 55 | perform_enqueued_jobs do 56 | article.broadcast_replace_later_to "stream" 57 | end 58 | end 59 | end 60 | 61 | test "#broadcast_remove_to" do 62 | article = Article.create! content: "Something" 63 | 64 | assert_broadcast_on "stream", turbo_stream_action_tag(:remove, target: article, template: nil) do 65 | article.broadcast_remove_to "stream" 66 | end 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /test/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | # Turn false under Spring and add config.action_view.cache_template_loading = true. 12 | config.cache_classes = true 13 | 14 | # Eager loading loads your whole application. When running a single test locally, 15 | # this probably isn't necessary. It's a good idea to do in a continuous integration 16 | # system, or in some way before deploying your code. 17 | config.eager_load = ENV["CI"].present? 18 | 19 | # Configure public file server for tests with Cache-Control for performance. 20 | config.public_file_server.enabled = true 21 | config.public_file_server.headers = { 22 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 23 | } 24 | 25 | # Show full error reports and disable caching. 26 | config.consider_all_requests_local = true 27 | config.action_controller.perform_caching = false 28 | config.cache_store = :null_store 29 | 30 | # Raise exceptions instead of rendering exception templates. 31 | config.action_dispatch.show_exceptions = false 32 | 33 | # Disable request forgery protection in test environment. 34 | config.action_controller.allow_forgery_protection = false 35 | 36 | # Store uploaded files on the local file system in a temporary directory. 37 | config.active_storage.service = :test 38 | 39 | config.action_mailer.perform_caching = false 40 | 41 | # Tell Action Mailer not to deliver emails to the real world. 42 | # The :test delivery method accumulates sent emails in the 43 | # ActionMailer::Base.deliveries array. 44 | config.action_mailer.delivery_method = :test 45 | 46 | # Print deprecation notices to the stderr. 47 | config.active_support.deprecation = :stderr 48 | 49 | # Raise exceptions for disallowed deprecations. 50 | config.active_support.disallowed_deprecation = :raise 51 | 52 | # Tell Active Support which deprecation messages to disallow. 53 | config.active_support.disallowed_deprecation_warnings = [] 54 | 55 | # Raises error for missing translations. 56 | # config.i18n.raise_on_missing_translations = true 57 | 58 | # Annotate rendered view with file names. 59 | # config.action_view.annotate_rendered_view_with_filenames = true 60 | end 61 | -------------------------------------------------------------------------------- /test/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 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 any time 7 | # it changes. 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 server timing 18 | config.server_timing = true 19 | 20 | # Enable/disable caching. By default caching is disabled. 21 | # Run rails dev:cache to toggle caching. 22 | if Rails.root.join("tmp/caching-dev.txt").exist? 23 | config.action_controller.perform_caching = true 24 | config.action_controller.enable_fragment_cache_logging = true 25 | 26 | config.cache_store = :memory_store 27 | config.public_file_server.headers = { 28 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 29 | } 30 | else 31 | config.action_controller.perform_caching = false 32 | 33 | config.cache_store = :null_store 34 | end 35 | 36 | # Store uploaded files on the local file system (see config/storage.yml for options). 37 | config.active_storage.service = :local 38 | 39 | # Don't care if the mailer can't send. 40 | config.action_mailer.raise_delivery_errors = false 41 | 42 | config.action_mailer.perform_caching = false 43 | 44 | # Print deprecation notices to the Rails logger. 45 | config.active_support.deprecation = :log 46 | 47 | # Raise exceptions for disallowed deprecations. 48 | config.active_support.disallowed_deprecation = :raise 49 | 50 | # Tell Active Support which deprecation messages to disallow. 51 | config.active_support.disallowed_deprecation_warnings = [] 52 | 53 | # Raise an error on page load if there are pending migrations. 54 | config.active_record.migration_error = :page_load 55 | 56 | # Highlight code that triggered database queries in logs. 57 | config.active_record.verbose_query_logs = true 58 | 59 | # Suppress logger output for asset requests. 60 | config.assets.quiet = true 61 | 62 | # Raises error for missing translations. 63 | # config.i18n.raise_on_missing_translations = true 64 | 65 | # Annotate rendered view with file names. 66 | # config.action_view.annotate_rendered_view_with_filenames = true 67 | 68 | # Uncomment if you wish to allow Action Cable access from any origin. 69 | # config.action_cable.disable_request_forgery_protection = true 70 | end 71 | -------------------------------------------------------------------------------- /test/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 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 CSS using a preprocessor. 28 | # config.assets.css_compressor = :sass 29 | 30 | # Do not fallback to assets pipeline if a precompiled asset is missed. 31 | config.assets.compile = false 32 | 33 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 34 | # config.asset_host = "http://assets.example.com" 35 | 36 | # Specifies the header that your server uses for sending files. 37 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache 38 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX 39 | 40 | # Store uploaded files on the local file system (see config/storage.yml for options). 41 | config.active_storage.service = :local 42 | 43 | # Mount Action Cable outside main process or domain. 44 | # config.action_cable.mount_path = nil 45 | # config.action_cable.url = "wss://example.com/cable" 46 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] 47 | 48 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 49 | # config.force_ssl = true 50 | 51 | # Include generic and useful information about system operation, but avoid logging too much 52 | # information to avoid inadvertent exposure of personally identifiable information (PII). 53 | config.log_level = :info 54 | 55 | # Prepend all log lines with the following tags. 56 | config.log_tags = [ :request_id ] 57 | 58 | # Use a different cache store in production. 59 | # config.cache_store = :mem_cache_store 60 | 61 | # Use a real queuing backend for Active Job (and separate queues per environment). 62 | # config.active_job.queue_adapter = :resque 63 | # config.active_job.queue_name_prefix = "dummy_production" 64 | 65 | config.action_mailer.perform_caching = false 66 | 67 | # Ignore bad email addresses and do not raise email delivery errors. 68 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 69 | # config.action_mailer.raise_delivery_errors = false 70 | 71 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 72 | # the I18n.default_locale when a translation cannot be found). 73 | config.i18n.fallbacks = true 74 | 75 | # Don't log any deprecations. 76 | config.active_support.report_deprecations = false 77 | 78 | # Use default logging formatter so that PID and timestamp are not suppressed. 79 | config.log_formatter = ::Logger::Formatter.new 80 | 81 | # Use a different logger for distributed setups. 82 | # require "syslog/logger" 83 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") 84 | 85 | if ENV["RAILS_LOG_TO_STDOUT"].present? 86 | logger = ActiveSupport::Logger.new(STDOUT) 87 | logger.formatter = config.log_formatter 88 | config.logger = ActiveSupport::TaggedLogging.new(logger) 89 | end 90 | 91 | # Do not dump schema after migrations. 92 | config.active_record.dump_schema_after_migration = false 93 | end 94 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | turbo_clone (0.1.0) 5 | rails (>= 7.0.0) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | actioncable (7.0.3) 11 | actionpack (= 7.0.3) 12 | activesupport (= 7.0.3) 13 | nio4r (~> 2.0) 14 | websocket-driver (>= 0.6.1) 15 | actionmailbox (7.0.3) 16 | actionpack (= 7.0.3) 17 | activejob (= 7.0.3) 18 | activerecord (= 7.0.3) 19 | activestorage (= 7.0.3) 20 | activesupport (= 7.0.3) 21 | mail (>= 2.7.1) 22 | net-imap 23 | net-pop 24 | net-smtp 25 | actionmailer (7.0.3) 26 | actionpack (= 7.0.3) 27 | actionview (= 7.0.3) 28 | activejob (= 7.0.3) 29 | activesupport (= 7.0.3) 30 | mail (~> 2.5, >= 2.5.4) 31 | net-imap 32 | net-pop 33 | net-smtp 34 | rails-dom-testing (~> 2.0) 35 | actionpack (7.0.3) 36 | actionview (= 7.0.3) 37 | activesupport (= 7.0.3) 38 | rack (~> 2.0, >= 2.2.0) 39 | rack-test (>= 0.6.3) 40 | rails-dom-testing (~> 2.0) 41 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 42 | actiontext (7.0.3) 43 | actionpack (= 7.0.3) 44 | activerecord (= 7.0.3) 45 | activestorage (= 7.0.3) 46 | activesupport (= 7.0.3) 47 | globalid (>= 0.6.0) 48 | nokogiri (>= 1.8.5) 49 | actionview (7.0.3) 50 | activesupport (= 7.0.3) 51 | builder (~> 3.1) 52 | erubi (~> 1.4) 53 | rails-dom-testing (~> 2.0) 54 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 55 | activejob (7.0.3) 56 | activesupport (= 7.0.3) 57 | globalid (>= 0.3.6) 58 | activemodel (7.0.3) 59 | activesupport (= 7.0.3) 60 | activerecord (7.0.3) 61 | activemodel (= 7.0.3) 62 | activesupport (= 7.0.3) 63 | activestorage (7.0.3) 64 | actionpack (= 7.0.3) 65 | activejob (= 7.0.3) 66 | activerecord (= 7.0.3) 67 | activesupport (= 7.0.3) 68 | marcel (~> 1.0) 69 | mini_mime (>= 1.1.0) 70 | activesupport (7.0.3) 71 | concurrent-ruby (~> 1.0, >= 1.0.2) 72 | i18n (>= 1.6, < 2) 73 | minitest (>= 5.1) 74 | tzinfo (~> 2.0) 75 | builder (3.2.4) 76 | concurrent-ruby (1.1.10) 77 | crass (1.0.6) 78 | digest (3.1.0) 79 | erubi (1.10.0) 80 | globalid (1.0.0) 81 | activesupport (>= 5.0) 82 | i18n (1.10.0) 83 | concurrent-ruby (~> 1.0) 84 | importmap-rails (1.1.2) 85 | actionpack (>= 6.0.0) 86 | railties (>= 6.0.0) 87 | loofah (2.18.0) 88 | crass (~> 1.0.2) 89 | nokogiri (>= 1.5.9) 90 | mail (2.7.1) 91 | mini_mime (>= 0.1.1) 92 | marcel (1.0.2) 93 | method_source (1.0.0) 94 | mini_mime (1.1.2) 95 | minitest (5.16.1) 96 | net-imap (0.2.3) 97 | digest 98 | net-protocol 99 | strscan 100 | net-pop (0.1.1) 101 | digest 102 | net-protocol 103 | timeout 104 | net-protocol (0.1.3) 105 | timeout 106 | net-smtp (0.3.1) 107 | digest 108 | net-protocol 109 | timeout 110 | nio4r (2.5.8) 111 | nokogiri (1.13.6-arm64-darwin) 112 | racc (~> 1.4) 113 | puma (5.6.4) 114 | nio4r (~> 2.0) 115 | racc (1.6.0) 116 | rack (2.2.3.1) 117 | rack-test (2.0.2) 118 | rack (>= 1.3) 119 | rails (7.0.3) 120 | actioncable (= 7.0.3) 121 | actionmailbox (= 7.0.3) 122 | actionmailer (= 7.0.3) 123 | actionpack (= 7.0.3) 124 | actiontext (= 7.0.3) 125 | actionview (= 7.0.3) 126 | activejob (= 7.0.3) 127 | activemodel (= 7.0.3) 128 | activerecord (= 7.0.3) 129 | activestorage (= 7.0.3) 130 | activesupport (= 7.0.3) 131 | bundler (>= 1.15.0) 132 | railties (= 7.0.3) 133 | rails-dom-testing (2.0.3) 134 | activesupport (>= 4.2.0) 135 | nokogiri (>= 1.6) 136 | rails-html-sanitizer (1.4.3) 137 | loofah (~> 2.3) 138 | railties (7.0.3) 139 | actionpack (= 7.0.3) 140 | activesupport (= 7.0.3) 141 | method_source 142 | rake (>= 12.2) 143 | thor (~> 1.0) 144 | zeitwerk (~> 2.5) 145 | rake (13.0.6) 146 | redis (4.7.0) 147 | sprockets (4.1.1) 148 | concurrent-ruby (~> 1.0) 149 | rack (> 1, < 3) 150 | sprockets-rails (3.4.2) 151 | actionpack (>= 5.2) 152 | activesupport (>= 5.2) 153 | sprockets (>= 3.0.0) 154 | sqlite3 (1.4.4) 155 | strscan (3.0.3) 156 | thor (1.2.1) 157 | timeout (0.3.0) 158 | tzinfo (2.0.4) 159 | concurrent-ruby (~> 1.0) 160 | websocket-driver (0.7.5) 161 | websocket-extensions (>= 0.1.0) 162 | websocket-extensions (0.1.5) 163 | zeitwerk (2.6.0) 164 | 165 | PLATFORMS 166 | arm64-darwin-21 167 | 168 | DEPENDENCIES 169 | importmap-rails 170 | puma 171 | redis 172 | sprockets-rails 173 | sqlite3 174 | turbo_clone! 175 | 176 | BUNDLED WITH 177 | 2.3.13 178 | --------------------------------------------------------------------------------