Skip to content

Commit 2d25125

Browse files
Refactor flashes
1 parent b128001 commit 2d25125

File tree

8 files changed

+33
-35
lines changed

8 files changed

+33
-35
lines changed

lib/generators/tailwindcss/authentication/authentication_generator.rb

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ module Tailwindcss
44
module Generators
55
class AuthenticationGenerator < Erb::Generators::AuthenticationGenerator
66
source_root File.expand_path("templates", __dir__)
7+
8+
def copy_view_files
9+
template "../../scaffold/templates/_flashes.html.erb", "app/views/application/_flashes.html.erb"
10+
end
711
end
812
end
913
end

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
<div class="mx-auto md:w-2/3 w-full">
2-
<%% if alert = flash[:alert] %>
3-
<p class="py-2 px-3 bg-red-50 mb-5 text-red-500 font-medium rounded-lg inline-block" id="alert"><%%= alert %></p>
4-
<%% end %>
1+
<div class="w-full mx-auto md:w-2/3">
2+
<%%= render "flashes" %>
53

6-
<h1 class="font-bold text-4xl">Update your password</h1>
4+
<h1 class="text-4xl font-bold">Update your password</h1>
75

86
<%%= form_with url: password_path(params[:token]), method: :put, class: "contents" do |form| %>
97
<div class="my-5">
10-
<%%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: "Enter new password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 outline-none focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
8+
<%%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: "Enter new password", maxlength: 72, class: "block w-full px-3 py-2 mt-2 border border-gray-400 rounded-md shadow outline-none focus:outline-blue-600" %>
119
</div>
1210

1311
<div class="my-5">
14-
<%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: "Repeat new password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 outline-none focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
12+
<%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: "Repeat new password", maxlength: 72, class: "block w-full px-3 py-2 mt-2 border border-gray-400 rounded-md shadow outline-none focus:outline-blue-600" %>
1513
</div>
1614

1715
<div class="inline">

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
<div class="mx-auto md:w-2/3 w-full">
2-
<%% if alert = flash[:alert] %>
3-
<p class="py-2 px-3 bg-red-50 mb-5 text-red-500 font-medium rounded-lg inline-block" id="alert"><%%= alert %></p>
4-
<%% end %>
1+
<div class="w-full mx-auto md:w-2/3">
2+
<%%= render "flashes" %>
53

6-
<h1 class="font-bold text-4xl">Forgot your password?</h1>
4+
<h1 class="text-4xl font-bold">Forgot your password?</h1>
75

86
<%%= form_with url: passwords_path, class: "contents" do |form| %>
97
<div class="my-5">
10-
<%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "block shadow rounded-md border border-gray-400 outline-none focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
8+
<%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "block w-full px-3 py-2 mt-2 border border-gray-400 rounded-md shadow outline-none focus:outline-blue-600" %>
119
</div>
1210

1311
<div class="inline">

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

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
<div class="mx-auto md:w-2/3 w-full">
2-
<%% if alert = flash[:alert] %>
3-
<p class="py-2 px-3 bg-red-50 mb-5 text-red-500 font-medium rounded-lg inline-block" id="alert"><%%= alert %></p>
4-
<%% end %>
5-
6-
<%% if notice = flash[:notice] %>
7-
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%%= notice %></p>
8-
<%% end %>
1+
<div class="w-full mx-auto md:w-2/3">
2+
<%%= render "flashes" %>
93

10-
<h1 class="font-bold text-4xl">Sign in</h1>
4+
<h1 class="text-4xl font-bold">Sign in</h1>
115

126
<%%= form_with url: session_url, class: "contents" do |form| %>
137
<div class="my-5">
14-
<%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "block shadow rounded-md border border-gray-400 focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
8+
<%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "block w-full px-3 py-2 mt-2 border border-gray-400 rounded-md shadow focus:outline-blue-600" %>
159
</div>
1610

1711
<div class="my-5">
18-
<%%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
12+
<%%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72, class: "block w-full px-3 py-2 mt-2 border border-gray-400 rounded-md shadow focus:outline-blue-600" %>
1913
</div>
2014

2115
<div class="col-span-6 sm:flex sm:items-center sm:gap-4">

lib/generators/tailwindcss/scaffold/scaffold_generator.rb

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def copy_view_files
2424
end
2525

2626
template "partial.html.erb", File.join("app/views", controller_file_path, "_#{singular_name}.html.erb")
27+
template "_flashes.html.erb", "app/views/application/_flashes.html.erb"
2728
end
2829

2930
private
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<%% if notice.present? %>
2+
<p class="inline-block px-3 py-2 mb-5 font-medium text-green-500 rounded-md bg-green-50" id="notice"><%%= notice %></p>
3+
<%% end %>
4+
5+
<%% if alert.present? %>
6+
<p class="inline-block px-3 py-2 mb-5 font-medium text-red-500 rounded-lg bg-red-50" id="alert"><%%= alert %></p>
7+
<%% end %>
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<%% content_for :title, "<%= human_name.pluralize %>" %>
22

33
<div class="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 %>
4+
<%%= render "flashes" %>
75

8-
<div class="flex justify-between items-center">
9-
<h1 class="font-bold text-4xl"><%= human_name.pluralize %></h1>
6+
<div class="flex items-center justify-between">
7+
<h1 class="text-4xl font-bold"><%= human_name.pluralize %></h1>
108
<%%= 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" %>
119
</div>
1210

@@ -19,7 +17,7 @@
1917
</p>
2018
<%% end %>
2119
<%% else %>
22-
<p class="text-center my-10">No <%= human_name.downcase.pluralize %> found.</p>
20+
<p class="my-10 text-center">No <%= human_name.downcase.pluralize %> found.</p>
2321
<%% end %>
2422
</div>
2523
</div>

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<%% content_for :title, "Showing <%= human_name.downcase %>" %>
22

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 %>
3+
<div class="w-full md:w-2/3">
4+
<%%= render "flashes" %>
75

8-
<h1 class="font-bold text-4xl">Showing <%= human_name.downcase %></h1>
6+
<h1 class="text-4xl font-bold">Showing <%= human_name.downcase %></h1>
97

108
<%%= render @<%= singular_table_name %> %>
119

0 commit comments

Comments
 (0)