From a0783a7135df01682f24248724ef0bacc912d6fa Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 29 Jul 2024 13:26:30 -0400 Subject: [PATCH 1/5] introduce specialized view for rails 8 authentication generator Co-authored-by: yshmarov --- .../authentication_generator.rb | 9 ++++++++ .../templates/views/sessions/new.html.erb | 22 +++++++++++++++++++ .../authentication_generator_test.rb | 16 ++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 lib/generators/tailwindcss/authentication/authentication_generator.rb create mode 100644 lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb create mode 100644 test/lib/generators/tailwindcss/authentication_generator_test.rb diff --git a/lib/generators/tailwindcss/authentication/authentication_generator.rb b/lib/generators/tailwindcss/authentication/authentication_generator.rb new file mode 100644 index 0000000..aa6fc23 --- /dev/null +++ b/lib/generators/tailwindcss/authentication/authentication_generator.rb @@ -0,0 +1,9 @@ +require "rails/generators/erb/authentication/authentication_generator" + +module Tailwindcss + module Generators + class AuthenticationGenerator < Erb::Generators::AuthenticationGenerator + source_root File.expand_path("templates", __dir__) + end + end +end diff --git a/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb b/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb new file mode 100644 index 0000000..824b506 --- /dev/null +++ b/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb @@ -0,0 +1,22 @@ +
+

Sign in

+ + <%% if alert = flash[:alert] %> +

<%%= alert %>

+ <%% end %> + + <%%= 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 outline-none 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 shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%%= form.submit "Sign in", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+ <%% end %> +
+ diff --git a/test/lib/generators/tailwindcss/authentication_generator_test.rb b/test/lib/generators/tailwindcss/authentication_generator_test.rb new file mode 100644 index 0000000..bdf712b --- /dev/null +++ b/test/lib/generators/tailwindcss/authentication_generator_test.rb @@ -0,0 +1,16 @@ +require "test_helper" + +if Rails::VERSION::MAJOR >= 8 + require "generators/tailwindcss/authentication/authentication_generator" + + class Tailwindcss::Generators::AuthenticationGeneratorTest < Rails::Generators::TestCase + tests Tailwindcss::Generators::AuthenticationGenerator + destination TAILWINDCSS_TEST_APP_ROOT + + test "generates the new session template" do + run_generator + + assert_file "app/views/sessions/new.html.erb" + end + end +end From 381446b2405dbbf028c3afcd8606de700400b7e5 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 30 Jul 2024 15:20:38 -0400 Subject: [PATCH 2/5] ci: add unit tests to the upstream workflow because the authentication template is only on rails edge --- .github/workflows/upstream.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml index b2dda2b..0b0f35e 100644 --- a/.github/workflows/upstream.yml +++ b/.github/workflows/upstream.yml @@ -14,20 +14,42 @@ on: - .github/workflows/upstream.yml # this file jobs: + tests: + name: "tests (rails main)" + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ["3.3"] + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{matrix.ruby}} + - run: | + rm Gemfile.lock + bundle remove actionmailer + git clone --depth 1 --branch main https://github.com/rails/rails + bundle add actionmailer --path=rails + bundle add railties --path=rails + bundle install + - name: Run tests + run: bin/test + user-journey: name: "user-journey (rails main)" + runs-on: ${{matrix.plat}}-latest strategy: fail-fast: false matrix: plat: ["ubuntu", "windows", "macos"] - runs-on: ${{matrix.plat}}-latest env: RAILSOPTS: --git=https://github.com/rails/rails --branch main steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: - ruby-version: "3.2" + ruby-version: "3.3" bundler: latest - run: test/integration/user_journey_test.sh shell: bash From 1d84cd12d97a2a87ef935a4fc45b2b340cc70bc4 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 3 Aug 2024 15:56:42 -0700 Subject: [PATCH 3/5] Add templates for password reset templates --- .../templates/views/passwords/edit.html.erb | 21 +++++++++++++++++++ .../templates/views/passwords/new.html.erb | 17 +++++++++++++++ .../templates/views/sessions/new.html.erb | 14 +++++++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb create mode 100644 lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb diff --git a/lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb b/lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb new file mode 100644 index 0000000..f648e89 --- /dev/null +++ b/lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb @@ -0,0 +1,21 @@ +
+

Update your password

+ + <%% if alert = flash[:alert] %> +

<%%= alert %>

+ <%% end %> + + <%%= 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 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 shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%%= form.submit "Save", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+ <%% end %> +
diff --git a/lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb b/lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb new file mode 100644 index 0000000..431cf70 --- /dev/null +++ b/lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb @@ -0,0 +1,17 @@ +
+

Forgot your password?

+ + <%% if alert = flash[:alert] %> +

<%%= alert %>

+ <%% end %> + + <%%= 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 px-3 py-2 mt-2 w-full" %> +
+ +
+ <%%= form.submit "Email reset instructions", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+ <%% end %> +
diff --git a/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb b/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb index 824b506..aebe999 100644 --- a/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb @@ -5,6 +5,10 @@

<%%= alert %>

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

<%%= notice %>

+ <%% end %> + <%%= 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 outline-none px-3 py-2 mt-2 w-full" %> @@ -14,8 +18,14 @@ <%%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
-
- <%%= form.submit "Sign in", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+
+ <%%= form.submit "Sign in", class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+ +
+ <%%= link_to "Forgot password?", new_password_path, class: "text-gray-700 underline" %> +
<%% end %>
From dfafa4c329e655383fe72189ea17c85fb5201e04 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 3 Aug 2024 15:57:25 -0700 Subject: [PATCH 4/5] Excess CR --- .../authentication/templates/views/sessions/new.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb b/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb index aebe999..644b578 100644 --- a/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb @@ -29,4 +29,3 @@ <%% end %> - From 6116343e842f876fd5e5735f807bac8af0b6c6e8 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 3 Aug 2024 17:21:55 -0700 Subject: [PATCH 5/5] Alerts and notices look better above the heading --- .../authentication/templates/views/passwords/edit.html.erb | 4 ++-- .../authentication/templates/views/passwords/new.html.erb | 4 ++-- .../authentication/templates/views/sessions/new.html.erb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb b/lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb index f648e89..939b0b8 100644 --- a/lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/views/passwords/edit.html.erb @@ -1,10 +1,10 @@
-

Update your password

- <%% if alert = flash[:alert] %>

<%%= alert %>

<%% end %> +

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 px-3 py-2 mt-2 w-full" %> diff --git a/lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb b/lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb index 431cf70..e5d8819 100644 --- a/lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/views/passwords/new.html.erb @@ -1,10 +1,10 @@
-

Forgot your password?

- <%% if alert = flash[:alert] %>

<%%= alert %>

<%% end %> +

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 px-3 py-2 mt-2 w-full" %> diff --git a/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb b/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb index 644b578..a475154 100644 --- a/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb +++ b/lib/generators/tailwindcss/authentication/templates/views/sessions/new.html.erb @@ -1,6 +1,4 @@
-

Sign in

- <%% if alert = flash[:alert] %>

<%%= alert %>

<%% end %> @@ -9,6 +7,8 @@

<%%= notice %>

<%% end %> +

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 outline-none px-3 py-2 mt-2 w-full" %>