myrails 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ed7e61ea2b40e5a344c676140da8f60af448c8e
4
- data.tar.gz: d41681dca063a5c9b72fe9642754ce560725c440
3
+ metadata.gz: ed411978cf30a8e66c37d173a9ae0fe4561b98cf
4
+ data.tar.gz: 31fbf6c05b7cb4924d6f98395c06626618749ec6
5
5
  SHA512:
6
- metadata.gz: 5438539fcbd03f0d222086028234936d46c5e0be42d86a7f61a7688c9f91470794f569fc0a4d48d1d2ada1c4ef85f4484eac99000137055918b942a8b08b0e62
7
- data.tar.gz: 3185b829a2982195df217b380496851e2c15bd1d98bea77827fe807e395c60b17ba8202821e2893623de23ef7dc320842ecf3716139295332ef4e504cc59c8ee
6
+ metadata.gz: 7896e5d9acbeb096cf7308a64b60b42443e27bd611ba7d2ca6f74ea4f7c8aceffaf65600637e7e204ca78e282bddf89892d68064682c636e5caee4af949e0ef7
7
+ data.tar.gz: 641c334f61fe76fa4c520e848313fa73fcb5399b89b8c421d68e2cbf2e8435715dbafdd7817f9d2b6153515558f5a73ca57e7dceda6e24ce1991be056c81a102
@@ -0,0 +1,2 @@
1
+ DATABASE_USER=root
2
+ DATABASE_PASSWORD=somepassword
@@ -1,3 +1,3 @@
1
1
  module Myrails
2
- VERSION = "3.1.0"
2
+ VERSION = "3.2.0"
3
3
  end
data/lib/myrails.rb CHANGED
@@ -9,6 +9,332 @@ module Myrails
9
9
  TEMPLATES = source_root
10
10
  ENVIRONMENTS = %w(development test production)
11
11
 
