From aa2d15aa338cd1e83462d58ff4eec1ce5fa122fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 2 Jan 2012 21:26:26 +0100 Subject: [PATCH] Move devise/shared/_links.erb to devise/_links.erb --- CHANGELOG.rdoc | 7 +++-- app/views/devise/_links.erb | 25 +++++++++++++++++ app/views/devise/confirmations/new.html.erb | 2 +- app/views/devise/passwords/edit.html.erb | 2 +- app/views/devise/passwords/new.html.erb | 2 +- app/views/devise/registrations/new.html.erb | 2 +- app/views/devise/sessions/new.html.erb | 2 +- app/views/devise/shared/_links.erb | 28 ++----------------- app/views/devise/unlocks/new.html.erb | 2 +- lib/generators/devise/views_generator.rb | 20 ++++--------- .../confirmations/new.html.erb | 2 +- .../simple_form_for/passwords/edit.html.erb | 2 +- .../simple_form_for/passwords/new.html.erb | 2 +- .../registrations/new.html.erb | 2 +- .../simple_form_for/sessions/new.html.erb | 2 +- .../simple_form_for/unlocks/new.html.erb | 2 +- test/generators/views_generator_test.rb | 2 +- 17 files changed, 52 insertions(+), 54 deletions(-) create mode 100644 app/views/devise/_links.erb diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 7255d9d6..c6e1a9e3 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -9,8 +9,11 @@ Notes: https://@plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0 * Do not run validations unless on reconfirmable branch * enhancements - * allow parent controller to be customizable - * inherit from the same Devise parent controller (by @sj26) + * Allow parent controller to be customizable + * Inherit from the same Devise parent controller (by @sj26) + +* deprecation + * Move devise/shared/_links.erb to devise/_links.erb == 2.0.0.rc diff --git a/app/views/devise/_links.erb b/app/views/devise/_links.erb new file mode 100644 index 00000000..eab783a4 --- /dev/null +++ b/app/views/devise/_links.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Sign in", new_session_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
+ <% end -%> +<% end -%> \ No newline at end of file diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb index b7ae403c..18d81b14 100644 --- a/app/views/devise/confirmations/new.html.erb +++ b/app/views/devise/confirmations/new.html.erb @@ -9,4 +9,4 @@
<%= f.submit "Resend confirmation instructions" %>
<% end %> -<%= render :partial => "devise/shared/links" %> \ No newline at end of file +<%= render "links" %> \ No newline at end of file diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index e75c9371..5f7bcf87 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -13,4 +13,4 @@
<%= f.submit "Change my password" %>
<% end %> -<%= render :partial => "devise/shared/links" %> \ No newline at end of file +<%= render "links" %> \ No newline at end of file diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index 6c21e9fd..b0b5690f 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -9,4 +9,4 @@
<%= f.submit "Send me reset password instructions" %>
<% end %> -<%= render :partial => "devise/shared/links" %> \ No newline at end of file +<%= render "links" %> \ No newline at end of file diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index d15e275a..f5136f13 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -15,4 +15,4 @@
<%= f.submit "Sign up" %>
<% end %> -<%= render :partial => "devise/shared/links" %> +<%= render "links" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index ff59f7cc..f12116bf 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -14,4 +14,4 @@
<%= f.submit "Sign in" %>
<% end %> -<%= render :partial => "devise/shared/links" %> \ No newline at end of file +<%= render "links" %> \ No newline at end of file diff --git a/app/views/devise/shared/_links.erb b/app/views/devise/shared/_links.erb index eab783a4..c4cbfe66 100644 --- a/app/views/devise/shared/_links.erb +++ b/app/views/devise/shared/_links.erb @@ -1,25 +1,3 @@ -<%- if controller_name != 'sessions' %> - <%= link_to "Sign in", new_session_path(resource_name) %>
-<% end -%> - -<%- if devise_mapping.registerable? && controller_name != 'registrations' %> - <%= link_to "Sign up", new_registration_path(resource_name) %>
-<% end -%> - -<%- if devise_mapping.recoverable? && controller_name != 'passwords' %> - <%= link_to "Forgot your password?", new_password_path(resource_name) %>
-<% end -%> - -<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> - <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
-<% end -%> - -<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> - <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
-<% end -%> - -<%- if devise_mapping.omniauthable? %> - <%- resource_class.omniauth_providers.each do |provider| %> - <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
- <% end -%> -<% end -%> \ No newline at end of file +<% ActiveSupport::Deprecation.warn "Rendering partials devise/shared/_links.erb is deprecated" \ + "please use devise/_links.erb instead." %> +<%= render "links" %> \ No newline at end of file diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb index c6cdcfe5..0dc79ac0 100644 --- a/app/views/devise/unlocks/new.html.erb +++ b/app/views/devise/unlocks/new.html.erb @@ -9,4 +9,4 @@
<%= f.submit "Resend unlock instructions" %>
<% end %> -<%= render :partial => "devise/shared/links" %> \ No newline at end of file +<%= render "links" %> \ No newline at end of file diff --git a/lib/generators/devise/views_generator.rb b/lib/generators/devise/views_generator.rb index 4d97aa51..bb39802d 100644 --- a/lib/generators/devise/views_generator.rb +++ b/lib/generators/devise/views_generator.rb @@ -32,17 +32,6 @@ module Devise end end - class SharedViewsGenerator < Rails::Generators::Base #:nodoc: - include ViewPathTemplates - source_root File.expand_path("../../../../app/views/devise", __FILE__) - desc "Copies shared Devise views to your application." - - # Override copy_views to just copy mailer and shared. - def copy_views - view_directory :shared - end - end - class FormForGenerator < Rails::Generators::Base #:nodoc: include ViewPathTemplates source_root File.expand_path("../../../../app/views/devise", __FILE__) @@ -80,12 +69,15 @@ module Devise end class ViewsGenerator < Rails::Generators::Base + include ViewPathTemplates + + source_root File.expand_path("../../../../app/views/devise", __FILE__) desc "Copies Devise views to your application." - argument :scope, :required => false, :default => nil, - :desc => "The scope to copy views to" + def copy_views + copy_file "_links.erb", "#{target_path}/_links.erb" + end - invoke SharedViewsGenerator hook_for :form_builder, :aliases => "-b", :desc => "Form builder to be used", :default => defined?(SimpleForm) ? "simple_form_for" : "form_for" diff --git a/lib/generators/templates/simple_form_for/confirmations/new.html.erb b/lib/generators/templates/simple_form_for/confirmations/new.html.erb index 9b0344e8..4c38fefd 100644 --- a/lib/generators/templates/simple_form_for/confirmations/new.html.erb +++ b/lib/generators/templates/simple_form_for/confirmations/new.html.erb @@ -12,4 +12,4 @@ <% end %> -<%= render :partial => "devise/shared/links" %> \ No newline at end of file +<%= render "links" %> \ No newline at end of file diff --git a/lib/generators/templates/simple_form_for/passwords/edit.html.erb b/lib/generators/templates/simple_form_for/passwords/edit.html.erb index be56ee41..80af5860 100644 --- a/lib/generators/templates/simple_form_for/passwords/edit.html.erb +++ b/lib/generators/templates/simple_form_for/passwords/edit.html.erb @@ -16,4 +16,4 @@ <% end %> -<%= render :partial => "devise/shared/links" %> \ No newline at end of file +<%= render "links" %> \ No newline at end of file diff --git a/lib/generators/templates/simple_form_for/passwords/new.html.erb b/lib/generators/templates/simple_form_for/passwords/new.html.erb index 56e2906f..01897508 100644 --- a/lib/generators/templates/simple_form_for/passwords/new.html.erb +++ b/lib/generators/templates/simple_form_for/passwords/new.html.erb @@ -12,4 +12,4 @@ <% end %> -<%= render :partial => "devise/shared/links" %> \ No newline at end of file +<%= render "links" %> \ No newline at end of file diff --git a/lib/generators/templates/simple_form_for/registrations/new.html.erb b/lib/generators/templates/simple_form_for/registrations/new.html.erb index 5f85c9ba..aece3e5b 100644 --- a/lib/generators/templates/simple_form_for/registrations/new.html.erb +++ b/lib/generators/templates/simple_form_for/registrations/new.html.erb @@ -14,4 +14,4 @@ <% end %> -<%= render :partial => "devise/shared/links" %> +<%= render "links" %> diff --git a/lib/generators/templates/simple_form_for/sessions/new.html.erb b/lib/generators/templates/simple_form_for/sessions/new.html.erb index e2eab4be..3c1e0d75 100644 --- a/lib/generators/templates/simple_form_for/sessions/new.html.erb +++ b/lib/generators/templates/simple_form_for/sessions/new.html.erb @@ -12,4 +12,4 @@ <% end %> -<%= render :partial => "devise/shared/links" %> \ No newline at end of file +<%= render "links" %> \ No newline at end of file diff --git a/lib/generators/templates/simple_form_for/unlocks/new.html.erb b/lib/generators/templates/simple_form_for/unlocks/new.html.erb index 89011af0..d717a763 100644 --- a/lib/generators/templates/simple_form_for/unlocks/new.html.erb +++ b/lib/generators/templates/simple_form_for/unlocks/new.html.erb @@ -12,4 +12,4 @@ <% end %> -<%= render :partial => "devise/shared/links" %> \ No newline at end of file +<%= render "links" %> \ No newline at end of file diff --git a/test/generators/views_generator_test.rb b/test/generators/views_generator_test.rb index 958bae62..8036a48a 100644 --- a/test/generators/views_generator_test.rb +++ b/test/generators/views_generator_test.rb @@ -46,7 +46,7 @@ class ViewsGeneratorTest < Rails::Generators::TestCase assert_file "app/views/#{scope}/registrations/new.html.erb" assert_file "app/views/#{scope}/registrations/edit.html.erb" assert_file "app/views/#{scope}/sessions/new.html.erb" - assert_file "app/views/#{scope}/shared/_links.erb" assert_file "app/views/#{scope}/unlocks/new.html.erb" + assert_file "app/views/#{scope}/_links.erb" end end