Skip to content

Commit c2b3abf

Browse files
authored
Merge pull request #452 from patriciomacadden/improve-scaffold-views
Improve scaffold views
2 parents d95bd19 + af38df9 commit c2b3abf

File tree

10 files changed

+53
-44
lines changed

10 files changed

+53
-44
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
tailwindcss-rails (3.0.0)
4+
tailwindcss-rails (3.1.0)
55
railties (>= 7.0.0)
66
tailwindcss-ruby
77

lib/generators/tailwindcss/authentication/templates/app/views/passwords/edit.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</div>
1616

1717
<div class="inline">
18-
<%%= form.submit "Save", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
18+
<%%= form.submit "Save", class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
1919
</div>
2020
<%% end %>
2121
</div>

lib/generators/tailwindcss/authentication/templates/app/views/passwords/new.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</div>
1212

1313
<div class="inline">
14-
<%%= form.submit "Email reset instructions", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
14+
<%%= form.submit "Email reset instructions", class: "rounded-lg px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
1515
</div>
1616
<%% end %>
1717
</div>

lib/generators/tailwindcss/authentication/templates/app/views/sessions/new.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020

2121
<div class="col-span-6 sm:flex sm:items-center sm:gap-4">
2222
<div class="inline">
23-
<%%= form.submit "Sign in", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
23+
<%%= form.submit "Sign in", class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
2424
</div>
2525

2626
<div class="mt-4 text-sm text-gray-500 sm:mt-0">
27-
<%%= link_to "Forgot password?", new_password_path, class: "text-gray-700 underline" %>
27+
<%%= link_to "Forgot password?", new_password_path, class: "text-gray-700 underline hover:no-underline" %>
2828
</div>
2929
</div>
3030
<%% end %>
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<%%= form_with(model: <%= model_resource_name %>, class: "contents") do |form| %>
22
<%% if <%= singular_table_name %>.errors.any? %>
3-
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
3+
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-md mt-3">
44
<h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
55