12
+ no_tasks do
13
+ desc 'install_application_helper', 'Replace current application helper with one that has commonly used code'
14
+ def install_application_helper
15
+ copy_file 'rails/application_helper.rb', 'app/helpers/application_helper.rb'
16
+ end
17
+
18
+ desc 'install_gems', 'Add & Install gems that I commonly use'
19
+ def install_gems
20
+ insert_into_file 'Gemfile', before: "group :development, :test do" do <<-CODE
21
+ group :test do
22
+ gem 'simplecov'
23
+ gem 'shoulda-matchers'
24
+ gem 'factory_girl_rails'
25
+ gem 'database_cleaner'
26
+ gem 'chromedriver-helper'
27
+ gem 'launchy'
28
+ gem 'rails-controller-testing'
29
+ end
30
+ CODE
31
+ end
32
+
33
+ insert_into_file 'Gemfile', after: "group :development, :test do\n" do <<-CODE
34
+ gem 'faker'
35
+ gem 'yard'
36
+ gem 'letter_opener'
37
+ gem "rails-erd"
38
+ CODE
39
+ end
40
+
41
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
42
+ gem 'bootstrap-sass', '~> 3.3.1'
43
+ gem 'autoprefixer-rails'
44
+ gem 'haml-rails'
45
+ gem "ransack"
46
+ gem 'will_paginate'
47
+ gem "font-awesome-rails"
48
+ gem 'trix'
49
+ gem 'record_tag_helper'
50
+ CODE
51
+ end
52
+ run 'bundle install'
53
+
54
+ insert_into_file 'app/controllers/application_controller.rb', before: 'end' do <<-CODE
55
+ private
56
+ CODE
57
+ end
58
+ end
59
+
60
+ desc 'install_assets', 'Generate common asset pipeline files'
61
+ def install_assets
62
+ run "rm app/assets/stylesheets/application.css"
63
+ copy_file 'assets/application.css.sass', 'app/assets/stylesheets/application.css.sass'
64
+ copy_file 'assets/application.js', 'app/assets/javascripts/application.js'
65
+ copy_file 'assets/animate.scss', 'app/assets/stylesheets/animate.scss'
66
+ copy_file 'assets/will_paginate.scss', 'app/assets/stylesheets/will_paginate.scss'
67
+ end
68
+
69
+
70
+ desc 'install_css', 'Generate & include application css theme'
71
+ def install_css
72
+ themes = Dir[File.join(TEMPLATES, 'assets', 'bootstrap_themes', '*')]
73
+
74
+ themes.each_with_index do |theme, index|
75
+ say "[#{index}] #{File.basename(theme,'.*')}"
76
+ end
77
+
78
+ idx = ask("Choose a color theme (by number) for the application. Default: 'spacelab'")
79
+ idx = idx.empty? ? themes.index{|theme| theme if theme.include?('spacelab')} : idx.to_i
80
+ copy_file(themes[idx], "app/assets/stylesheets/#{File.basename(themes[idx])}")
81
+
82
+ inject_into_file 'app/assets/stylesheets/application.css.sass', before: "@import will_paginate" do <<-CODE
83
+ @import #{File.basename(themes[idx], '.*')}
84
+ CODE
85
+ end
86
+ end
87
+
88
+ desc 'install_footer', 'Generate & include application footer'
89
+ def install_footer
90
+ footers = Dir[File.join(TEMPLATES, 'layout', 'footers', '*.haml')]
91
+ footers_css = Dir[File.join(TEMPLATES, 'layout', 'footers', 'css', '*')]
92
+
93
+ footers.each_with_index do |footer, index|
94
+ say "[#{index}] #{File.basename(footer,'.html.*')}"
95
+ end
96
+
97
+ idx = ask("Chose a footer theme (by number) for the application. Deault: 'footer-distributed (Basic)'")
98
+ idx = idx.empty? ? footers.index{|footer| footer if footer.include?('footer-distributed.html.haml')} : idx.to_i
99
+ copy_file footers[idx], "app/views/layouts/_footer.html.haml"
100
+ copy_file footers_css[idx], "app/assets/stylesheets/#{File.basename(footers_css[idx])}"
101
+
102
+ inject_into_file 'app/assets/stylesheets/application.css.sass', after: "@import animate\n" do <<-CODE
103
+ @import #{File.basename(footers_css[idx], '.*')}
104
+ CODE
105
+ end
106
+ end
107
+
108
+ desc 'install_layout', 'Generate common layout files'
109
+ def install_layout
110
+ run 'rm app/views/layouts/application.html.erb'
111
+ template 'layout/application.html.haml', 'app/views/layouts/application.html.haml'
112
+ template 'layout/_nav.html.haml', 'app/views/layouts/_nav.html.haml'
113
+ copy_file 'layout/_info_messages.html.haml', 'app/views/layouts/_info_messages.html.haml'
114
+ copy_file 'layout/_success_message.html.haml', 'app/views/layouts/_success_message.html.haml'
115
+ copy_file 'layout/_error_messages.html.haml', 'app/views/layouts/_error_messages.html.haml'
116
+ copy_file 'layout/_footer.html.haml', 'app/views/layouts/_footer.html.haml'
117
+ insert_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do <<-CODE
118
+ add_flash_types :error, :success
119
+ CODE
120
+ end
121
+ end
122
+
123
+ desc 'install_heroku', 'setup application for use with heroku using sqlite3 for development'
124
+ def install_heroku
125
+ insert_into_file 'Gemfile', before: "group :development, :test do\n" do <<-CODE
126
+ group :production do
127
+ gem 'pg'
128
+ gem 'rails_12factor'
129
+ end
130
+
131
+ CODE
132
+ end
133
+ copy_file 'db/sqlite3_database.yml', 'config/database.yml'
134
+ copy_file 'heroku/Procfile', 'Procfile'
135
+ copy_file 'heroku/puma.rb', 'config/puma.rb'
136
+ end
137
+
138
+ desc 'git_init', "Initialize git with some files autormoatically ignored"
139
+ def git_init
140
+ run 'git init'
141
+ run 'echo /coverage >> .gitignore'
142
+ run 'echo /config/application.yml >> .gitignore'
143
+ run 'git add --all'
144
+ run "git commit -m 'initial commit'"
145
+ end
146
+
147
+ desc 'install_ui', 'Generate UI files and code for prototyping views in app/views/ui'
148
+ def install_ui
149
+ copy_file 'ui/ui_controller.rb', 'app/controllers/ui_controller.rb'
150
+ copy_file 'ui/index.html.haml', 'app/views/ui/index.html.haml'
151
+ inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<-CODE
152
+ # Requires an application restart everytime a new page is added.
153
+ Dir.glob('app/views/ui/*.html.haml').sort.each do |file|
154
+ action = File.basename(file,'.html.haml')
155
+ get \"ui/\#{action}\", controller: 'ui', action: action
156
+ end
157
+ CODE
158
+ end
159
+ end
160
+
161
+ desc 'install_rspec', 'Generate rspec structure & rspec configuration that I commonly use'
162
+ def install_rspec
163
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
164
+ gem 'rspec-rails', group: :test
165
+ CODE
166
+ end
167
+ run 'bundle install'
168
+ run 'rails g rspec:install'
169
+ install_rails_helper
170
+ copy_file 'rspec/database_cleaner.rb', "spec/support/configs/database_cleaner.rb"
171
+ copy_file 'rspec/factory_girl.rb', 'spec/support/configs/factory_girl.rb'
172
+ copy_file 'rspec/shoulda_matchers.rb', 'spec/support/configs/shoulda_matchers.rb'
173
+ copy_file 'rspec/silence_backtrace.rb', 'spec/support/configs/silence_rspec_backtrace.rb'
174
+ copy_file 'rspec/javascript.rb', 'spec/support/configs/javascript.rb'
175
+ copy_file 'rspec/mailer.rb', 'spec/support/configs/mailer.rb'
176
+ copy_file 'rspec/router.rb', 'spec/support/configs/router.rb'
177
+ copy_file 'rspec/files.rb', 'spec/support/configs/files.rb'
178
+ end
179
+
180
+ desc 'install_rails_helper', 'Add code to rspec/rails_helper so rspec runs the way I like'
181
+ def install_rails_helper
182
+ inject_into_file "spec/rails_helper.rb", after: "require 'rspec/rails'\n" do <<-CODE
183
+ require 'simplecov'
184
+ SimpleCov.start
185
+ #use Chromedriver
186
+ unless ENV['NOCHROME']
187
+ Capybara.register_driver :selenium do |app|
188
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
189
+ end
190
+ end
191
+ CODE
192
+ end
193
+
194
+ gsub_file 'spec/rails_helper.rb', "# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }", "Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }"
195
+
196
+ gsub_file "spec/rails_helper.rb", "config.use_transactional_fixtures = true", "config.use_transactional_fixtures = false"
197
+
198
+ inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
199
+ config.include(JavascriptHelper, type: :feature)
200
+ CODE
201
+ end
202
+ end
203
+
204
+ desc 'install_devise', 'Generate devise files'
205
+ def install_devise
206
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
207
+ gem 'devise', '~> 4.2.0'
208
+ CODE
209
+ end
210
+ run 'bundle update'
211
+ copy_file 'rspec/devise.rb', 'spec/support/configs/devise.rb'
212
+
213
+ devise_model = ask("What would you like to call the devise model? Default: user")
214
+ devise_model = devise_model.empty? ? 'user' : devise_model
215
+ run 'rails generate devise:install'
216
+ run 'rake db:migrate'
217
+ run "rails generate devise #{devise_model}"
218
+ run 'rails generate devise:views'
219
+
220
+ inject_into_file 'app/controllers/application_controller.rb', before: 'protect_from_forgery with: :exception' do <<-CODE
221
+ # Devise authentication method
222
+ before_action :authenticate_#{devise_model}!
223
+ CODE
224
+ end
225
+
226
+ if File.exist?('app/controllers/ui_controller.rb')
227
+ inject_into_file 'app/controllers/ui_controller.rb', after: "class UiController < ApplicationController\n" do <<-CODE
228
+ skip_before_action :authenticate_#{devise_model}!
229
+ CODE
230
+ end
231
+ end
232
+
233
+ if yes?('Will you be needing registration params override? Answer "yes" if you will be adding attributes to the user model')
234
+ inject_into_file 'app/controllers/application_controller.rb', after: "skip_before_action :authenticate_#{devise_model}!\n" do <<-CODE
235
+ # Before action include additional registration params
236
+ # (see #configure_permitted_parameters)
237
+ before_action :configure_permitted_parameters, if: :devise_controller?
238
+ CODE
239
+ end
240
+
241
+ inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
242
+ # Register additional registration params
243
+ def configure_permitted_parameters
244
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute, :attribute])
245
+ end
246
+ CODE
247
+ end
248
+ end
249
+ end
250
+
251
+ desc 'install_pundit', 'Install pundit gem and generate pundit files and application controller code'
252
+ def install_pundit
253
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
254
+ gem 'pundit'
255
+ CODE
256
+ end
257
+
258
+ insert_into_file 'Gemfile', after: "group :test do\n" do <<-CODE
259
+ gem 'pundit-matchers', '~> 1.1.0'
260
+ CODE
261
+ end
262
+
263
+ run 'bundle update'
264
+ run 'rails g pundit:install'
265
+
266
+ inject_into_file 'app/controllers/application_controller.rb', after: "protect_from_forgery with: :exception\n" do <<-CODE
267
+ # Add pundit authorization
268
+ include Pundit
269
+ CODE
270
+ end
271
+
272
+ inject_into_file 'app/controllers/application_controller.rb', after: "rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized\n" do <<-CODE
273
+ # Rescue from pundit error
274
+ # (see #user_not_authorized)
275
+ rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
276
+ CODE
277
+ end
278
+
279
+ inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
280
+ # Method to gracefully let a user know they are are not authorized
281
+ #
282
+ # @return flash [Hash] the action notice
283
+ def user_not_authorized
284
+ flash[:alert] = "You are not authorized to perform this action."
285
+ redirect_to home_path
286
+ end
287
+ CODE
288
+ end
289
+ end
290
+
291
+ desc 'install_footnotes', 'Install rails-footnotes and run its generator'
292
+ def install_footnotes
293
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
294
+ gem 'rails-footnotes'
295
+ CODE
296
+ end
297
+ run 'bundle install'
298
+ run 'rails generate rails_footnotes:install'
299
+ end
300
+
301
+ desc 'install_dotenv', 'Install dotenv gem'
302
+ def install_dotenv
303
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
304
+ gem 'dotenv-rails', groups: [:development, :test]
305
+ CODE
306
+ end
307
+
308
+ run 'bundle install'
309
+
310
+ inject_into_file 'config.ru', after: "require_relative 'config/environment'\n" do <<-CODE
311
+ require 'dotenv'
312
+ Dotenv.load
313
+ CODE
314
+ end
315
+ copy_file 'rails/env.config', '.env.development'
316
+ copy_file 'rails/env.config', '.env.test'
317
+ run 'touch .env.production'
318
+ end
319
+
320
+ desc 'base_install', 'Run the most common actions in the right order'
321
+ def base_install
322
+ install_gems
323
+ install_application_helper
324
+ install_assets
325
+ install_layout
326
+ install_css
327
+ install_footer
328
+ install_ui
329
+ install_pundit
330
+ install_rspec
331
+ install_footnotes
332
+ install_dotenv
333
+ git_init
334
+ say 'Dont forget to run config_env'
335
+ end
336
+ end
337
+
12
338
  desc 'model', "Generates a rails model with the given name along with its related spec file and namespace prefix for table creation. Use '/' to create a namespaced model"
