From 2d25125f79310aebee3fd9e356f74df053da1056 Mon Sep 17 00:00:00 2001 From: Patricio Mac Adden Date: Sat, 11 Jan 2025 00:32:25 -0300 Subject: [PATCH 1/2] Refactor flashes --- .../authentication/authentication_generator.rb | 4 ++++ .../templates/app/views/passwords/edit.html.erb | 12 +++++------- .../templates/app/views/passwords/new.html.erb | 10 ++++------ .../templates/app/views/sessions/new.html.erb | 16 +++++----------- .../tailwindcss/scaffold/scaffold_generator.rb | 1 + .../scaffold/templates/_flashes.html.erb.tt | 7 +++++++ .../scaffold/templates/index.html.erb.tt | 10 ++++------ .../scaffold/templates/show.html.erb.tt | 8 +++----- 8 files changed, 33 insertions(+), 35 deletions(-) create mode 100644 lib/generators/tailwindcss/scaffold/templates/_flashes.html.erb.tt diff --git a/lib/generators/tailwindcss/authentication/authentication_generator.rb b/lib/generators/tailwindcss/authentication/authentication_generator.rb index aa6fc23b..220a2fa4 100644 --- a/lib/generators/tailwindcss/authentication/authentication_generator.rb +++ b/lib/generators/tailwindcss/authentication/authentication_generator.rb @@ -4,6 +4,10 @@ module Tailwindcss module Generators class AuthenticationGenerator < Erb::Generators::AuthenticationGenerator source_root File.expand_path("templates", __dir__) + + def copy_view_files + template "../../scaffold/templates/_flashes.html.erb", "app/views/application/_flashes.html.erb" + end end end end diff --git a/lib/generators/tailwindcss/authentication/templates/app/views/passwords/edit.html.erb b/lib/generators/tailwindcss/authentication/templates/app/views/passwords/edit.html.erb index 707bbe5c..76a855eb 100644 --- a/lib/generators/tailwindcss/authentication/templates/app/views/passwords/edit.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/app/views/passwords/edit.html.erb @@ -1,17 +1,15 @@ -
- <%% if alert = flash[:alert] %> -

<%%= alert %>

- <%% end %> +
+ <%%= render "flashes" %> -

Update your password

+

Update your password

<%%= form_with url: password_path(params[:token]), method: :put, class: "contents" do |form| %>
- <%%= 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" %> + <%%= 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" %>
- <%%= 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" %> + <%%= 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" %>
diff --git a/lib/generators/tailwindcss/authentication/templates/app/views/passwords/new.html.erb b/lib/generators/tailwindcss/authentication/templates/app/views/passwords/new.html.erb index 72c434de..66a6227c 100644 --- a/lib/generators/tailwindcss/authentication/templates/app/views/passwords/new.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/app/views/passwords/new.html.erb @@ -1,13 +1,11 @@ -
- <%% if alert = flash[:alert] %> -

<%%= alert %>

- <%% end %> +
+ <%%= render "flashes" %> -

Forgot your password?

+

Forgot your password?

<%%= form_with url: passwords_path, class: "contents" do |form| %>
- <%%= 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" %> + <%%= 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" %>
diff --git a/lib/generators/tailwindcss/authentication/templates/app/views/sessions/new.html.erb b/lib/generators/tailwindcss/authentication/templates/app/views/sessions/new.html.erb index 92d64b79..acd3fbcd 100644 --- a/lib/generators/tailwindcss/authentication/templates/app/views/sessions/new.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/app/views/sessions/new.html.erb @@ -1,21 +1,15 @@ -
- <%% if alert = flash[:alert] %> -

<%%= alert %>

- <%% end %> - - <%% if notice = flash[:notice] %> -

<%%= notice %>

- <%% end %> +
+ <%%= render "flashes" %> -

Sign in

+

Sign in

<%%= form_with url: session_url, class: "contents" do |form| %>
- <%%= 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" %> + <%%= 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" %>
- <%%= 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" %> + <%%= 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" %>
diff --git a/lib/generators/tailwindcss/scaffold/scaffold_generator.rb b/lib/generators/tailwindcss/scaffold/scaffold_generator.rb index 39c2da1f..59d6fa73 100644 --- a/lib/generators/tailwindcss/scaffold/scaffold_generator.rb +++ b/lib/generators/tailwindcss/scaffold/scaffold_generator.rb @@ -24,6 +24,7 @@ def copy_view_files end template "partial.html.erb", File.join("app/views", controller_file_path, "_#{singular_name}.html.erb") + template "_flashes.html.erb", "app/views/application/_flashes.html.erb" end private diff --git a/lib/generators/tailwindcss/scaffold/templates/_flashes.html.erb.tt b/lib/generators/tailwindcss/scaffold/templates/_flashes.html.erb.tt new file mode 100644 index 00000000..9013ac74 --- /dev/null +++ b/lib/generators/tailwindcss/scaffold/templates/_flashes.html.erb.tt @@ -0,0 +1,7 @@ +<%% if notice.present? %> +

