From 8c6d296021d4d98e47aa3bdf24e3db65b8447fb1 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sun, 3 Dec 2023 23:27:10 +0100 Subject: [PATCH] Enable turbo (without Drive) --- Gemfile | 3 +++ Gemfile.lock | 10 ++++++++++ app/assets/config/manifest.js | 2 ++ app/javascript/application.js | 3 +++ app/views/layouts/application.html.erb | 1 + bin/importmap | 4 ++++ config/importmap.rb | 4 ++++ vendor/javascript/.keep | 0 8 files changed, 27 insertions(+) create mode 100644 app/javascript/application.js create mode 100755 bin/importmap create mode 100644 config/importmap.rb create mode 100644 vendor/javascript/.keep diff --git a/Gemfile b/Gemfile index 28b5f23..4ef4372 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,9 @@ gem "devise" gem 'awesome_nested_set' +gem 'importmap-rails' +gem 'turbo-rails' + group :development, :test do gem "byebug" end diff --git a/Gemfile.lock b/Gemfile.lock index 3b89d73..0b07a02 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -98,6 +98,10 @@ GEM activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + importmap-rails (1.2.3) + actionpack (>= 6.0.0) + activesupport (>= 6.0.0) + railties (>= 6.0.0) loofah (2.21.4) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -189,6 +193,10 @@ GEM thor (1.3.0) tilt (2.3.0) timeout (0.4.0) + turbo-rails (1.5.0) + actionpack (>= 6.0.0) + activejob (>= 6.0.0) + railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) warden (1.2.9) @@ -214,12 +222,14 @@ DEPENDENCIES byebug capybara devise + importmap-rails mysql2 (~> 0.5) puma (~> 5.0) rails (~> 7.0.4, >= 7.0.4.2) sassc-rails selenium-webdriver sprockets-rails + turbo-rails tzinfo-data web-console diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index 5918193..ddd546a 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -1,2 +1,4 @@ //= link_tree ../images //= link_directory ../stylesheets .css +//= link_tree ../../javascript .js +//= link_tree ../../../vendor/javascript .js diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 0000000..0d1717e --- /dev/null +++ b/app/javascript/application.js @@ -0,0 +1,3 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails +import "@hotwired/turbo-rails" +Turbo.session.drive = false diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 14fde5e..d8b9f58 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,6 +7,7 @@ <%= csp_meta_tag %> <%= stylesheet_link_tag "application" %> + <%= javascript_importmap_tags %> diff --git a/bin/importmap b/bin/importmap new file mode 100755 index 0000000..36502ab --- /dev/null +++ b/bin/importmap @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require_relative "../config/application" +require "importmap/commands" diff --git a/config/importmap.rb b/config/importmap.rb new file mode 100644 index 0000000..26c5560 --- /dev/null +++ b/config/importmap.rb @@ -0,0 +1,4 @@ +# Pin npm packages by running ./bin/importmap + +pin "application", preload: true +pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true diff --git a/vendor/javascript/.keep b/vendor/javascript/.keep new file mode 100644 index 0000000..e69de29