13
339
  option :name, required: true
14
340
  def model
@@ -51,44 +377,6 @@ module Myrails
51
377
  template 'rspec/factory.rb', "spec/factories/#{options[:name].downcase}.rb"
52
378
  end
53
379
 
54
- desc 'install_application_helper', 'Replace current application helper with one that has commonly used code'
55
- def install_application_helper
56
- copy_file 'rails/application_helper.rb', 'app/helpers/application_helper.rb'
57
- end
58
-
59
- desc 'install_ui', 'Generate UI files and code for prototyping views in app/views/ui'
60
- def install_ui
61
- copy_file 'ui/ui_controller.rb', 'app/controllers/ui_controller.rb'
62
- copy_file 'ui/index.html.haml', 'app/views/ui/index.html.haml'
63
- inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<-CODE
64
- # Requires an application restart everytime a new page is added.
65
- Dir.glob('app/views/ui/*.html.haml').sort.each do |file|
66
- action = File.basename(file,'.html.haml')
67
- get \"ui/\#{action}\", controller: 'ui', action: action
68
- end
69
- CODE
70
- end
71
- end
72
-
73
- desc 'install_rspec', 'Generate rspec structure & rspec configuration that I commonly use'
74
- def install_rspec
75
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
76
- gem 'rspec-rails', group: :test
77
- CODE
78
- end
79
- run 'bundle install'
80
- run 'rails g rspec:install'
81
- install_rails_helper
82
- copy_file 'rspec/database_cleaner.rb', "spec/support/configs/database_cleaner.rb"
83
- copy_file 'rspec/factory_girl.rb', 'spec/support/configs/factory_girl.rb'
84
- copy_file 'rspec/shoulda_matchers.rb', 'spec/support/configs/shoulda_matchers.rb'
85
- copy_file 'rspec/silence_backtrace.rb', 'spec/support/configs/silence_rspec_backtrace.rb'
86
- copy_file 'rspec/javascript.rb', 'spec/support/configs/javascript.rb'
87
- copy_file 'rspec/mailer.rb', 'spec/support/configs/mailer.rb'
88
- copy_file 'rspec/router.rb', 'spec/support/configs/router.rb'
89
- copy_file 'rspec/files.rb', 'spec/support/configs/files.rb'
90
- end
91
-
92
380
  desc 'sendgrid', 'Generate sendgrid initializer and mail interceptor'