<%%= notice %>

+<%% end %> + +<%% if alert.present? %> +

<%%= alert %>

+<%% end %> diff --git a/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt b/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt index 3d337f95..d0a93148 100644 --- a/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt +++ b/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt @@ -1,12 +1,10 @@ <%% content_for :title, "<%= human_name.pluralize %>" %>
- <%% if notice.present? %> -

<%%= notice %>

- <%% end %> + <%%= render "flashes" %> -
-

<%= human_name.pluralize %>

+
+

<%= human_name.pluralize %>

<%%= 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" %>
@@ -19,7 +17,7 @@

<%% end %> <%% else %> -

No <%= human_name.downcase.pluralize %> found.

+

No <%= human_name.downcase.pluralize %> found.

<%% end %>
diff --git a/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt b/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt index 3a49e9a0..1a008ed3 100644 --- a/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt +++ b/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt @@ -1,11 +1,9 @@ <%% content_for :title, "Showing <%= human_name.downcase %>" %> -
- <%% if notice.present? %> -

<%%= notice %>

- <%% end %> +
+ <%%= render "flashes" %> -

Showing <%= human_name.downcase %>

+

Showing <%= human_name.downcase %>

<%%= render @<%= singular_table_name %> %> From d1abd373292c627bc3b05e9aa97a895cbcfff8cd Mon Sep 17 00:00:00 2001 From: Patricio Mac Adden Date: Mon, 20 Jan 2025 00:25:47 -0300 Subject: [PATCH 2/2] revert class ordering --- .../templates/app/views/passwords/edit.html.erb | 8 ++++---- .../templates/app/views/passwords/new.html.erb | 6 +++--- .../templates/app/views/sessions/new.html.erb | 8 ++++---- .../tailwindcss/scaffold/templates/index.html.erb.tt | 6 +++--- .../tailwindcss/scaffold/templates/show.html.erb.tt | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/generators/tailwindcss/authentication/templates/app/views/passwords/edit.html.erb b/lib/generators/tailwindcss/authentication/templates/app/views/passwords/edit.html.erb index 76a855eb..57e4fcc4 100644 --- a/lib/generators/tailwindcss/authentication/templates/app/views/passwords/edit.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/app/views/passwords/edit.html.erb @@ -1,15 +1,15 @@ -
+
<%%= render "flashes" %> -

Update your password

+

Update your password

<%%= form_with url: password_path(params[:token]), method: :put, class: "contents" do |form| %>
- <%%= 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" %> + <%%= 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" %>
- <%%= 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" %> + <%%= 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" %>
diff --git a/lib/generators/tailwindcss/authentication/templates/app/views/passwords/new.html.erb b/lib/generators/tailwindcss/authentication/templates/app/views/passwords/new.html.erb index 66a6227c..db743016 100644 --- a/lib/generators/tailwindcss/authentication/templates/app/views/passwords/new.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/app/views/passwords/new.html.erb @@ -1,11 +1,11 @@ -
+
<%%= render "flashes" %> -

Forgot your password?

+

Forgot your password?

<%%= form_with url: passwords_path, class: "contents" do |form| %>
- <%%= 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" %> + <%%= 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" %>
diff --git a/lib/generators/tailwindcss/authentication/templates/app/views/sessions/new.html.erb b/lib/generators/tailwindcss/authentication/templates/app/views/sessions/new.html.erb index acd3fbcd..8a425512 100644 --- a/lib/generators/tailwindcss/authentication/templates/app/views/sessions/new.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/app/views/sessions/new.html.erb @@ -1,15 +1,15 @@ -
+
<%%= render "flashes" %> -

Sign in

+

Sign in

<%%= form_with url: session_url, class: "contents" do |form| %>
- <%%= 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" %> + <%%= 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" %>
- <%%= 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" %> + <%%= 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" %>
diff --git a/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt b/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt index d0a93148..2b245cf3 100644 --- a/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt +++ b/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt @@ -3,8 +3,8 @@
<%%= render "flashes" %> -
-

<%= human_name.pluralize %>

+
+

<%= human_name.pluralize %>

<%%= 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" %>
@@ -17,7 +17,7 @@

<%% end %> <%% else %> -

No <%= human_name.downcase.pluralize %> found.

+

No <%= human_name.downcase.pluralize %> found.

<%% end %>
diff --git a/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt b/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt index 1a008ed3..cd90644b 100644 --- a/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt +++ b/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt @@ -1,9 +1,9 @@ <%% content_for :title, "Showing <%= human_name.downcase %>" %> -
+
<%%= render "flashes" %> -

Showing <%= human_name.downcase %>

+

Showing <%= human_name.downcase %>

<%%= render @<%= singular_table_name %> %>