Skip to content

Commit 8f2b32a

Browse files
committed
Support Rails 6
Add custom scaffold generator that is same as the one inside the Rails 7 in order to make this work with Rails 6.
1 parent 7f8bbc1 commit 8f2b32a

File tree

7 files changed

+27
-8
lines changed

7 files changed

+27
-8
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
/node_modules
1212
.byebug_history
1313
*.gem
14-
.idea/
14+
.idea/
15+
**/tmp/

lib/generators/tailwindcss/scaffold/scaffold_generator.rb

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# frozen_string_literal: true
2-
3-
require "rails/generators/erb"
41
require 'rails/generators/erb/scaffold/scaffold_generator'
52
require "rails/generators/resource_helpers"
63

lib/generators/tailwindcss/scaffold/templates/edit.html.erb.tt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
<%%= link_to "Show this <%= human_name.downcase %>", @<%= singular_table_name %>, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
77
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
8-
</div>
8+
</div>

lib/generators/tailwindcss/scaffold/templates/new.html.erb.tt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
55

66
<%%= link_to 'Back to <%= human_name.pluralize.downcase %>', <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
7-
</div>
7+
</div>

lib/generators/tailwindcss/scaffold/templates/partial.html.erb.tt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
<%%= link_to 'Edit this <%= human_name.downcase %>', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
2020
<hr class="mt-6">
2121
<%% end %>
22-
</div>
22+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require "test_helper"
2+
require "generators/tailwindcss/scaffold/scaffold_generator"
3+
4+
class Tailwindcss::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
5+
GENERATION_PATH = File.expand_path("../tmp", File.dirname(__FILE__))
6+
7+
tests Tailwindcss::Generators::ScaffoldGenerator
8+
destination GENERATION_PATH
9+
10+
arguments %w(message title:string content:text)
11+
12+
Minitest.after_run do
13+
FileUtils.rm_rf GENERATION_PATH
14+
end
15+
16+
test "generates correct view templates" do
17+
run_generator
18+
19+
%w(index edit new show _form _message).each { |view| assert_file "app/views/messages/#{view}.html.erb" }
20+
end
21+
end

test/test_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
require_relative "../lib/tailwindcss-rails"
88

99
require "rails/test_unit/reporter"
10-
Rails::TestUnitReporter.executable = 'bin/test'
10+
Rails::TestUnitReporter.executable = "bin/test"
1111

0 commit comments

Comments
 (0)