93
381
  option :email, required: true
94
382
  def sendgrid
@@ -138,260 +426,6 @@ gem 'rspec-rails', group: :test
138
426
  end
139
427
  end
140
428
 
141
- desc 'install_rails_helper', 'Add code to rspec/rails_helper so rspec runs the way I like'
142
- def install_rails_helper
143
- inject_into_file "spec/rails_helper.rb", after: "require 'rspec/rails'\n" do <<-CODE
144
- require 'simplecov'
145
- SimpleCov.start
146
- #use Chromedriver
147
- unless ENV['NOCHROME']
148
- Capybara.register_driver :selenium do |app|
149
- Capybara::Selenium::Driver.new(app, :browser => :chrome)
150
- end
151
- end
152
- CODE
153
- end
154
-
155
- gsub_file 'spec/rails_helper.rb', "# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }", "Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }"
156
-
157
- gsub_file "spec/rails_helper.rb", "config.use_transactional_fixtures = true", "config.use_transactional_fixtures = false"
158
-
159
- inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
160
- config.include(JavascriptHelper, type: :feature)
161
- CODE
162
- end
163
- end
164
-
165
- desc 'install_devise', 'Generate devise files'
166
- def install_devise
167
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
168
- gem 'devise', '~> 4.2.0'
169
- CODE
170
- end
171
- run 'bundle update'
172
- copy_file 'rspec/devise.rb', 'spec/support/configs/devise.rb'
173
-
174
- devise_model = ask("What would you like to call the devise model? Default: user")
175
- devise_model = devise_model.empty? ? 'user' : devise_model
176
- run 'rails generate devise:install'
177
- run 'rake db:migrate'
178
- run "rails generate devise #{devise_model}"
179
- run 'rails generate devise:views'
180
-
181
- inject_into_file 'app/controllers/application_controller.rb', before: 'protect_from_forgery with: :exception' do <<-CODE
182
- # Devise authentication method
183
- before_action :authenticate_#{devise_model}!
184
- CODE
185
- end
186
-
187
- if File.exist?('app/controllers/ui_controller.rb')
188
- inject_into_file 'app/controllers/ui_controller.rb', after: "class UiController < ApplicationController\n" do <<-CODE
189
- skip_before_action :authenticate_#{devise_model}!
190
- CODE
191
- end
192
- end
193
-
194
- if yes?('Will you be needing registration params override? Answer "yes" if you will be adding attributes to the user model')
195
- inject_into_file 'app/controllers/application_controller.rb', after: "skip_before_action :authenticate_#{devise_model}!\n" do <<-CODE
196
- # Before action include additional registration params
197
- # (see #configure_permitted_parameters)
198
- before_action :configure_permitted_parameters, if: :devise_controller?
199
- CODE
200
- end
201
-
202
- inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
203
- # Register additional registration params
204
- def configure_permitted_parameters
205
- devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute, :attribute])
206
- end
207
- CODE
208
- end
209
- end
210
- end
211
-
212
- desc 'install_pundit', 'Install pundit gem and generate pundit files and application controller code'
213
- def install_pundit
214
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
215
- gem 'pundit'
216
- CODE
217
- end
218
-
219
- insert_into_file 'Gemfile', before: "group :development, :test do" do <<-CODE
220
- gem 'pundit-matchers', '~> 1.1.0'
221
- CODE
222
- end
223
-
224
- run 'bundle update'
225
- run 'rails g pundit:install'
226
-
227
- inject_into_file 'app/controllers/application_controller.rb', after: "protect_from_forgery with: :exception\n" do <<-CODE
228
- # Add pundit authorization
229
- include Pundit
230
- CODE
231
- end
232
-
233
- inject_into_file 'app/controllers/application_controller.rb', after: "rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized\n" do <<-CODE
234
- # Rescue from pundit error
235
- # (see #user_not_authorized)
236
- rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
237
- CODE
238
- end
239
-
240
- inject_into_file 'app/controllers/application_controller.rb', after: "private\n" do <<-CODE
241
- # Method to gracefully let a user know they are are not authorized
242
- #
243
- # @return flash [Hash] the action notice
244
- def user_not_authorized
245
- flash[:alert] = "You are not authorized to perform this action."
246
- redirect_to home_path
247
- end
248
- CODE
249
- end
250
- end
251
-
252
- desc 'install_footnotes', 'Install rails-footnotes and run its generator'
253
- def install_footnotes
254
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
255
- gem 'rails-footnotes'
256
- CODE
257
- end
258
- run 'bundle install'
259
- run 'rails generate rails_footnotes:install'
260
- end
261
-
262
- desc 'install_gems', 'Add & Install gems that I commonly use'
263
- def install_gems
264
- insert_into_file 'Gemfile', before: "group :development, :test do" do <<-CODE
265
- group :test do
266
- gem 'simplecov'
267
- gem 'shoulda-matchers'
268
- gem 'factory_girl_rails'
269
- gem 'database_cleaner'
270
- gem 'capybara'
271
- gem 'selenium-webdriver'
272
- gem 'chromedriver-helper'
273
- gem 'launchy'
274
- gem 'rails-controller-testing'
275
- end
276
-
277
- CODE
278
- end
279
-
280
- insert_into_file 'Gemfile', after: "group :development, :test do\n" do <<-CODE
281
- gem 'faker'
282
- gem 'yard'
283
- gem 'letter_opener'
284
- gem "rails-erd"
285
- CODE
286
- end
287
-
288
- insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
289
- gem 'node'
290
- gem 'bootstrap-sass', '~> 3.3.1'
291
- gem 'autoprefixer-rails'
292
- gem 'haml-rails'
293
- gem "ransack"
294
- gem 'will_paginate'
295
- gem "font-awesome-rails"
296
- gem 'trix'
297
- gem 'record_tag_helper'
298
- CODE
299
- end
300
- run 'bundle install'
301
-
302
- insert_into_file 'app/controllers/application_controller.rb', before: 'end' do <<-CODE
303
- private
304
- CODE
305
- end
306
- end
307
-
308
- desc 'install_assets', 'Generate common asset pipeline files'
309
- def install_assets
310
- run "rm app/assets/stylesheets/application.css"
311
- copy_file 'assets/application.css.sass', 'app/assets/stylesheets/application.css.sass'
312
- copy_file 'assets/application.js', 'app/assets/javascripts/application.js'
313
- copy_file 'assets/animate.scss', 'app/assets/stylesheets/animate.scss'
314
- copy_file 'assets/will_paginate.scss', 'app/assets/stylesheets/will_paginate.scss'
315
- end
316
-
317
-
318
- desc 'install_css', 'Generate & include application css theme'
319
- def install_css
320
- themes = Dir[File.join(TEMPLATES, 'assets', 'bootstrap_themes', '*')]
321
-
322
- themes.each_with_index do |theme, index|
323
- say "[#{index}] #{File.basename(theme,'.*')}"
324
- end
325
-
326
- idx = ask("Choose a color theme (by number) for the application. Default: 'spacelab'")
327
- idx = idx.empty? ? themes.index{|theme| theme if theme.include?('spacelab')} : idx.to_i
328
- copy_file(themes[idx], "app/assets/stylesheets/#{File.basename(themes[idx])}")
329
-
330
- inject_into_file 'app/assets/stylesheets/application.css.sass', before: "@import will_paginate" do <<-CODE
331
- @import #{File.basename(themes[idx], '.*')}
332
- CODE
333
- end
334
- end
335
-
336
- desc 'install_footer', 'Generate & include application footer'
337
- def install_footer
338
- footers = Dir[File.join(TEMPLATES, 'layout', 'footers', '*.haml')]
339
- footers_css = Dir[File.join(TEMPLATES, 'layout', 'footers', 'css', '*')]
340
-
341
- footers.each_with_index do |footer, index|
342
- say "[#{index}] #{File.basename(footer,'.html.*')}"
343
- end
344
-
345
- idx = ask("Chose a footer theme (by number) for the application. Deault: 'footer-distributed (Basic)'")
346
- idx = idx.empty? ? footers.index{|footer| footer if footer.include?('footer-distributed.html.haml')} : idx.to_i
347
- copy_file footers[idx], "app/views/layouts/_footer.html.haml"
348
- copy_file footers_css[idx], "app/assets/stylesheets/#{File.basename(footers_css[idx])}"
349
-
350
- inject_into_file 'app/assets/stylesheets/application.css.sass', after: "@import animate\n" do <<-CODE
351
- @import #{File.basename(footers_css[idx], '.*')}
352
- CODE
353
- end
354
- end
355
-
356
- desc 'install_layout', 'Generate common layout files'
357
- def install_layout
358
- run 'rm app/views/layouts/application.html.erb'
359
- template 'layout/application.html.haml', 'app/views/layouts/application.html.haml'
360
- template 'layout/_nav.html.haml', 'app/views/layouts/_nav.html.haml'
361
- copy_file 'layout/_info_messages.html.haml', 'app/views/layouts/_info_messages.html.haml'
362
- copy_file 'layout/_success_message.html.haml', 'app/views/layouts/_success_message.html.haml'
363
- copy_file 'layout/_error_messages.html.haml', 'app/views/layouts/_error_messages.html.haml'
364
- copy_file 'layout/_footer.html.haml', 'app/views/layouts/_footer.html.haml'
365
- insert_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do <<-CODE
366
- add_flash_types :error, :success
367
- CODE
368
- end
369
- end
370
-
371
- desc 'install_heroku', 'setup application for use with heroku using sqlite3 for development'
372
- def install_heroku
373
- insert_into_file 'Gemfile', before: "group :development, :test do\n" do <<-CODE
374
- group :production do
375
- gem 'pg'
376
- gem 'rails_12factor'
377
- end
378
-
379
- CODE
380
- end
381
- copy_file 'db/sqlite3_database.yml', 'config/database.yml'
382
- copy_file 'heroku/Procfile', 'Procfile'
383
- copy_file 'heroku/puma.rb', 'config/puma.rb'
384
- end
385
-
386
- desc 'git_init', "Initialize git with some files autormoatically ignored"
387
- def git_init
388
- run 'git init'
389
- run 'echo /coverage >> .gitignore'
390
- run 'echo /config/application.yml >> .gitignore'
391
- run 'git add --all'
392
- run "git commit -m 'initial commit'"
393
- end
394
-
395
429
  desc 'mysql_switch', 'Switch to mysql database'