6-
<ul>
6+
<ul class="list-disc ml-6">
77
<%% <%= singular_table_name %>.errors.each do |error| %>
88
<li><%%= error.full_message %></li>
99
<%% end %>
@@ -15,29 +15,29 @@
1515
<div class="my-5">
1616
<% if attribute.password_digest? -%>
1717
<%%= form.label :password %>
18-
<%%= form.password_field :password, class: "block shadow rounded-md border border-gray-400 outline-none focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
19-
</div>
18+
<%%= form.password_field :password, class: ["block shadow rounded-md border outline-none px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:password].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:password].any?}] %>
19+
</div>
2020

21-
<div class="my-5">
21+
<div class="my-5">
2222
<%%= form.label :password_confirmation %>
23-
<%%= form.password_field :password_confirmation, class: "block shadow rounded-md border border-gray-400 outline-none focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
23+
<%%= form.password_field :password_confirmation, class: ["block shadow rounded-md border outline-none px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:password_confirmation].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:password_confirmation].any?}] %>
2424
<% elsif attribute.attachments? -%>
2525
<%%= form.label :<%= attribute.column_name %> %>
26-
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true, class: "block shadow rounded-md border border-gray-400 outline-none focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
26+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true, class: ["block shadow rounded-md border outline-none px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:password].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:password].any?}] %>
2727
<% else -%>
2828
<%%= form.label :<%= attribute.column_name %> %>
2929
<% if attribute.field_type == :textarea || attribute.field_type == :text_area -%>
30-
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
30+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, rows: 4, class: ["block shadow rounded-md border outline-none px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
3131
<% elsif attribute.field_type == :checkbox || attribute.field_type == :check_box -%>
32-
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: "block shadow rounded-md border border-gray-400 outline-none focus:outline-blue-600 mt-2 h-5 w-5" %>
32+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: ["block shadow rounded-md border outline-none mt-2 h-5 w-5", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
3333
<% else -%>
34-
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: "block shadow rounded-md border border-gray-400 outline-none focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
34+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: ["block shadow rounded-md border outline-none px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
3535
<% end -%>
3636
<% end -%>
3737
</div>
3838

3939
<% end -%>
4040
<div class="inline">
41-
<%%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
41+
<%%= form.submit class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
4242
</div>
4343
<%% end %>
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<div class="mx-auto md:w-2/3 w-full">
1+
<%% content_for :title, "Editing <%= human_name.downcase %>" %>
2+
3+
<div class="md:w-2/3 w-full">
24
<h1 class="font-bold text-4xl">Editing <%= human_name.downcase %></h1>
35

46
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
57

6-
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
7-
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
8+
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, class: "ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
9+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>, class: "ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
810
</div>
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1+
<%% content_for :title, "<%= human_name.pluralize %>" %>
2+
13
<div class="w-full">
24
<%% if notice.present? %>
3-
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%%= notice %></p>
5+
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-md inline-block" id="notice"><%%= notice %></p>
46
<%% end %>
57

6-
<%% content_for :title, "<%= human_name.pluralize %>" %>
7-
88
<div class="flex justify-between items-center">
99
<h1 class="font-bold text-4xl"><%= human_name.pluralize %></h1>
10-
<%%= link_to "New <%= human_name.downcase %>", new_<%= singular_route_name %>_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
10+
<%%= link_to "New <%= human_name.downcase %>", new_<%= singular_route_name %>_path, class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white block font-medium" %>
1111
</div>
1212

1313
<div id="<%= plural_table_name %>" class="min-w-full">
14-
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
15-
<%%= render <%= singular_table_name %> %>
16-
<p>
17-
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(singular_table_name) %>, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
18-
</p>
14+
<%% if @<%= plural_table_name %>.any? %>
15+
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
16+
<%%= render <%= singular_table_name %> %>
17+
<p>
18+
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(singular_table_name) %>, class: "ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
19+
</p>
20+
<%% end %>
21+
<%% else %>
22+
<p class="text-center my-10">No <%= human_name.downcase.pluralize %> found.</p>
1923
<%% end %>
2024
</div>
2125
</div>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<div class="mx-auto md:w-2/3 w-full">
1+
<%% content_for :title, "New <%= human_name.downcase %>" %>
2+
3+
<div class="md:w-2/3 w-full">
24
<h1 class="font-bold text-4xl">New <%= human_name.downcase %></h1>
35

46
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
57

6-
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
8+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>, class: "ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
79
</div>

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

-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212
<%%= <%= singular_name %>.<%= attribute.column_name %> %>
1313
<% end -%>
1414
</p>
15-
1615
<% end -%>
1716
</div>
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
<div class="mx-auto md:w-2/3 w-full flex">
2-
<div class="mx-auto">
3-
<%% if notice.present? %>
4-
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%%= notice %></p>
5-
<%% end %>
6-
7-
<%%= render @<%= singular_table_name %> %>
8-
9-
<%%= link_to "Edit this <%= human_name.downcase %>", <%= edit_helper(type: :path) %>, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
10-
<%%= 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" %>
11-
<div class="inline-block ml-2">
12-
<%%= button_to "Destroy this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
13-
</div>
1+
<%% content_for :title, "Showing <%= human_name.downcase %>" %>
2+
3+
<div class="md:w-2/3 w-full">
4+
<%% if notice.present? %>
5+
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-md inline-block" id="notice"><%%= notice %></p>
6+
<%% end %>
7+
8+
<h1 class="font-bold text-4xl">Showing <%= human_name.downcase %></h1>
9+
10+
<%%= render @<%= singular_table_name %> %>
11+
12+
<%%= link_to "Edit this <%= human_name.downcase %>", <%= edit_helper(type: :path) %>, class: "mt-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
13+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path, class: "ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
14+
<div class="inline-block ml-2">
15+
<%%= button_to "Destroy this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, method: :delete, class: "mt-2 rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium" %>
1416
</div>
1517
</div>

0 commit comments

Comments
 (0)