rails_apps_composer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. data/README.textile +313 -0
  2. data/bin/rails_apps_composer +7 -0
  3. data/lib/rails_wizard.rb +10 -0
  4. data/lib/rails_wizard/command.rb +79 -0
  5. data/lib/rails_wizard/config.rb +86 -0
  6. data/lib/rails_wizard/recipe.rb +106 -0
  7. data/lib/rails_wizard/recipes.rb +38 -0
  8. data/lib/rails_wizard/template.rb +58 -0
  9. data/recipes/action_mailer.rb +41 -0
  10. data/recipes/activerecord.rb +37 -0
  11. data/recipes/add_user.rb +87 -0
  12. data/recipes/add_user_name.rb +74 -0
  13. data/recipes/application_layout.rb +45 -0
  14. data/recipes/ban_spiders.rb +27 -0
  15. data/recipes/capybara.rb +34 -0
  16. data/recipes/cleanup.rb +36 -0
  17. data/recipes/css_setup.rb +42 -0
  18. data/recipes/cucumber.rb +62 -0
  19. data/recipes/devise.rb +76 -0
  20. data/recipes/devise_navigation.rb +93 -0
  21. data/recipes/env_yaml.rb +54 -0
  22. data/recipes/git.rb +38 -0
  23. data/recipes/haml.rb +23 -0
  24. data/recipes/heroku.rb +58 -0
  25. data/recipes/home_page.rb +45 -0
  26. data/recipes/home_page_users.rb +47 -0
  27. data/recipes/hoptoad.rb +34 -0
  28. data/recipes/jammit.rb +43 -0
  29. data/recipes/jquery.rb +70 -0
  30. data/recipes/less.rb +12 -0
  31. data/recipes/mongo_mapper.rb +18 -0
  32. data/recipes/mongohq.rb +59 -0
  33. data/recipes/mongoid.rb +39 -0
  34. data/recipes/mootools.rb +23 -0
  35. data/recipes/navigation.rb +68 -0
  36. data/recipes/omniauth.rb +152 -0
  37. data/recipes/omniauth_email.rb +82 -0
  38. data/recipes/pow.rb +12 -0
  39. data/recipes/prototype.rb +11 -0
  40. data/recipes/rails_admin.rb +21 -0
  41. data/recipes/redis.rb +17 -0
  42. data/recipes/redistogo.rb +40 -0
  43. data/recipes/rightjs.rb +17 -0
  44. data/recipes/rspec.rb +112 -0
  45. data/recipes/sass.rb +13 -0
  46. data/recipes/seed_database.rb +42 -0
  47. data/recipes/sequel.rb +13 -0
  48. data/recipes/settingslogic.rb +43 -0
  49. data/recipes/slim.rb +11 -0
  50. data/recipes/test_unit.rb +11 -0
  51. data/recipes/users_page.rb +103 -0
  52. data/spec/rails_wizard/config_spec.rb +99 -0
  53. data/spec/rails_wizard/recipe_spec.rb +103 -0
  54. data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
  55. data/spec/rails_wizard/recipes_spec.rb +24 -0
  56. data/spec/rails_wizard/template_spec.rb +48 -0
  57. data/spec/spec_helper.rb +11 -0
  58. data/spec/support/rails_directory.rb +17 -0
  59. data/spec/support/template_runner.rb +28 -0
  60. data/templates/helpers.erb +45 -0
  61. data/templates/layout.erb +69 -0
  62. data/templates/recipe.erb +10 -0
  63. data/version.rb +3 -0
  64. metadata +206 -0