396
430
  def mysql_switch
397
431
  gsub_file 'Gemfile', "gem 'sqlite3'", "gem 'mysql2', '>= 0.3.13', '< 0.5'"
@@ -495,26 +529,71 @@ require 'database_cleaner'
495
529
  copy_file 'rspec/request_shared_example.rb', 'spec/support/request_shared_examples.rb'
496
530
  end
497
531
 
498
- desc 'auto_install', 'Run the most common actions in the right order'
499
- def base_install
500
- install_gems
501
- install_application_helper
502
- install_assets
503
- install_layout
504
- install_css
505
- install_footer
506
- install_ui
507
- install_pundit
508
- install_rspec
509
- install_footnotes
510
- git_init
511
- end
532
+ desc 'install NAME', 'Install gems and customized files. Type `myrails install` for options'
533
+ def install(name=nil)
534
+ options = {
535
+ application_helper: 'Overwrite default application helper with a custom helper',
536
+ gems: 'Install default gem set',
537
+ assets: 'Generate custom asset pipeline files',
538
+ layout: 'Generate custom layout',
539
+ styles: 'Generate custom styles',
540
+ footer: 'Generate a footer',
541
+ ui: 'Generate UI resource',
542
+ pundit: 'Install and configure Pundit gem',
543
+ rspec: 'Install and configure Rspec gem',
544
+ footnotes: 'Install and configure Footnotes gem',
545
+ base: 'Run through all options listed in this list',
546
+ git: 'Generate git directory and ignore default files',
547
+ heroku: 'Generate needed setup for Heroku deployment',
548
+ devise: 'Generate and configure Devise gem',
549
+ dotenv: 'Generate and configure Dotenv gem'
550
+ }
551
+ unless name
552
+ say 'ERROR: "myrails install" was called with no arguments'
553
+ say 'Usage: "myrails install NAME"'
554
+ say "Available Options:\n"
555
+ options.each{|k,v| say "* #{k}: #{v}"}
556
+ exit
557
+ end
512
558
 
