From ed2b217a082a3738bbc6232de8abc9e3c4ace593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 27 Jul 2020 12:11:33 +0200 Subject: [PATCH] Remove duplication in oauth actions We were writing the same code twice, with the only difference being the text "Sign up" in the sign_up action, and "Sign in" in the sign_in action. Note we're renaming the `omniauth.info_*` I18n keys so we don't need to add new exceptions to the `ignore_unused` list, and so it's consistent with all the other keys under the `omniauth` key. --- app/views/devise/_omniauth_form.html.erb | 134 ++++++--------------- app/views/devise/sessions/new.html.erb | 2 +- app/views/users/registrations/new.html.erb | 2 +- config/locales/en/general.yml | 5 +- config/locales/es/general.yml | 5 +- 5 files changed, 48 insertions(+), 100 deletions(-) diff --git a/app/views/devise/_omniauth_form.html.erb b/app/views/devise/_omniauth_form.html.erb index 9010330c4..d820e5e4e 100644 --- a/app/views/devise/_omniauth_form.html.erb +++ b/app/views/devise/_omniauth_form.html.erb @@ -1,103 +1,49 @@ <% if feature?(:twitter_login) || feature?(:facebook_login) || feature?(:google_login) %> - - <% if current_page?(new_user_session_path) %> -
-
-
- <%= t("omniauth.info_sign_in") %> -
-
- - <% if feature? :twitter_login %> -
- <%= link_to t("omniauth.twitter.name"), user_twitter_omniauth_authorize_path, - title: t("omniauth.twitter.sign_in"), - class: "button-twitter button expanded", - method: :post %> -
- <% end %> - - <% if feature? :facebook_login %> -
- <%= link_to t("omniauth.facebook.name"), user_facebook_omniauth_authorize_path, - title: t("omniauth.facebook.sign_in"), - class: "button-facebook button expanded", - method: :post %> -
- <% end %> - - <% if feature? :google_login %> -
- <%= link_to t("omniauth.google_oauth2.name"), user_google_oauth2_omniauth_authorize_path, - title: t("omniauth.google_oauth2.sign_in"), - class: "button-google button expanded", - method: :post %> -
- <% end %> - - <% if feature? :wordpress_login %> -
- <%= link_to t("omniauth.wordpress_oauth2.name"), user_wordpress_oauth2_omniauth_authorize_path, - title: t("omniauth.wordpress_oauth2.sign_in"), - class: "button-wordpress button expanded", - method: :post %> -
- <% end %> - -
- <%= t("omniauth.or_fill") %> +
+
+
+ <%= t("omniauth.info.#{action}") %>
- <% elsif current_page?(new_user_registration_path) %> -
-
-
- <%= t("omniauth.info_sign_up") %> -
+ <% if feature? :twitter_login %> +
+ <%= link_to t("omniauth.twitter.name"), user_twitter_omniauth_authorize_path, + title: t("omniauth.twitter.#{action}"), + class: "button-twitter button expanded", + method: :post %>
+ <% end %> - <% if feature? :twitter_login %> -
- <%= link_to t("omniauth.twitter.name"), user_twitter_omniauth_authorize_path, - title: t("omniauth.twitter.sign_up"), - class: "button-twitter button expanded", - method: :post %> -
- <% end %> - - <% if feature? :facebook_login %> -
- <%= link_to t("omniauth.facebook.name"), user_facebook_omniauth_authorize_path, - title: t("omniauth.facebook.sign_up"), - class: "button-facebook button expanded", - method: :post %> -
- <% end %> - - <% if feature? :google_login %> -
- <%= link_to t("omniauth.google_oauth2.name"), user_google_oauth2_omniauth_authorize_path, - title: t("omniauth.google_oauth2.sign_up"), - class: "button-google button expanded", - method: :post %> - -
- <% end %> - - <% if feature? :wordpress_login %> -
- <%= link_to t("omniauth.wordpress_oauth2.name"), user_wordpress_oauth2_omniauth_authorize_path, - title: t("omniauth.wordpress_oauth2.sign_up"), - class: "button-wordpress button expanded", - method: :post %> -
- <% end %> - -
- <%= t("omniauth.or_fill") %> + <% if feature? :facebook_login %> +
+ <%= link_to t("omniauth.facebook.name"), user_facebook_omniauth_authorize_path, + title: t("omniauth.facebook.#{action}"), + class: "button-facebook button expanded", + method: :post %>
+ <% end %> + + <% if feature? :google_login %> +
+ <%= link_to t("omniauth.google_oauth2.name"), user_google_oauth2_omniauth_authorize_path, + title: t("omniauth.google_oauth2.#{action}"), + class: "button-google button expanded", + method: :post %> +
+ <% end %> + + <% if feature? :wordpress_login %> +
+ <%= link_to t("omniauth.wordpress_oauth2.name"), user_wordpress_oauth2_omniauth_authorize_path, + title: t("omniauth.wordpress_oauth2.#{action}"), + class: "button-wordpress button expanded", + method: :post %> +
+ <% end %> + +
+ <%= t("omniauth.or_fill") %>
- <% end %> - +
<% end %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index d0d219c62..85ae3d320 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,7 +1,7 @@ <% provide :title do %><%= t("devise_views.sessions.new.title") %><% end %>

<%= t("devise_views.sessions.new.title") %>

-<%= render "devise/omniauth_form" %> +<%= render "devise/omniauth_form", action: "sign_in" %>

<%= sanitize(t("devise_views.shared.links.signup", diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index f296d3b69..7dafa264f 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -1,7 +1,7 @@ <% provide :title do %><%= t("devise_views.users.registrations.new.title") %><% end %>

<%= t("devise_views.users.registrations.new.title") %>

-<%= render "devise/omniauth_form" %> +<%= render "devise/omniauth_form", action: "sign_up" %> <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "shared/errors", resource: resource %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 24fb4fe6f..23dc76513 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -299,8 +299,9 @@ en: sign_in: Sign in with Twitter sign_up: Sign up with Twitter name: Twitter - info_sign_in: "Sign in with:" - info_sign_up: "Sign up with:" + info: + sign_in: "Sign in with:" + sign_up: "Sign up with:" or_fill: "Or fill the following form:" proposals: create: diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 92de921d8..dda320025 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -299,8 +299,9 @@ es: sign_in: Entra con Twitter sign_up: Regístrate con Twitter name: Twitter - info_sign_in: "Entra con:" - info_sign_up: "Regístrate con:" + info: + sign_in: "Entra con:" + sign_up: "Regístrate con:" or_fill: "O rellena el siguiente formulario:" proposals: create: