forked from RailsApps/rails_apps_composer
/
home_page_users.rb
50 lines (41 loc) · 1.14 KB
/
home_page_users.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
# Application template recipe for the rails3_devise_wizard. Check for a newer version here:
# https://github.com/fortuity/rails3_devise_wizard/blob/master/recipes/home_page_users.rb
after_bundler do
if recipes.include? 'devise'
# Modify the home controller
gsub_file 'app/controllers/home_controller.rb', /def index/ do
<<-RUBY
def index
@users = User.all
RUBY
end
# Replace the home page
if recipes.include? 'haml'
remove_file 'app/views/home/index.html.haml'
# There is Haml code in this script. Changing the indentation is perilous between HAMLs.
# We have to use single-quote-style-heredoc to avoid interpolation.
create_file 'app/views/home/index.html.haml' do
<<-'HAML'
%h3 Home
- @users.each do |user|
%p User: #{user.name}
HAML
end
else
append_file 'app/views/home/index.html.erb' do <<-ERB
<h3>Home</h3>
<% @users.each do |user| %>
<p>User: <%= user.name %></p>
<% end %>
ERB
end
end
end
end
__END__
name: HomePageUsers
description: "Display a list of users on the home page."
author: fortuity
requires: [devise]
category: other
tags: [utilities, configuration]