513
- desc 'use_global_varables', 'creates and loads config/application.yml'
514
- def use_global_variables
515
- copy_file 'initializers/application_vars.rb', 'config/initializers/application_vars.rb'
516
- copy_file 'rails/application.yml', 'config/application.yml'
559
+ case name
560
+ when 'application_helper'
561
+ install_application_helper
562
+ when 'gems'
563
+ install_gems
564
+ when 'assets'
565
+ install_assets
566
+ when 'layout'
567
+ install_layout
568
+ when 'styles'
569
+ install_css
570
+ when 'footer'
571
+ install_footer
572
+ when 'ui'
573
+ install_ui
574
+ say 'Dont forget to run config_env'
575
+ when 'pundit'
576
+ install_pundit
577
+ install_rails_helper
578
+ when 'rspec'
579
+ install_rspec
580
+ when 'footnotes'
581
+ install_footnotes
582
+ when 'base'
583
+ base_install
584
+ when 'git'
585
+ git_init
586
+ when 'heroku'
587
+ install_heroku
588
+ when 'devise'
589
+ install_devise
590
+ when 'dotenv'
591
+ install_dotenv
592
+ else
593
+ say "Unknown Action!"
594
+ end
517
595
  end
596
+
518
597
  end
519
598
  end
520
599
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-05 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -146,6 +146,7 @@ files:
146
146
  - lib/myrails/templates/rails/application.yml
147
147
  - lib/myrails/templates/rails/application_helper.rb
148
148
  - lib/myrails/templates/rails/controller.rb
149
+ - lib/myrails/templates/rails/env.config
149
150
  - lib/myrails/templates/rails/model.rb
150
151
  - lib/myrails/templates/rails/namespace_controller.rb
151
152
  - lib/myrails/templates/rails/namespace_model.rb