Skip to content

Commit ac79965

Browse files
committed
Replace rails ujs with turbo
1 parent 3d44d7b commit ac79965

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+94
-117
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ gem "sprockets-rails"
1717
gem "jsbundling-rails"
1818
gem "cssbundling-rails"
1919
gem "turbo-rails"
20+
gem "stimulus-rails"
2021

2122
gem 'sassc-rails'
2223

Rakefile

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ namespace :test do
3737
end
3838

3939
namespace :app do
40-
task :environment do
41-
ENV['RAILS_ROOT'] = TEST_APP_ROOT
42-
ENV['RAILS_ENV'] = 'test'
4340

44-
require(File.join(TEST_APP_ROOT, 'config', 'environment'))
45-
end
41+
desc "Initializes the test application with a couple of classes"
42+
task init: [:seed, :customize]
43+
44+
desc "Customize some of the functionality provided by dry_crud"
45+
task customize: ['test:app:add_pagination',
46+
'test:app:use_bootstrap',
47+
'test:app:build_assets'
48+
]
4649

4750
desc "Create a rails test application"
4851
task :create do
@@ -53,10 +56,6 @@ namespace :test do
5356
File.read(File.join(File.dirname(__FILE__),
5457
'test', 'templates', 'Gemfile.append')))
5558
sh "cd #{TEST_APP_ROOT}; bundle install --local" # update Gemfile.lock
56-
#sh "cd #{TEST_APP_ROOT}; bundle binstubs bundler"
57-
#sh "cd #{TEST_APP_ROOT}; rails javascript:install:esbuild"
58-
#sh "cd #{TEST_APP_ROOT}; yarn add esbuild from \".\""
59-
#sh "cd #{TEST_APP_ROOT}; gem install foreman from \".\""
6059

6160
sh "cd #{TEST_APP_ROOT}; rails g rspec:install"
6261
FileUtils.rm_f(File.join(TEST_APP_ROOT,
@@ -87,6 +86,13 @@ namespace :test do
8786
destination_root: TEST_APP_ROOT).invoke_all
8887
end
8988

89+
task :environment do
90+
ENV['RAILS_ROOT'] = TEST_APP_ROOT
91+
ENV['RAILS_ENV'] = 'test'
92+
93+
require(File.join(TEST_APP_ROOT, 'config', 'environment'))
94+
end
95+
9096
desc "Populates the test application with some models and controllers"
9197
task populate: [:generate_crud] do
9298
# copy test app templates
@@ -117,15 +123,6 @@ namespace :test do
117123
end
118124
end
119125

120-
desc "Initializes the test application with a couple of classes"
121-
task init: [:seed, :customize]
122-
123-
desc "Customize some of the functionality provided by dry_crud"
124-
task customize: ['test:app:add_pagination',
125-
'test:app:add_ujs',
126-
'test:app:use_bootstrap'
127-
]
128-
129126
desc "Adds pagination to the test app"
130127
task :add_pagination do
131128
list_ctrl = File.join(TEST_APP_ROOT,
@@ -145,17 +142,6 @@ namespace :test do
145142
"= paginate entries\n\n= render 'list'")
146143
end
147144

148-
desc "Adds Rails UJS to the test app"
149-
task :add_ujs do
150-
sh "cd #{TEST_APP_ROOT}; yarn add @rails/ujs"
151-
app_js = File.join(TEST_APP_ROOT, 'app', 'javascript', 'application.js')
152-
if File.exist?(app_js) && File.read(app_js) !~ /ujs/
153-
file_replace(app_js,
154-
/\n\z/,
155-
"\nimport Rails from '@rails/ujs'\nRails.start()\n")
156-
end
157-
end
158-
159145
desc "Use Boostrap Icons in the test app"
160146
task :use_bootstrap do
161147
sh "cd #{TEST_APP_ROOT}; yarn add bootstrap-icons"
@@ -178,6 +164,10 @@ namespace :test do
178164
'app', 'assets', 'stylesheets', 'sample.scss'))
179165
end
180166

167+
desc "Build javascript and css in the test app"
168+
task :build_assets do
169+
sh "cd #{TEST_APP_ROOT}; rails javascript:build css:build"
170+
end
181171
end
182172
end
183173

app/assets/stylesheets/sample.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ a.icon img {
222222
.icon-plus {
223223
background-image: image-url("actions/add.png");
224224
}
225-
.icon-remove {
225+
.icon-trash {
226226
background-image: image-url("actions/delete.png");
227227
}
228228
.icon-pencil {

app/helpers/actions_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def edit_action_link(path = nil)
3838
# Uses the current +entry+ if no path is given.
3939
def destroy_action_link(path = nil)
4040
path ||= path_args(entry)
41-
action_link(ti('link.delete'), 'remove', path,
42-
data: { confirm: ti(:confirm_delete),
43-
method: :delete })
41+
action_link(ti('link.delete'), 'trash', path,
42+
data: { 'turbo-confirm': ti(:confirm_delete),
43+
'turbo-method': :delete })
4444
end
4545

4646
# Standard list action to the given path.

app/helpers/dry_crud/table/actions.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def destroy_action_col(**html_options, &block)
5757
action_col do |entry|
5858
path = action_path(entry, &block)
5959
if path
60-
table_action_link('remove',
60+
table_action_link('trash',
6161
path,
6262
**html_options.merge(
63-
data: { confirm: ti(:confirm_delete),
64-
method: :delete }
63+
data: { 'turbo-confirm': ti(:confirm_delete),
64+
'turbo-method': :delete }
6565
))
6666
end
6767
end

app/views/shared/_error_messages.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<% if errors.any? %>
22
<div id='error_explanation' class='alert alert-danger'>
3-
<h2>
3+
<p>
44
<%= ti(:"errors.header", count: errors.count, model: object.to_s) %>
5-
</h2>
5+
</p>
66
<ul>
77
<% errors.full_messages.each do |msg| %>
88
<li><%= msg %></li>

test/templates/app/controllers/admin/cities_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Admin
22
# Cities Controller nested under /admin and countries
3-
class CitiesController < AjaxController
3+
class CitiesController < TurboController
44
self.nesting = :admin, Country
55

66
self.search_columns = :name, 'countries.name'

test/templates/app/controllers/admin/countries_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Admin
22
# Countries Controller nested under /admin
3-
class CountriesController < AjaxController
3+
class CountriesController < TurboController
44
self.nesting = :admin
55

66
self.search_columns = :name, :code

test/templates/app/controllers/people_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# People Controller
2-
class PeopleController < AjaxController
2+
class PeopleController < TurboController
33
self.search_columns = [:name, :email, :remarks, 'cities.name']
44

55
self.default_sort = 'people.name, countries.code, cities.name'
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Crud controller responding to js as well
2-
class AjaxController < CrudController
3-
def ajax; end
2+
class TurboController < CrudController
3+
def turbo; end
44

55
def update
66
super do |format, _success|
7-
format.js
7+
format.turbo_stream
88
end
99
end
1010
end

0 commit comments

Comments
 (0)