@@ -0,0 +1,39 @@
1
+ # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
+ # https://github.com/fortuity/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.3.0'
8
+ gem 'mongoid', '>= 2.0.1'
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: fortuity
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?
@@ -0,0 +1,23 @@
1
+ inside "public/javascripts" do
2
+ get "https://github.com/kevinvaldek/mootools-ujs/raw/master/Source/rails.js", "rails.js"
3
+ get "http://ajax.googleapis.com/ajax/libs/mootools/1.3.1/mootools-yui-compressed.js", "mootools.min.js"
4
+ end
5
+
6
+ gsub_file "config/application.rb", /# JavaScript.*\n/, ""
7
+ gsub_file "config/application.rb", /# config\.action_view\.javascript.*\n/, ""
8
+
9
+ application do
10
+ "\n config.action_view.javascript_expansions[:defaults] = %w(mootools.min rails)\n"
11
+ end
12
+
13
+ __END__
14
+
15
+ name: MooTools
16
+ description: "Adds MooTools and MooTools-compatible UJS helpers."
17
+ author: mbleigh
18
+
19
+ exclusive: javascript_framework
20
+ category: assets
21
+ tags: [javascript, framework]
22
+
23
+ args: ["-J"]
@@ -0,0 +1,68 @@
1
+ # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
+ # https://github.com/fortuity/rails_apps_composer/blob/master/recipes/navigation.rb
3
+
4
+ after_bundler do
5
+
6
+ say_wizard "Navigation recipe running 'after bundler'"
7
+
8
+ # Create navigation links
9
+ if recipes.include? 'haml'
10
+ # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
11
+ # We have to use single-quote-style-heredoc to avoid interpolation.
12
+ create_file "app/views/shared/_navigation.html.haml" do <<-'HAML'
13
+ - if user_signed_in?
14
+ %li
15
+ Logged in as #{current_user.name}
16
+ %li
17
+ = link_to('Logout', signout_path)
18
+ - else
19
+ %li
20
+ = link_to('Login', signin_path)
21
+ HAML
22
+ end
23
+ else
24
+ create_file "app/views/shared/_navigation.html.erb" do <<-ERB
25
+ <% if user_signed_in? %>
26
+ <li>
27
+ Logged in as <%= current_user.name %>
28
+ </li>
29
+ <li>
30
+ <%= link_to('Logout', signout_path) %>
31
+ </li>
32
+ <% else %>
33
+ <li>
34
+ <%= link_to('Login', signin_path) %>
35
+ </li>
36
+ <% end %>
37
+ ERB
38
+ end
39
+ end
40
+
41
+ # Add navigation links to the default application layout
42
+ if recipes.include? 'haml'
43
+ # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
44
+ inject_into_file 'app/views/layouts/application.html.haml', :after => "%body\n" do <<-HAML
45
+ %ul.hmenu
46
+ = render 'shared/navigation'
47
+ HAML
48
+ end
49
+ else
50
+ inject_into_file 'app/views/layouts/application.html.erb', :after => "<body>\n" do
51
+ <<-ERB
52
+ <ul class="hmenu">
53
+ <%= render 'shared/navigation' %>
54
+ </ul>
55
+ ERB
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ __END__
62
+
63
+ name: Navigation
64
+ description: "Add navigation links."
65
+ author: fortuity
66
+
67
+ category: other
68
+ tags: [utilities, configuration]
@@ -0,0 +1,152 @@
1
+ # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
+ # https://github.com/fortuity/rails_apps_composer/blob/master/recipes/omniauth.rb
3
+
4
+ if config['omniauth']
5
+ gem 'omniauth', '>= 0.2.4'
6
+ else
7
+ recipes.delete('omniauth')
8
+ end
9
+
10
+ if config['omniauth']
11
+ after_bundler do
12
+
13
+ # Don't use single-quote-style-heredoc: we want interpolation.
14
+ create_file 'config/initializers/omniauth.rb' do <<-RUBY
15
+ Rails.application.config.middleware.use OmniAuth::Builder do
16
+ provider :#{config['provider']}, 'KEY', 'SECRET'
17
+ end
18
+ RUBY
19
+ end
20
+
21
+ # add routes
22
+ route "match '/auth/failure' => 'sessions#failure'"
23
+ route "match '/signout' => 'sessions#destroy', :as => :signout"
24
+ route "match '/signin' => 'sessions#new', :as => :signin"
25
+ route "match '/auth/:provider/callback' => 'sessions#create'"
26
+ route "resources :users, :only => [ :show, :edit, :update ]"
27
+
28
+ # add a user model (unless another recipe did so already)
29
+ unless recipes.include? 'add_user'
30
+ generate(:model, "user provider:string uid:string name:string email:string")
31
+ gsub_file 'app/models/user.rb', /end/ do
32
+ <<-RUBY
33
+ attr_accessible :provider, :uid, :name, :email
34
+ end
35
+ RUBY
36
+ end
37
+ end
38
+
39
+ # modify the user model
40
+ inject_into_file 'app/models/user.rb', :before => 'end' do <<-RUBY
41
+
42
+ def self.create_with_omniauth(auth)
43
+ begin
44
+ create! do |user|
45
+ user.provider = auth['provider']
46
+ user.uid = auth['uid']
47
+ if auth['user_info']
48
+ user.name = auth['user_info']['name'] if auth['user_info']['name'] # Twitter, Google, Yahoo, GitHub
49
+ user.email = auth['user_info']['email'] if auth['user_info']['email'] # Google, Yahoo, GitHub
50
+ end
51
+ if auth['extra']['user_hash']
52
+ user.name = auth['extra']['user_hash']['name'] if auth['extra']['user_hash']['name'] # Facebook
53
+ user.email = auth['extra']['user_hash']['email'] if auth['extra']['user_hash']['email'] # Facebook
54
+ end
55
+ end
56
+ rescue Exception
57
+ raise Exception, "cannot create user record"
58
+ end
59
+ end
60
+
61
+ RUBY
62
+ end
63
+
64
+ # We have to use single-quote-style-heredoc to avoid interpolation.
65
+ create_file 'app/controllers/sessions_controller.rb' do <<-'RUBY'
66
+ class SessionsController < ApplicationController
67
+
68
+ def create
69
+ auth = request.env["omniauth.auth"]
70
+ user = User.where(:provider => auth['provider'],
71
+ :uid => auth['uid']).first || User.create_with_omniauth(auth)
72
+ session[:user_id] = user.id
73
+ redirect_to root_url, :notice => 'Signed in!'
74
+ end
75
+
76
+ def destroy
77
+ session[:user_id] = nil
78
+ redirect_to root_url, :notice => 'Signed out!'
79
+ end
80
+
81
+ def failure
82
+ redirect_to root_url, :alert => "Authentication error: #{params[:message].humanize}"
83
+ end
84
+
85
+ end
86
+ RUBY
87
+ end
88
+
89
+ # Don't use single-quote-style-heredoc: we want interpolation.
90
+ inject_into_class 'app/controllers/sessions_controller.rb', 'SessionsController' do <<-RUBY
91
+
92
+ def new
93
+ redirect_to '/auth/#{config['provider']}'
94
+ end
95
+
96
+ RUBY
97
+ end
98
+
99
+ inject_into_file 'app/controllers/application_controller.rb', :before => 'end' do <<-RUBY
100
+ helper_method :current_user
101
+ helper_method :user_signed_in?
102
+ helper_method :correct_user?
103
+
104
+ private
105
+ def current_user
106
+ begin
107
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
108
+ rescue Mongoid::Errors::DocumentNotFound
109
+ nil
110
+ end
111
+ end
112
+
113
+ def user_signed_in?
114
+ return true if current_user
115
+ end
116
+
117
+ def correct_user?
118
+ @user = User.find(params[:id])
119
+ unless current_user == @user
120
+ redirect_to root_url, :alert => "Access denied."
121
+ end
122
+ end
123
+
124
+ def authenticate_user!
125
+ if !current_user
126
+ redirect_to root_url, :alert => 'You need to sign in for access to this page.'
127
+ end
128
+ end
129
+
130
+ RUBY
131
+ end
132
+
133
+ end
134
+ end
135
+
136
+ __END__
137
+
138
+ name: OmniAuth
139
+ description: "Utilize OmniAuth for authentication."
140
+ author: fortuity
141
+
142
+ exclusive: authentication
143
+ category: authentication
144
+
145
+ config:
146
+ - omniauth:
147
+ type: boolean
148
+ prompt: Would you like to use OmniAuth for authentication?
149
+ - provider:
150
+ type: multiple_choice
151
+ prompt: "Which service provider will you use?"
152
+ choices: [["Twitter", twitter], ["Facebook", facebook], ["GitHub", github], ["LinkedIn", linked_in], ["Other", provider]]
@@ -0,0 +1,82 @@
1
+ # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
+ # https://github.com/fortuity/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
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: fortuity
80
+
81
+ category: other
82
+ tags: [utilities, configuration]
data/recipes/pow.rb ADDED
@@ -0,0 +1,12 @@
1
+ run "ln -s #{destination_root} ~/.pow/#{app_name}"
2
+ say_wizard "App is available at http://#{app_name}.dev/"
3
+
4
+ __END__
5
+
6
+ name: Pow
7
+ description: "Automatically create a symlink for Pow."
8
+ author: mbleigh
9
+
10
+ category: other
11
+ tags: [dev]
12
+
@@ -0,0 +1,11 @@
1
+ # No extra code required.
2
+
3
+ __END__
4
+
5
+ name: Prototype
6
+ description: "Use the default Javascript libraries and helpers."
7
+ author: mbleigh
8
+
9
+ exclusive: javascript_framework
10
+ category: assets
11
+ tags: [javascript, framework, defaults]
@@ -0,0 +1,21 @@
1
+ gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'
2
+
3
+ after_bundler do
4
+ generate 'rails_admin:install_admin'
5
+ rake 'admin:copy_assets'
6
+ rake 'admin:ckeditor_download' if config['ckeditor']
7
+ end
8
+
9
+ __END__
10
+
11
+ name: RailsAdmin
12
+ description: "Install RailsAdmin to manage data in your application"
13
+ author: alno
14
+
15
+ category: other
16
+
17
+ config:
18
+ - ckeditor:
19
+ type: boolean
20
+ prompt: Install CKEditor?
21
+
data/recipes/redis.rb ADDED
@@ -0,0 +1,17 @@
1
+ gem 'redis'
2
+
3
+ say_wizard "Generating Redis initializer..."
4
+
5
+ initializer "redis.rb", <<-RUBY
6
+ REDIS = Redis.new
7
+ RUBY
8
+
9
+ __END__
10
+
11
+ name: Redis
12
+ description: "Add Redis as a persistence engine to your application."
13
+ author: mbleigh
14
+
15
+ exclusive: key_value
16
+ category: persistence
17
+ tags: [key_value, cache, session_store]
@@ -0,0 +1,40 @@
1
+ prepend_file "config/initializers/redis.rb", <<-RUBY
2
+ uri = URI.parse(ENV['REDISTOGO_URL'])
3
+
4
+ RUBY
5
+
6
+ inject_into_file "config/initializers/redis.rb", :after => "Redis.new" do
7
+ "(:host => uri.host, :port => uri.port, :password => uri.password)"
8
+ end
9
+
10
+ env("REDISTOGO_URL", "redis://localhost:6379")
11
+
12
+ after_everything do
13
+ if config['use_heroku']
14
+ say_wizard "Adding redistogo:nano Heroku addon, you can always upgrade later."
15
+ run "heroku addons:add redistogo:nano"
16
+ else
17
+ env("REDISTOGO_URL", config['url'], 'production') if config['url']
18
+ end
19
+ end
20
+
21
+ __END__
22
+
23
+ name: RedisToGo
24
+ description: "Use RedisToGo hosting for this app's Redis."
25
+ author: mbleigh
26
+
27
+ requires: [redis, env_yaml]
28
+ run_after: [redis, env_yaml]
29
+ category: services
30
+
31
+ config:
32
+ - use_heroku:
33
+ type: boolean
34
+ prompt: "Use the RedisToGo Heroku addon?"
35
+ if_recipe: heroku
36
+ - url:
37
+ type: string
38
+ prompt: "Enter your RedisToGo URL:"
39
+ unless: use_heroku
40
+