-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevise_navigation.rb
96 lines (85 loc) · 2.62 KB
/
devise_navigation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# >--------------------------------[ devise_navigation ]--------------------------------<
# Application template recipe. Check for a newer version here:
# https://github.com/fortuity/rails-template-recipes/blob/master/devise_navigation.rb
# There is Haml code in this script. Changing the indentation is perilous between HAMLs.
say_recipe 'Devise Navigation'
after_bundler do
if extra_recipes.include? 'devise'
#----------------------------------------------------------------------------
# Create navigation links for Devise
#----------------------------------------------------------------------------
if recipe_list.include? 'haml'
create_file "app/views/devise/menu/_login_items.html.haml" do <<-'HAML'
- if user_signed_in?
%li
= link_to('Logout', destroy_user_session_path)
- else
%li
= link_to('Login', new_user_session_path)
HAML
end
else
create_file "app/views/devise/menu/_login_items.html.erb" do <<-ERB
<% if user_signed_in? %>
<li>
<%= link_to('Logout', destroy_user_session_path) %>
</li>
<% else %>
<li>
<%= link_to('Login', new_user_session_path) %>
</li>
<% end %>
ERB
end
end
if recipe_list.include? 'haml'
create_file "app/views/devise/menu/_registration_items.html.haml" do <<-'HAML'
- if user_signed_in?
%li
= link_to('Edit account', edit_user_registration_path)
- else
%li
= link_to('Sign up', new_user_registration_path)
HAML
end
else
create_file "app/views/devise/menu/_registration_items.html.erb" do <<-ERB
<% if user_signed_in? %>
<li>
<%= link_to('Edit account', edit_user_registration_path) %>
</li>
<% else %>
<li>
<%= link_to('Sign up', new_user_registration_path) %>
</li>
<% end %>
ERB
end
end
#----------------------------------------------------------------------------
# Add navigation links to the default application layout
#----------------------------------------------------------------------------
if recipe_list.include? 'haml'
inject_into_file 'app/views/layouts/application.html.haml', :after => "%body\n" do <<-HAML
%ul.hmenu
= render 'devise/menu/registration_items'
= render 'devise/menu/login_items'
HAML
end
else
inject_into_file 'app/views/layouts/application.html.erb', :after => "<body>\n" do
<<-ERB
<ul class="hmenu">
<%= render 'devise/menu/registration_items' %>
<%= render 'devise/menu/login_items' %>
</ul>
ERB
end
end
if extra_recipes.include? 'git'
git :tag => "devise_navlinks"
git :add => '.'
git :commit => "-am 'Add navigation links for Devise.'"
end
end
end