thyone_creator 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/thyone +7 -0
- data/lib/rails_wizard/command.rb +116 -0
- data/lib/rails_wizard/config.rb +88 -0
- data/lib/rails_wizard/recipe.rb +106 -0
- data/lib/rails_wizard/recipes.rb +38 -0
- data/lib/rails_wizard/template.rb +73 -0
- data/lib/rails_wizard.rb +10 -0
- data/recipes/action_mailer.rb +123 -0
- data/recipes/active_admin.rb +44 -0
- data/recipes/activerecord.rb +37 -0
- data/recipes/add_user.rb +129 -0
- data/recipes/airbrake.rb +34 -0
- data/recipes/backbone.rb +23 -0
- data/recipes/capybara.rb +34 -0
- data/recipes/cleanup.rb +40 -0
- data/recipes/cloudfiles.rb +36 -0
- data/recipes/compass.rb +46 -0
- data/recipes/compass_960.rb +48 -0
- data/recipes/cucumber.rb +75 -0
- data/recipes/datamapper.rb +111 -0
- data/recipes/devise.rb +114 -0
- data/recipes/extras.rb +80 -0
- data/recipes/git.rb +40 -0
- data/recipes/guard.rb +99 -0
- data/recipes/haml.rb +23 -0
- data/recipes/heroku.rb +62 -0
- data/recipes/home_page.rb +58 -0
- data/recipes/home_page_users.rb +47 -0
- data/recipes/html5.rb +153 -0
- data/recipes/inherited_resources.rb +23 -0
- data/recipes/less.rb +12 -0
- data/recipes/mongohq.rb +59 -0
- data/recipes/mongoid.rb +39 -0
- data/recipes/mongolab.rb +59 -0
- data/recipes/omniauth.rb +192 -0
- data/recipes/omniauth_email.rb +82 -0
- data/recipes/paperclip.rb +79 -0
- data/recipes/rails_admin.rb +21 -0
- data/recipes/redis.rb +23 -0
- data/recipes/responders.rb +10 -0
- data/recipes/resque.rb +25 -0
- data/recipes/rspec.rb +133 -0
- data/recipes/sass.rb +25 -0
- data/recipes/seed_database.rb +76 -0
- data/recipes/settingslogic.rb +43 -0
- data/recipes/simple_form.rb +54 -0
- data/recipes/slim.rb +46 -0
- data/recipes/static_page.rb +43 -0
- data/recipes/subdomains.rb +121 -0
- data/recipes/users_page.rb +165 -0
- data/spec/rails_wizard/config_spec.rb +108 -0
- data/spec/rails_wizard/recipe_spec.rb +81 -0
- data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
- data/spec/rails_wizard/recipes_spec.rb +24 -0
- data/spec/rails_wizard/template_spec.rb +78 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/rails_directory.rb +17 -0
- data/spec/support/template_runner.rb +28 -0
- data/templates/helpers.erb +45 -0
- data/templates/layout.erb +83 -0
- data/templates/recipe.erb +10 -0
- data/version.rb +3 -0
- metadata +251 -0
data/recipes/html5.rb
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
# Application template recipe for the rails_apps_composer. Check for a newer version here:
|
2
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/html5.rb
|
3
|
+
|
4
|
+
case config['css_option']
|
5
|
+
|
6
|
+
when 'foundation'
|
7
|
+
# https://github.com/zurb/foundation-rails
|
8
|
+
gem 'zurb-foundation'
|
9
|
+
|
10
|
+
when 'bootstrap_less'
|
11
|
+
# https://github.com/seyhunak/twitter-bootstrap-rails
|
12
|
+
# http://railscasts.com/episodes/328-twitter-bootstrap-basics
|
13
|
+
gem 'twitter-bootstrap-rails', '>= 2.0.3', :group => :assets
|
14
|
+
# please install gem 'therubyracer' to use Less
|
15
|
+
gem 'therubyracer', :group => :assets, :platform => :ruby
|
16
|
+
recipes << 'bootstrap'
|
17
|
+
recipes << 'jsruntime'
|
18
|
+
|
19
|
+
when 'bootstrap_sass'
|
20
|
+
# https://github.com/thomas-mcdonald/bootstrap-sass
|
21
|
+
# http://rubysource.com/twitter-bootstrap-less-and-sass-understanding-your-options-for-rails-3-1/
|
22
|
+
gem 'bootstrap-sass', '>= 2.0.3'
|
23
|
+
recipes << 'bootstrap'
|
24
|
+
|
25
|
+
end
|
26
|
+
after_bundler do
|
27
|
+
say_wizard "HTML5 recipe running 'after bundler'"
|
28
|
+
# add a humans.txt file
|
29
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/humans.txt', 'public/humans.txt'
|
30
|
+
# install a front-end framework for HTML5 and CSS3
|
31
|
+
remove_file 'app/assets/stylesheets/application.css'
|
32
|
+
remove_file 'app/views/layouts/application.html.erb'
|
33
|
+
remove_file 'app/views/layouts/application.html.haml'
|
34
|
+
unless recipes.include? 'bootstrap'
|
35
|
+
if recipes.include? 'haml'
|
36
|
+
# Haml version of a simple application layout
|
37
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/simple/views/layouts/application.html.haml', 'app/views/layouts/application.html.haml'
|
38
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/simple/views/layouts/_messages.html.haml', 'app/views/layouts/_messages.html.haml'
|
39
|
+
else
|
40
|
+
# ERB version of a simple application layout
|
41
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/simple/views/layouts/application.html.erb', 'app/views/layouts/application.html.erb'
|
42
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/simple/views/layouts/_messages.html.erb', 'app/views/layouts/_messages.html.erb'
|
43
|
+
end
|
44
|
+
# simple css styles
|
45
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/simple/assets/stylesheets/application.css.scss', 'app/assets/stylesheets/application.css.scss'
|
46
|
+
else # for Twitter Bootstrap
|
47
|
+
if recipes.include? 'haml'
|
48
|
+
# Haml version of a complex application layout using Twitter Bootstrap
|
49
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/twitter-bootstrap/views/layouts/application.html.haml', 'app/views/layouts/application.html.haml'
|
50
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/twitter-bootstrap/views/layouts/_messages.html.haml', 'app/views/layouts/_messages.html.haml'
|
51
|
+
else
|
52
|
+
# ERB version of a complex application layout using Twitter Bootstrap
|
53
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/twitter-bootstrap/views/layouts/application.html.erb', 'app/views/layouts/application.html.erb'
|
54
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/twitter-bootstrap/views/layouts/_messages.html.erb', 'app/views/layouts/_messages.html.erb'
|
55
|
+
end
|
56
|
+
# complex css styles using Twitter Bootstrap
|
57
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/twitter-bootstrap/assets/stylesheets/application.css.scss', 'app/assets/stylesheets/application.css.scss'
|
58
|
+
end
|
59
|
+
# get an appropriate navigation partial
|
60
|
+
if recipes.include? 'haml'
|
61
|
+
if recipes.include? 'devise'
|
62
|
+
if recipes.include? 'authorization'
|
63
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/devise/authorization/_navigation.html.haml', 'app/views/layouts/_navigation.html.haml'
|
64
|
+
else
|
65
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/devise/_navigation.html.haml', 'app/views/layouts/_navigation.html.haml'
|
66
|
+
end
|
67
|
+
elsif recipes.include? 'omniauth'
|
68
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/omniauth/_navigation.html.haml', 'app/views/layouts/_navigation.html.haml'
|
69
|
+
elsif recipes.include? 'subdomains'
|
70
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/subdomains/_navigation.html.haml', 'app/views/layouts/_navigation.html.haml'
|
71
|
+
else
|
72
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/none/_navigation.html.haml', 'app/views/layouts/_navigation.html.haml'
|
73
|
+
end
|
74
|
+
else
|
75
|
+
if recipes.include? 'devise'
|
76
|
+
if recipes.include? 'authorization'
|
77
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/devise/authorization/_navigation.html.erb', 'app/views/layouts/_navigation.html.erb'
|
78
|
+
else
|
79
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/devise/_navigation.html.erb', 'app/views/layouts/_navigation.html.erb'
|
80
|
+
end
|
81
|
+
elsif recipes.include? 'omniauth'
|
82
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/omniauth/_navigation.html.erb', 'app/views/layouts/_navigation.html.erb'
|
83
|
+
elsif recipes.include? 'subdomains'
|
84
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/subdomains/_navigation.html.erb', 'app/views/layouts/_navigation.html.erb'
|
85
|
+
else
|
86
|
+
get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/none/_navigation.html.erb', 'app/views/layouts/_navigation.html.erb'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
if recipes.include? 'haml'
|
90
|
+
gsub_file 'app/views/layouts/application.html.haml', /App_Name/, "#{app_name.humanize.titleize}"
|
91
|
+
gsub_file 'app/views/layouts/_navigation.html.haml', /App_Name/, "#{app_name.humanize.titleize}"
|
92
|
+
else
|
93
|
+
gsub_file 'app/views/layouts/application.html.erb', /App_Name/, "#{app_name.humanize.titleize}"
|
94
|
+
gsub_file 'app/views/layouts/_navigation.html.erb', /App_Name/, "#{app_name.humanize.titleize}"
|
95
|
+
end
|
96
|
+
case config['css_option']
|
97
|
+
|
98
|
+
when 'bootstrap_less'
|
99
|
+
say_wizard 'installing Twitter Bootstrap HTML5 framework (less)'
|
100
|
+
generate 'bootstrap:install'
|
101
|
+
remove_file 'app/assets/stylesheets/application.css' # already created application.css.scss above
|
102
|
+
insert_into_file 'app/assets/stylesheets/bootstrap_and_overrides.css.less', "body { padding-top: 60px; }\n", :after => "@import \"twitter/bootstrap/bootstrap\";\n"
|
103
|
+
|
104
|
+
when 'bootstrap_sass'
|
105
|
+
say_wizard 'installing Twitter Bootstrap HTML5 framework (sass)'
|
106
|
+
insert_into_file 'app/assets/javascripts/application.js', "//= require bootstrap\n", :after => "jquery_ujs\n"
|
107
|
+
create_file 'app/assets/stylesheets/bootstrap_and_overrides.css.scss', <<-RUBY
|
108
|
+
// Set the correct sprite paths
|
109
|
+
$iconSpritePath: asset-url('glyphicons-halflings.png', image);
|
110
|
+
$iconWhiteSpritePath: asset-url('glyphicons-halflings-white.png', image);
|
111
|
+
@import "bootstrap";
|
112
|
+
body { padding-top: 60px; }
|
113
|
+
@import "bootstrap-responsive";
|
114
|
+
RUBY
|
115
|
+
|
116
|
+
when 'foundation'
|
117
|
+
say_wizard 'installing Zurb Foundation HTML5 framework'
|
118
|
+
insert_into_file 'app/assets/javascripts/application.js', "//= require foundation\n", :after => "jquery_ujs\n"
|
119
|
+
insert_into_file 'app/assets/stylesheets/application.css.scss', " *= require foundation\n", :after => "require_self\n"
|
120
|
+
|
121
|
+
when 'skeleton'
|
122
|
+
say_wizard 'installing Skeleton HTML5 framework'
|
123
|
+
get 'https://raw.github.com/necolas/normalize.css/master/normalize.css', 'app/assets/stylesheets/normalize.css.scss'
|
124
|
+
get 'https://raw.github.com/dhgamache/Skeleton/master/stylesheets/base.css', 'app/assets/stylesheets/base.css.scss'
|
125
|
+
get 'https://raw.github.com/dhgamache/Skeleton/master/stylesheets/layout.css', 'app/assets/stylesheets/layout.css.scss'
|
126
|
+
get 'https://raw.github.com/dhgamache/Skeleton/master/stylesheets/skeleton.css', 'app/assets/stylesheets/skeleton.css.scss'
|
127
|
+
get 'https://raw.github.com/dhgamache/Skeleton/master/javascripts/tabs.js', 'app/assets/javascripts/tabs.js'
|
128
|
+
|
129
|
+
when 'normalize'
|
130
|
+
say_wizard 'normalizing CSS for consistent styling'
|
131
|
+
get 'https://raw.github.com/necolas/normalize.css/master/normalize.css', 'app/assets/stylesheets/normalize.css.scss'
|
132
|
+
|
133
|
+
when 'nothing'
|
134
|
+
say_wizard 'no HTML5 front-end framework selected'
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
__END__
|
141
|
+
|
142
|
+
name: html5
|
143
|
+
description: "Install a front-end framework for HTML5 and CSS."
|
144
|
+
author: RailsApps
|
145
|
+
|
146
|
+
category: other
|
147
|
+
tags: [utilities, configuration]
|
148
|
+
|
149
|
+
config:
|
150
|
+
- css_option:
|
151
|
+
type: multiple_choice
|
152
|
+
prompt: "Which front-end framework would you like for HTML5 and CSS?"
|
153
|
+
choices: [["None", nothing], ["Zurb Foundation", foundation], ["Twitter Bootstrap (less)", bootstrap_less], ["Twitter Bootstrap (sass)", bootstrap_sass], ["Skeleton", skeleton], ["Just normalize CSS for consistent styling", normalize]]
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Application template recipe for the rails_apps_composer. Check for a newer version here:
|
2
|
+
# https://github.com/gmgp/rails_apps_composer/blob/master/recipes/inherited_resources.rb
|
3
|
+
|
4
|
+
if config['inherited_resources']
|
5
|
+
gem 'inherited_resources'
|
6
|
+
else
|
7
|
+
recipes.delete('inherited_resources')
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
__END__
|
12
|
+
|
13
|
+
name: InheritedResources
|
14
|
+
description: "Include inherited_resources "
|
15
|
+
author: Gmgp
|
16
|
+
|
17
|
+
category: other
|
18
|
+
tags: [utilities, configuration]
|
19
|
+
|
20
|
+
config:
|
21
|
+
- inherited_resources:
|
22
|
+
type: boolean
|
23
|
+
prompt: Would you like to use 'inherited_resources'?
|
data/recipes/less.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
gem 'less'
|
2
|
+
plugin 'more', :git => 'git://github.com/cloudhead/more.git'
|
3
|
+
|
4
|
+
__END__
|
5
|
+
|
6
|
+
name: Less CSS
|
7
|
+
description: "Utilize Less CSS for CSS generation utilizing the \"more\" plugin for Rails."
|
8
|
+
author: mbleigh
|
9
|
+
|
10
|
+
exclusive: css_replacement
|
11
|
+
category: assets
|
12
|
+
tags: [css]
|
data/recipes/mongohq.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
if config['use_heroku']
|
2
|
+
|
3
|
+
header = <<-YAML
|
4
|
+
<% if ENV['MONGOHQ_URL'] %>
|
5
|
+
<% mongohq = URI.parse(ENV['MONGOHQ_URL']) %>
|
6
|
+
mongohq:
|
7
|
+
host: <%= mongohq.host %>
|
8
|
+
port: <%= mongohq.port %>
|
9
|
+
database: <%= mongohq.path.sub '/', '' %>
|
10
|
+
username: <%= mongohq.user %>
|
11
|
+
password: <%= mongohq.password %>
|
12
|
+
<% end %>
|
13
|
+
YAML
|
14
|
+
|
15
|
+
after_everything do
|
16
|
+
say_wizard 'Adding mongohq:free addon (you can always upgrade later)'
|
17
|
+
system 'heroku addons:add mongohq:free'
|
18
|
+
end
|
19
|
+
else
|
20
|
+
mongohq = URI.parse(config['uri'])
|
21
|
+
|
22
|
+
header = <<-YAML
|
23
|
+
mongohq:
|
24
|
+
host: #{mongohq.host}
|
25
|
+
port: #{mongohq.port}
|
26
|
+
database: #{mongohq.path.sub '/',''}
|
27
|
+
username: #{mongohq.user}
|
28
|
+
password: #{mongohq.password}
|
29
|
+
YAML
|
30
|
+
end
|
31
|
+
|
32
|
+
after_bundler do
|
33
|
+
mongo_yml = "config/mongo#{'id' if recipe?('mongoid')}.yml"
|
34
|
+
|
35
|
+
prepend_file mongo_yml, header
|
36
|
+
inject_into_file mongo_yml, " <<: *mongohq\n", :after => "production:\n <<: *defaults\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
__END__
|
40
|
+
|
41
|
+
name: MongoHQ
|
42
|
+
description: "Utilize MongoHQ as the production data host for your application."
|
43
|
+
author: mbleigh
|
44
|
+
|
45
|
+
requires_any: [mongo_mapper, mongoid]
|
46
|
+
run_after: [mongo_mapper, mongoid, heroku]
|
47
|
+
exclusive: mongodb_host
|
48
|
+
category: services
|
49
|
+
tags: [mongodb]
|
50
|
+
|
51
|
+
config:
|
52
|
+
- use_heroku:
|
53
|
+
type: boolean
|
54
|
+
prompt: "Use the MongoHQ Heroku addon?"
|
55
|
+
if_recipe: heroku
|
56
|
+
- uri:
|
57
|
+
type: string
|
58
|
+
prompt: "Enter your MongoHQ URI:"
|
59
|
+
unless: use_heroku
|
data/recipes/mongoid.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Application template recipe for the rails_apps_composer. Check for a newer version here:
|
2
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/mongoid.rb
|
3
|
+
|
4
|
+
if config['mongoid']
|
5
|
+
say_wizard "REMINDER: When creating a Rails app using Mongoid..."
|
6
|
+
say_wizard "you should add the '-O' flag to 'rails new'"
|
7
|
+
gem 'bson_ext', '>= 1.6.2'
|
8
|
+
gem 'mongoid', '>= 2.4.10'
|
9
|
+
else
|
10
|
+
recipes.delete('mongoid')
|
11
|
+
end
|
12
|
+
|
13
|
+
if config['mongoid']
|
14
|
+
after_bundler do
|
15
|
+
say_wizard "Mongoid recipe running 'after bundler'"
|
16
|
+
# note: the mongoid generator automatically modifies the config/application.rb file
|
17
|
+
# to remove the ActiveRecord dependency by commenting out "require active_record/railtie'"
|
18
|
+
generate 'mongoid:config'
|
19
|
+
# remove the unnecessary 'config/database.yml' file
|
20
|
+
remove_file 'config/database.yml'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
__END__
|
25
|
+
|
26
|
+
name: Mongoid
|
27
|
+
description: "Use Mongoid to connect to a MongoDB database."
|
28
|
+
author: RailsApps
|
29
|
+
|
30
|
+
category: persistence
|
31
|
+
exclusive: orm
|
32
|
+
tags: [orm, mongodb]
|
33
|
+
|
34
|
+
args: ["-O"]
|
35
|
+
|
36
|
+
config:
|
37
|
+
- mongoid:
|
38
|
+
type: boolean
|
39
|
+
prompt: Would you like to use Mongoid to connect to a MongoDB database?
|
data/recipes/mongolab.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
if config['use_heroku']
|
2
|
+
|
3
|
+
header = <<-YAML
|
4
|
+
<% if ENV['MONGOLAB_URI'] %>
|
5
|
+
<% mongolab = URI.parse(ENV['MONGOLAB_URI']) %>
|
6
|
+
mongolab:
|
7
|
+
host: <%= mongolab.host %>
|
8
|
+
port: <%= mongolab.port %>
|
9
|
+
database: <%= mongolab.path.sub '/', '' %>
|
10
|
+
username: <%= mongolab.user %>
|
11
|
+
password: <%= mongolab.password %>
|
12
|
+
<% end %>
|
13
|
+
YAML
|
14
|
+
|
15
|
+
after_everything do
|
16
|
+
say_wizard 'Adding mongolab:starter addon (you can always upgrade later)'
|
17
|
+
system 'heroku addons:add mongolab:starter'
|
18
|
+
end
|
19
|
+
else
|
20
|
+
mongolab = URI.parse(config['uri'])
|
21
|
+
|
22
|
+
header = <<-YAML
|
23
|
+
mongolab:
|
24
|
+
host: #{mongolab.host}
|
25
|
+
port: #{mongolab.port}
|
26
|
+
database: #{mongolab.path.sub '/',''}
|
27
|
+
username: #{mongolab.user}
|
28
|
+
password: #{mongolab.password}
|
29
|
+
YAML
|
30
|
+
end
|
31
|
+
|
32
|
+
after_bundler do
|
33
|
+
mongo_yml = "config/mongo#{'id' if recipe?('mongoid')}.yml"
|
34
|
+
|
35
|
+
prepend_file mongo_yml, header
|
36
|
+
inject_into_file mongo_yml, " <<: *mongolab\n", :after => "production:\n <<: *defaults\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
__END__
|
40
|
+
|
41
|
+
name: mongolab (based on mongohq recipe)
|
42
|
+
description: "Utilize mongolab as the production data host for your application."
|
43
|
+
author: l4u (based on mongohq recipe by mbleigh)
|
44
|
+
|
45
|
+
requires_any: [mongo_mapper, mongoid]
|
46
|
+
run_after: [mongo_mapper, mongoid, heroku]
|
47
|
+
exclusive: mongodb_host
|
48
|
+
category: services
|
49
|
+
tags: [mongodb]
|
50
|
+
|
51
|
+
config:
|
52
|
+
- use_heroku:
|
53
|
+
type: boolean
|
54
|
+
prompt: "Use the MongoLab Heroku addon?"
|
55
|
+
if_recipe: heroku
|
56
|
+
- uri:
|
57
|
+
type: string
|
58
|
+
prompt: "Enter your MongoLab URI:"
|
59
|
+
unless: use_heroku
|
data/recipes/omniauth.rb
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
# Application template recipe for the rails_apps_composer. Check for a newer version here:
|
2
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/omniauth.rb
|
3
|
+
|
4
|
+
if config['omniauth']
|
5
|
+
gem 'omniauth', '>= 1.1.0'
|
6
|
+
# for available gems, see https://github.com/intridea/omniauth/wiki/List-of-Strategies
|
7
|
+
case config['provider']
|
8
|
+
when 'twitter'
|
9
|
+
gem 'omniauth-twitter'
|
10
|
+
when 'facebook'
|
11
|
+
gem 'omniauth-facebook'
|
12
|
+
when 'github'
|
13
|
+
gem 'omniauth-github'
|
14
|
+
when 'linkedin'
|
15
|
+
gem 'omniauth-linkedin'
|
16
|
+
when 'google'
|
17
|
+
gem 'omniauth-google'
|
18
|
+
when 'tumblr'
|
19
|
+
gem 'omniauth-tumblr'
|
20
|
+
end
|
21
|
+
else
|
22
|
+
recipes.delete('omniauth')
|
23
|
+
end
|
24
|
+
|
25
|
+
if config['omniauth']
|
26
|
+
after_bundler do
|
27
|
+
|
28
|
+
say_wizard "OmniAuth recipe running 'after bundler'"
|
29
|
+
|
30
|
+
# Don't use single-quote-style-heredoc: we want interpolation.
|
31
|
+
create_file 'config/initializers/omniauth.rb' do <<-RUBY
|
32
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
33
|
+
provider :#{config['provider']}, 'KEY', 'SECRET'
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
end
|
37
|
+
|
38
|
+
# add routes
|
39
|
+
route "match '/auth/failure' => 'sessions#failure'"
|
40
|
+
route "match '/signout' => 'sessions#destroy', :as => :signout"
|
41
|
+
route "match '/signin' => 'sessions#new', :as => :signin"
|
42
|
+
route "match '/auth/:provider/callback' => 'sessions#create'"
|
43
|
+
route "resources :users, :only => [ :show, :edit, :update ]"
|
44
|
+
|
45
|
+
# add a user model (unless another recipe did so already)
|
46
|
+
unless recipes.include? 'add_user'
|
47
|
+
generate(:model, "user provider:string uid:string name:string email:string")
|
48
|
+
gsub_file 'app/models/user.rb', /end/ do
|
49
|
+
<<-RUBY
|
50
|
+
attr_accessible :provider, :uid, :name, :email
|
51
|
+
end
|
52
|
+
RUBY
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# modify the user model
|
57
|
+
inject_into_file 'app/models/user.rb', :before => 'end' do <<-RUBY
|
58
|
+
|
59
|
+
def self.create_with_omniauth(auth)
|
60
|
+
create! do |user|
|
61
|
+
user.provider = auth['provider']
|
62
|
+
user.uid = auth['uid']
|
63
|
+
if auth['info']
|
64
|
+
user.name = auth['info']['name'] || ""
|
65
|
+
user.email = auth['info']['email'] || ""
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
RUBY
|
71
|
+
end
|
72
|
+
|
73
|
+
# We have to use single-quote-style-heredoc to avoid interpolation.
|
74
|
+
create_file 'app/controllers/sessions_controller.rb' do <<-'RUBY'
|
75
|
+
class SessionsController < ApplicationController
|
76
|
+
|
77
|
+
def create
|
78
|
+
auth = request.env["omniauth.auth"]
|
79
|
+
user = User.where(:provider => auth['provider'],
|
80
|
+
:uid => auth['uid']).first || User.create_with_omniauth(auth)
|
81
|
+
session[:user_id] = user.id
|
82
|
+
redirect_to root_url, :notice => 'Signed in!'
|
83
|
+
end
|
84
|
+
|
85
|
+
def destroy
|
86
|
+
reset_session
|
87
|
+
redirect_to root_url, :notice => 'Signed out!'
|
88
|
+
end
|
89
|
+
|
90
|
+
def failure
|
91
|
+
redirect_to root_url, :alert => "Authentication error: #{params[:message].humanize}"
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
RUBY
|
96
|
+
end
|
97
|
+
|
98
|
+
# Don't use single-quote-style-heredoc: we want interpolation.
|
99
|
+
inject_into_class 'app/controllers/sessions_controller.rb', 'SessionsController' do <<-RUBY
|
100
|
+
|
101
|
+
def new
|
102
|
+
redirect_to '/auth/#{config['provider']}'
|
103
|
+
end
|
104
|
+
|
105
|
+
RUBY
|
106
|
+
end
|
107
|
+
|
108
|
+
inject_into_file 'app/controllers/application_controller.rb', :before => 'end' do <<-RUBY
|
109
|
+
helper_method :current_user
|
110
|
+
helper_method :user_signed_in?
|
111
|
+
helper_method :correct_user?
|
112
|
+
|
113
|
+
private
|
114
|
+
def current_user
|
115
|
+
begin
|
116
|
+
@current_user ||= User.find(session[:user_id]) if session[:user_id]
|
117
|
+
rescue Mongoid::Errors::DocumentNotFound
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def user_signed_in?
|
123
|
+
return true if current_user
|
124
|
+
end
|
125
|
+
|
126
|
+
def correct_user?
|
127
|
+
@user = User.find(params[:id])
|
128
|
+
unless current_user == @user
|
129
|
+
redirect_to root_url, :alert => "Access denied."
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def authenticate_user!
|
134
|
+
if !current_user
|
135
|
+
redirect_to root_url, :alert => 'You need to sign in for access to this page.'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
RUBY
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
after_everything do
|
145
|
+
|
146
|
+
say_wizard "OmniAuth recipe running 'after everything'"
|
147
|
+
|
148
|
+
if recipes.include? 'rspec'
|
149
|
+
say_wizard "Copying RSpec files from the rails3-mongoid-omniauth examples"
|
150
|
+
begin
|
151
|
+
# copy all the RSpec specs files from the rails3-mongoid-omniauth example app
|
152
|
+
# spec_helper
|
153
|
+
remove_file 'spec/spec_helper.rb'
|
154
|
+
get 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/spec/spec_helper.rb', 'spec/spec_helper.rb'
|
155
|
+
# factories
|
156
|
+
remove_file 'spec/factories/users.rb'
|
157
|
+
get 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/spec/factories/users.rb', 'spec/factories/users.rb'
|
158
|
+
# controllers
|
159
|
+
get 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/spec/controllers/sessions_controller_spec.rb', 'spec/controllers/sessions_controller_spec.rb'
|
160
|
+
remove_file 'spec/controllers/home_controller_spec.rb'
|
161
|
+
remove_file 'spec/controllers/users_controller_spec.rb'
|
162
|
+
get 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/spec/controllers/home_controller_spec.rb', 'spec/controllers/home_controller_spec.rb'
|
163
|
+
get 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/spec/controllers/users_controller_spec.rb', 'spec/controllers/users_controller_spec.rb'
|
164
|
+
# models
|
165
|
+
remove_file 'spec/models/user_spec.rb'
|
166
|
+
get 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/spec/models/user_spec.rb', 'spec/models/user_spec.rb'
|
167
|
+
rescue OpenURI::HTTPError
|
168
|
+
say_wizard "Unable to obtain RSpec example files from the repo"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
__END__
|
177
|
+
|
178
|
+
name: OmniAuth
|
179
|
+
description: "Utilize OmniAuth for authentication."
|
180
|
+
author: RailsApps
|
181
|
+
|
182
|
+
exclusive: authentication
|
183
|
+
category: authentication
|
184
|
+
|
185
|
+
config:
|
186
|
+
- omniauth:
|
187
|
+
type: boolean
|
188
|
+
prompt: Would you like to use OmniAuth for authentication?
|
189
|
+
- provider:
|
190
|
+
type: multiple_choice
|
191
|
+
prompt: "Which service provider will you use?"
|
192
|
+
choices: [["Twitter", twitter], ["Facebook", facebook], ["GitHub", github], ["LinkedIn", linkedin], ["Google", google], ["Tumblr", tumblr]]
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Application template recipe for the rails_apps_composer. Check for a newer version here:
|
2
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/omniauth_email.rb
|
3
|
+
|
4
|
+
after_bundler do
|
5
|
+
|
6
|
+
say_wizard "OmniAuthEmail recipe running 'after bundler'"
|
7
|
+
|
8
|
+
#----------------------------------------------------------------------------
|
9
|
+
# Modify a users controller
|
10
|
+
#----------------------------------------------------------------------------
|
11
|
+
inject_into_file 'app/controllers/users_controller.rb', :after => "before_filter :authenticate_user!\n" do <<-RUBY
|
12
|
+
before_filter :correct_user?
|
13
|
+
RUBY
|
14
|
+
end
|
15
|
+
|
16
|
+
inject_into_file 'app/controllers/users_controller.rb', :before => 'def show' do <<-RUBY
|
17
|
+
def edit
|
18
|
+
@user = User.find(params[:id])
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
@user = User.find(params[:id])
|
23
|
+
if @user.update_attributes(params[:user])
|
24
|
+
redirect_to @user
|
25
|
+
else
|
26
|
+
render :edit
|
27
|
+
end
|
28
|
+
end
|
29
|
+
\n
|
30
|
+
RUBY
|
31
|
+
end
|
32
|
+
|
33
|
+
#----------------------------------------------------------------------------
|
34
|
+
# Create a users edit page
|
35
|
+
#----------------------------------------------------------------------------
|
36
|
+
if recipes.include? 'haml'
|
37
|
+
remove_file 'app/views/users/edit.html.haml'
|
38
|
+
# There is Haml code in this script. Changing the indentation is perilous between HAMLs.
|
39
|
+
# We have to use single-quote-style-heredoc to avoid interpolation.
|
40
|
+
create_file 'app/views/users/edit.html.haml' do <<-'HAML'
|
41
|
+
= form_for(@user) do |f|
|
42
|
+
= f.label :email
|
43
|
+
= f.text_field :email
|
44
|
+
%br/
|
45
|
+
= f.submit "Sign in"
|
46
|
+
HAML
|
47
|
+
end
|
48
|
+
else
|
49
|
+
create_file 'app/views/users/edit.html.erb' do <<-ERB
|
50
|
+
<%= form_for(@user) do |f| %>
|
51
|
+
<%= f.label :email %>
|
52
|
+
<%= f.text_field :email %>
|
53
|
+
<br />
|
54
|
+
<%= f.submit "Sign in" %>
|
55
|
+
<% end %>
|
56
|
+
ERB
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
#----------------------------------------------------------------------------
|
61
|
+
# Modify a Sessions controller
|
62
|
+
#----------------------------------------------------------------------------
|
63
|
+
gsub_file 'app/controllers/sessions_controller.rb', /redirect_to root_url, :notice => 'Signed in!'/ do
|
64
|
+
<<-RUBY
|
65
|
+
if user.email.blank?
|
66
|
+
redirect_to edit_user_path(user), :alert => "Please enter your email address."
|
67
|
+
else
|
68
|
+
redirect_to root_url, :notice => 'Signed in!'
|
69
|
+
end
|
70
|
+
RUBY
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
__END__
|
76
|
+
|
77
|
+
name: OmniAuthEmail
|
78
|
+
description: "Request a user's email address for an OmniAuth example app."
|
79
|
+
author: RailsApps
|
80
|
+
|
81
|
+
category: other
|
82
|
+
tags: [utilities, configuration]
|