rails_baseline 0.1.9 → 0.2.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6873b896a27ee7dfc6ac3e7fc7733a45111277cf
4
- data.tar.gz: 7df87df30949aa5de5e255fd8483f1898340af36
3
+ metadata.gz: c3d86b901aabc84fc45ea951418d0f24628f659b
4
+ data.tar.gz: 7770ad54d1fe1dc95759cb3076d9c02d9b3cc730
5
5
  SHA512:
6
- metadata.gz: c383327500f9e2e03a59f7924feab65c94f149d69dbcd532e79db2e86129f13df993a0e36301536accb01518d68c5a47d10e27ca48f2484442dbb5284d560ddb
7
- data.tar.gz: 545749ff5b2d67c69410766bb9e9e97347418822f9de77f2233f1335a4b9dd40a84d10911151a572f5fd5f6ad694b9456bb756d2b9d3e1cdd807830d3964fa9b
6
+ metadata.gz: e704d004f2efc5467fe93826f358a0a226f3291f33669b8209ca92791726c1f305ca9203897288b7f48e55a2a58e00251adbc8a604e885daadbac6b341c4e8db
7
+ data.tar.gz: 2c2e6f7406997eb40befd6375afd00e1c6f08219c6a44696082750b74237fb780ad90a8d614c3f180d0e9ed198c1d2b1d5bd76bda2d8fa92c655b2ef5f386179
data/README.md CHANGED
@@ -1,7 +1,3 @@
1
- ## !!Under Active Development
2
-
3
- This gem is still under active development.
4
-
5
1
  # Rails 4 Baseline
6
2
  [![Gem Version](https://badge.fury.io/rb/rails_baseline.svg)](http://badge.fury.io/rb/rails_baseline)
7
3
 
@@ -55,14 +51,16 @@ and run migration for the pending migration files:
55
51
  3. 0.1.2 - Added Paranoia, Better Errors, Hirb and jQuery DataTables
56
52
  4. 0.1.3 - Added Quiet Assets, Decent Exposure, Paperclip, State Machines, Delayed Job and Kaminari
57
53
  5. 0.1.7 - Various fixes, and generate a static home page
54
+ 6. 0.2.9 - Modularize code base, removed several gems
58
55
 
59
56
  ## Contributing
60
57
 
61
58
  1. Fork it ( https://github.com/cloudcodermy/baseline/fork )
62
59
  2. Create your feature branch (`git checkout -b my-new-feature`)
63
- 3. Commit your changes (`git commit -am 'Add some feature'`)
64
- 4. Push to the branch (`git push origin my-new-feature`)
65
- 5. Create a new Pull Request
60
+ 3. Test codebase by `running bin/rails_baseline new <project_name>` to make sure it runs properly
61
+ 4. Commit your changes (`git commit -am 'Add some feature'`) without committing test rails apps
62
+ 5. Push to the branch (`git push origin my-new-feature`)
63
+ 6. Create a new Pull Request
66
64
 
67
65
  ## License
68
66
 
@@ -0,0 +1,50 @@
1
+ def recipes
2
+ @recipes
3
+ end
4
+
5
+ def recipe?(name)
6
+ @recipes.include?(name)
7
+ end
8
+
9
+ def say_custom(tag, text)
10
+ say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}"
11
+ end
12
+
13
+ def say_recipe(name)
14
+ say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..."
15
+ end
16
+
17
+ def say_wizard(text)
18
+ say_custom(@current_recipe || 'wizard', text)
19
+ end
20
+
21
+ def ask_wizard(question)
22
+ ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
23
+ end
24
+
25
+ def yes_wizard?(question)
26
+ answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
27
+ case answer.downcase
28
+ when "yes", "y"
29
+ true
30
+ when "no", "n"
31
+ false
32
+ else
33
+ yes_wizard?(question)
34
+ end
35
+ end
36
+
37
+ def no_wizard?(question)
38
+ !yes_wizard?(question)
39
+ end
40
+
41
+ def multiple_choice(question, choices)
42
+ say_custom('question', question)
43
+ values = {}
44
+ choices.each_with_index do |choice,i|
45
+ values[(i + 1).to_s] = choice[1]
46
+ say_custom (i + 1).to_s + ')', choice[0]
47
+ end
48
+ answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
49
+ values[answer]
50
+ end
@@ -0,0 +1,708 @@
1
+ # >----------------------------[ Initial Setup ]------------------------------<
2
+
3
+ # @recipes = ["database", "mongoid", "devise", "activeadmin", "git", "sass"]
4
+ @database_choice = nil
5
+
6
+ def recipes; @recipes end
7
+ def recipe?(name); @recipes.include?(name) end
8
+
9
+ def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
10
+ def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
11
+ def say_wizard(text); say_custom(@current_recipe || 'wizard', text) end
12
+
13
+ def ask_wizard(question)
14
+ ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
15
+ end
16
+
17
+ def yes_wizard?(question)
18
+ answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
19
+ case answer.downcase
20
+ when "yes", "y"
21
+ true
22
+ when "no", "n"
23
+ false
24
+ else
25
+ yes_wizard?(question)
26
+ end
27
+ end
28
+
29
+ def no_wizard?(question); !yes_wizard?(question) end
30
+
31
+ def multiple_choice(question, choices)
32
+ say_custom('question', question)
33
+ values = {}
34
+ choices.each_with_index do |choice,i|
35
+ values[(i + 1).to_s] = choice[1]
36
+ say_custom (i + 1).to_s + ')', choice[0]
37
+ end
38
+ answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
39
+ values[answer]
40
+ end
41
+
42
+ @current_recipe = nil
43
+ @configs = {}
44
+
45
+ @after_blocks = []
46
+ def after_bundler(&block); @after_blocks << [@current_recipe, block]; end
47
+ @after_everything_blocks = []
48
+ def after_everything(&block); @after_everything_blocks << [@current_recipe, block]; end
49
+ @before_configs = {}
50
+ def before_config(&block); @before_configs[@current_recipe] = block; end
51
+
52
+ # >-----------------------[ Deflator and Autoloads ]--------------------------<
53
+ @current_recipe = "deflator"
54
+
55
+ insertion_text = <<-TEXT
56
+ \n
57
+ config.middleware.use Rack::Deflater
58
+ TEXT
59
+
60
+ inject_into_file "config/application.rb", insertion_text, :after => "# config.i18n.default_locale = :de"
61
+
62
+ # >--------------------------------[ Email Settings ]---------------------------------<
63
+ @current_recipe = "smtp"
64
+
65
+ email_configuration_text = <<-TEXT
66
+ \n
67
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
68
+
69
+ config.action_mailer.delivery_method = :smtp
70
+ config.action_mailer.smtp_settings = {
71
+ :enable_starttls_auto => true,
72
+ :address => "smtp.mandrillapp.com",
73
+ :port => 587,
74
+ :domain => 'YOUR_DOMAIN',
75
+ :user_name => "USERNAME",
76
+ :password => "PASSWORD",
77
+ :authentication => :plain
78
+ }
79
+ TEXT
80
+
81
+ after_bundler do
82
+ inject_into_file 'config/environments/development.rb', email_configuration_text, :after => "config.assets.debug = true"
83
+ inject_into_file 'config/environments/production.rb', email_configuration_text, :after => "config.active_support.deprecation = :notify"
84
+ say_wizard "------------------------ EMAIL SETTINGS --------------------------"
85
+ say_wizard "| Please change your email settings in development.rb |"
86
+ say_wizard "| and production.rb |"
87
+ say_wizard "------------------------------------------------------------------"
88
+ end
89
+
90
+ # >--------------------------------[ Rails Config ]---------------------------------<
91
+
92
+ @current_recipe = "rails_config"
93
+ @before_configs["rails_config"].call if @before_configs["rails_config"]
94
+ say_recipe 'Rails Config'
95
+
96
+ gem 'rails_config', '0.5.0.beta1'
97
+
98
+ after_bundler do
99
+ generate 'rails_config:install'
100
+ end
101
+
102
+ # >--------------------------------[ Quiet Assets ]---------------------------------<
103
+
104
+ @current_recipe = "quiet_assets"
105
+ @before_configs["quiet_assets"].call if @before_configs["quiet_assets"]
106
+ say_recipe 'Quiet Assets'
107
+
108
+ gem 'quiet_assets', group: :development
109
+
110
+ # >--------------------------------[ RSpec ]---------------------------------<
111
+ @current_recipe = "rspec"
112
+ @before_configs["rspec"].call if @before_configs["rspec"]
113
+ say_recipe 'RSpec'
114
+
115
+ gem_group :development do
116
+ gem 'spring-commands-rspec'
117
+ gem 'rails_apps_testing'
118
+ end
119
+
120
+ gem_group :development, :test do
121
+ gem "rspec-rails"
122
+ gem 'factory_girl_rails'
123
+ gem 'faker'
124
+ end
125
+
126
+ gem_group :test do
127
+ gem 'capybara'
128
+ gem 'database_cleaner'
129
+ gem 'launchy'
130
+ gem 'selenium-webdriver'
131
+ end
132
+
133
+ rspec_text = <<-TEXT
134
+ \n
135
+ config.generators do |g|
136
+ g.test_framework :rspec,
137
+ fixtures: true,
138
+ view_specs: false,
139
+ helper_specs: false,
140
+ routing_specs: false,
141
+ controller_specs: true,
142
+ request_specs: false
143
+ g.fixture_replacement :factory_girl, dir: "spec/factories"
144
+ end
145
+ TEXT
146
+
147
+ after_bundler do
148
+ run 'bundle binstubs rspec-core'
149
+ generate 'rspec:install'
150
+ remove_dir 'test'
151
+
152
+ inject_into_file "config/application.rb", rspec_text, :after => "# config.i18n.default_locale = :de"
153
+ end
154
+
155
+ # >---------------------------[ ActiveRecord/Mongoid ]----------------------------<
156
+
157
+ @current_recipe = "database"
158
+ @before_configs["activerecord"].call if @before_configs["activerecord"]
159
+ say_recipe 'Database'
160
+
161
+ database_option = "activerecord"
162
+
163
+ config = {}
164
+ config['database'] = multiple_choice("Which database are you using?", [["MongoDB", "mongoid"], ["MySQL", "mysql"], ["PostgreSQL", "postgresql"], ["SQLite", "sqlite3"]]) if true && true unless config.key?('database')
165
+ database_option = config['database']
166
+ @configs[@current_recipe] = config
167
+
168
+
169
+ if config['database']
170
+ say_wizard "Configuring '#{config['database']}' database settings..."
171
+ @options = @options.dup.merge(:database => config['database'])
172
+ say_recipe "Currently selected as #{database_option}"
173
+ if database_option != "mongoid"
174
+ config['auto_create'] = yes_wizard?("Automatically create database with default configuration?") if true && true unless config.key?('auto_create')
175
+ gem gem_for_database
176
+ template "config/databases/#{@options[:database]}.yml", "config/database.yml.new"
177
+ run 'mv config/database.yml.new config/database.yml'
178
+ else
179
+ database_option = "mongoid"
180
+ gem 'mongoid', '~> 4.0.0'
181
+ end
182
+ end
183
+
184
+ after_bundler do
185
+ if database_option == "activerecord"
186
+ rake "db:create" if config['auto_create']
187
+ elsif database_option == "mongoid"
188
+ generate 'mongoid:config'
189
+ end
190
+ end
191
+
192
+ # >--------------------------------[ Devise ]---------------------------------<
193
+
194
+ @current_recipe = "devise"
195
+ @before_configs["devise"].call if @before_configs["devise"]
196
+ say_recipe 'Devise'
197
+
198
+ gem 'devise'
199
+
200
+ after_bundler do
201
+ generate 'devise:install'
202
+ end
203
+
204
+ if yes_wizard?("Generate Devise model?")
205
+ model_name = ask_wizard("Enter the model name for Devise. Leave it blank to default as User.")
206
+ after_bundler do
207
+ if model_name.present?
208
+ generate "devise #{model_name}"
209
+ else
210
+ generate "devise user"
211
+ end
212
+ end
213
+ end
214
+
215
+ # >--------------------------------[ Active Admin ]---------------------------------<
216
+
217
+ # Disable activeadmin for mongoid at the moment
218
+ if config['database'] != "mongoid"
219
+ @current_recipe = "activeadmin"
220
+ @before_configs["activeadmin"].call if @before_configs["activeadmin"]
221
+ say_recipe 'Active Admin'
222
+
223
+ gem 'activeadmin', github: 'activeadmin'
224
+
225
+ if yes_wizard?("Active Admin with Users?(no to skip users)")
226
+ model_name = ask_wizard("Enter the model name of ActiveAdmin. Leave it blank to default as AdminUser.")
227
+ after_bundler do
228
+ if model_name.present?
229
+ generate "active_admin:install #{model_name}"
230
+ else
231
+ generate "active_admin:install"
232
+ end
233
+ end
234
+ else
235
+ after_bundler do
236
+ generate "active_admin:install --skip-users"
237
+ end
238
+ end
239
+ end
240
+
241
+ # >--------------------------------[ CanCanCan ]---------------------------------<
242
+
243
+ @current_recipe = "cancancan"
244
+ @before_configs["cancancan"].call if @before_configs["cancancan"]
245
+ say_recipe 'CanCanCan'
246
+
247
+ gem 'cancancan', '~> 1.10'
248
+
249
+ after_bundler do
250
+ generate "cancan:ability"
251
+ end
252
+
253
+ # >-----------------------------[ Decent Exposure ]------------------------------<
254
+
255
+ @current_recipe = "decent_exposure"
256
+ @before_configs["decent_exposure"].call if @before_configs["decent_exposure"]
257
+ say_recipe 'Decent Exposure'
258
+
259
+ gem 'decent_exposure', '~> 2.3.2'
260
+
261
+ decent_exposure_strong_parameters = <<-TEXT
262
+ \n
263
+ decent_configuration do
264
+ strategy DecentExposure::StrongParametersStrategy
265
+ end
266
+ TEXT
267
+
268
+ after_bundler do
269
+ inject_into_file "app/controllers/application_controller.rb", decent_exposure_strong_parameters, :after => "protect_from_forgery with: :exception"
270
+ end
271
+
272
+ # >--------------------------------[ Paperclip ]---------------------------------<
273
+
274
+ @current_recipe = "paperclip"
275
+ @before_configs["paperclip"].call if @before_configs["paperclip"]
276
+ say_recipe 'Paperclip'
277
+
278
+ if config['database'] == "mongoid"
279
+ gem "mongoid-paperclip", :require => "mongoid_paperclip"
280
+ gem 'aws-sdk', '~> 1.3.4'
281
+ else
282
+ gem "paperclip", "~> 4.2"
283
+ end
284
+
285
+ # >--------------------------------[ State Machines ]---------------------------------<
286
+
287
+ @current_recipe = "state_machines"
288
+ @before_configs["state_machines"].call if @before_configs["state_machines"]
289
+ say_recipe 'State Machines'
290
+
291
+ if config['database'] == "mongoid"
292
+ gem 'state_machines-mongoid'
293
+ else
294
+ gem 'state_machines-activerecord'
295
+ end
296
+
297
+ # >--------------------------------[ Delayed Job ]---------------------------------<
298
+
299
+ @current_recipe = "delayed_job"
300
+ @before_configs["delayed_job"].call if @before_configs["delayed_job"]
301
+ say_recipe 'Delayed Job'
302
+
303
+ if config['database'] == "mongoid"
304
+ gem 'delayed_job_mongoid'
305
+ else
306
+ gem 'delayed_job_active_record'
307
+ after_bundler do
308
+ generate "delayed_job:active_record"
309
+ end
310
+ end
311
+
312
+ delayed_job_config = <<-TEXT
313
+ \n
314
+ config.active_job.queue_adapter = :delayed_job
315
+ TEXT
316
+
317
+ after_bundler do
318
+ inject_into_file "config/application.rb", delayed_job_config, :after => "# config.i18n.default_locale = :de"
319
+ end
320
+ # >---------------------------[ Application Views ]------------------------------<
321
+ @current_recipe = "application"
322
+ @before_configs["application"].call if @before_configs["application"]
323
+ say_recipe 'Application Views'
324
+
325
+ application_html_file = <<-TEXT
326
+ <!DOCTYPE html>
327
+ <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
328
+ <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
329
+ <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
330
+ <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
331
+ <html>
332
+ <head>
333
+ <meta charset="utf-8">
334
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
335
+ <meta name="viewport" content="width=device-width, initial-scale=1">
336
+ <title>Title</title>
337
+ <meta name="description" content="This is the description">
338
+ <meta content="width=device-width, initial-scale=1.0" name="viewport">
339
+
340
+ <meta property="og:title" content="Title" />
341
+ <meta property="og:type" content="article" />
342
+ <meta property="og:url" content="<%= root_url %>" />
343
+ <meta property="og:image" content="<%= root_url %>/logo.png" />
344
+ <meta property="og:description" content="This is the description" />
345
+
346
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
347
+ <%= csrf_meta_tags %>
348
+ <!--[if lt IE 9]>
349
+ <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
350
+ <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
351
+ <![endif]-->
352
+ </head>
353
+ <body>
354
+ <!--[if lt IE 7]>
355
+ <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
356
+ <![endif]-->
357
+ <!-- Google Tag Manager -->
358
+ <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
359
+ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
360
+ <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
361
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
362
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
363
+ '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
364
+ })(window,document,'script','dataLayer','GTM-XXXXXX');</script>
365
+ <!-- End Google Tag Manager -->
366
+
367
+ <%= yield %>
368
+
369
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
370
+ </body>
371
+ </html>
372
+ TEXT
373
+
374
+ after_bundler do
375
+ remove_file 'app/views/layouts/application.html.erb'
376
+ create_file 'app/views/layouts/application.html.erb', application_html_file
377
+ say_wizard "--------------------------- APPLICATION VIEWS -----------------------------"
378
+ say_wizard "|Please change your GTM, title and meta settings in application.html.erb. |"
379
+ say_wizard "---------------------------------------------------------------------------"
380
+ end
381
+
382
+ # >--------------------------------[ Paranoia ]-----------------------------------<
383
+
384
+ @current_recipe = "paranoia"
385
+ @before_configs["paranoia"].call if @before_configs["paranoia"]
386
+ say_recipe 'Paranoia'
387
+
388
+ if config['database'] != "mongoid"
389
+ gem "paranoia", "~> 2.0"
390
+ else
391
+ gem 'mongoid_paranoia', '~> 0.1.2'
392
+ end
393
+
394
+ # >------------------------[ Better Errors and Hirb ]-----------------------------<
395
+
396
+ @current_recipe = "better_errors"
397
+ @before_configs["better_errors"].call if @before_configs["better_errors"]
398
+ say_recipe 'Better Errors and Hirb'
399
+
400
+ gem_group :development do
401
+ gem "better_errors"
402
+ gem "hirb"
403
+ end
404
+
405
+ # >-------------------------------[ Setup SASS ]----------------------------------<
406
+
407
+ @current_recipe = "sass"
408
+ @before_configs["sass"].call if @before_configs["sass"]
409
+ say_recipe 'SASS'
410
+
411
+ after_bundler do
412
+ copy_file 'app/assets/stylesheets/application.css', 'app/assets/stylesheets/application.css.scss'
413
+ remove_file 'app/assets/stylesheets/application.css'
414
+ end
415
+
416
+ # >--------------------------------[ Bootstrap ]---------------------------------<
417
+
418
+ @current_recipe = "bootstrap"
419
+ @before_configs["bootstrap"].call if @before_configs["bootstrap"]
420
+ say_recipe 'Bootstrap Front End'
421
+
422
+ config_lines = <<-TEXT
423
+ @import "bootstrap-sprockets";
424
+ @import "bootstrap";
425
+ TEXT
426
+
427
+ flash_message = <<-TEXT
428
+ <% flash.each do |name, msg| %>
429
+ <%
430
+ code = "warning"
431
+ desc = "Oh!"
432
+ case name.to_s
433
+ when "notice"
434
+ code = "success"
435
+ desc = "Done!"
436
+ when "error"
437
+ code = "danger"
438
+ desc = "Alert!"
439
+ when "info"
440
+ code = "info"
441
+ desc = "Info!"
442
+ end
443
+ %>
444
+ <div class="alert alert-<%= code %>">
445
+ <button type="button" class="close" data-dismiss="alert">x</button>
446
+ <strong><%= desc %></strong> <%= msg %>
447
+ </div>
448
+ <% end %>
449
+ TEXT
450
+
451
+ use_bootstrap = @configs[@current_recipe] = yes_wizard?("Install and configure Bootstrap?")
452
+ if use_bootstrap
453
+ gem 'bootstrap-sass', '~> 3.3.4'
454
+
455
+ after_bundler do
456
+ append_to_file 'app/assets/stylesheets/application.css.scss', config_lines
457
+ insert_into_file "app/assets/javascripts/application.js", :after => %r{//= require +['"]?jquery_ujs['"]?} do
458
+ "\n//= require bootstrap-sprockets"
459
+ end
460
+ create_file 'app/views/shared/_messages.html.erb', flash_message
461
+ end
462
+ end
463
+
464
+ # >-----------------------------[ Font Awesome ]------------------------------<
465
+
466
+ @current_recipe = "font-awesome"
467
+ @before_configs["font-awesome"].call if @before_configs["font-awesome"]
468
+ say_recipe 'Font Awesome'
469
+
470
+ font_awesome_configs = <<-TEXT
471
+ @import "font-awesome-sprockets";
472
+ @import "font-awesome";
473
+ TEXT
474
+
475
+ gem 'font-awesome-sass', '~> 4.3.0'
476
+
477
+ after_bundler do
478
+ append_to_file 'app/assets/stylesheets/application.css.scss', font_awesome_configs
479
+ end
480
+
481
+ # >-----------------------------[ Liquid ]------------------------------<
482
+
483
+ @current_recipe = "liquid"
484
+ @before_configs["liquid"].call if @before_configs["liquid"]
485
+ say_recipe 'Liquid'
486
+
487
+ gem "liquid"
488
+
489
+ # >--------------------------[ jQuery Validation ]-----------------------------<
490
+
491
+ @current_recipe = "jquery-validation-rails"
492
+ @before_configs["jquery-validation-rails"].call if @before_configs["jquery-validation-rails"]
493
+ say_recipe 'jQuery Validation Rails'
494
+
495
+ gem "jquery-validation-rails"
496
+
497
+ after_bundler do
498
+ insert_into_file "app/assets/javascripts/application.js", :after => %r{//= require +['"]?jquery_ujs['"]?} do
499
+ "\n//= require jquery.validate\n//= require jquery.validate.additional-methods"
500
+ end
501
+ end
502
+
503
+ # >--------------------------[ jQuery dataTables ]-----------------------------<
504
+
505
+ @current_recipe = "jquery-datatables-rails"
506
+ @before_configs["jquery-datatables-rails"].call if @before_configs["jquery-datatables-rails"]
507
+ say_recipe 'jQuery dataTables Rails'
508
+
509
+ gem 'jquery-datatables-rails', '~> 3.2.0'
510
+
511
+ datatable_config_lines_bootstrap = <<-TEXT
512
+ @import "dataTables/bootstrap/3/jquery.dataTables.bootstrap";
513
+ TEXT
514
+
515
+ datatable_config_lines_non_bootstrap = <<-TEXT
516
+ @import "dataTables/jquery.dataTables";
517
+ TEXT
518
+
519
+ datatable_model = <<-TEXT
520
+ class Datatable
521
+ include ApplicationHelper
522
+ delegate :params, :t, :h, :current_user, :link_to, to: :@view
523
+
524
+ def initialize(view)
525
+ @view = view
526
+ end
527
+
528
+ def as_json(options = {})
529
+ {
530
+ sEcho: params[:sEcho].to_i,
531
+ iTotalRecords: rows ? rows.count : 0,
532
+ iTotalDisplayRecords: rows ? rows.total_entries : 0,
533
+ aaData: data
534
+ }
535
+ end
536
+
537
+
538
+ def rows
539
+ @rows ||= fetch_datas
540
+ end
541
+
542
+ def fetch_datas
543
+ end
544
+
545
+ def page
546
+ params[:iDisplayStart].to_i/per_page + 1
547
+ end
548
+
549
+ def per_page
550
+ params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10
551
+ end
552
+
553
+ def columns
554
+ %w[]
555
+ end
556
+
557
+ def sort_column
558
+ if params["iSortCol_0"].blank?
559
+ columns[params[:order]["0"]["column"].to_i]
560
+ else
561
+ columns[params["iSortCol_0"].to_i]
562
+ end
563
+
564
+ end
565
+
566
+ def sort_direction
567
+ if params["iSortCol_0"].blank?
568
+ params[:order]["0"]["dir"] == "desc" ? "desc" : "asc"
569
+ else
570
+ params["sSortDir_0"] == "desc" ? "desc" : "asc"
571
+ end
572
+
573
+ end
574
+ end
575
+ TEXT
576
+
577
+ after_bundler do
578
+ after_bundler do
579
+ if @configs["bootstrap"] # if bootstrap configuration is true
580
+ say_wizard "Generating Bootstrap 3 dataTables"
581
+ append_to_file 'app/assets/stylesheets/application.css.scss', datatable_config_lines_bootstrap
582
+ insert_into_file "app/assets/javascripts/application.js", :after => %r{//= require +['"]?jquery_ujs['"]?} do
583
+ "\n//= require dataTables/jquery.dataTables\n//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap"
584
+ end
585
+ else
586
+ append_to_file 'app/assets/stylesheets/application.css.scss', datatable_config_lines_non_bootstrap
587
+ insert_into_file "app/assets/javascripts/application.js", :after => %r{//= require +['"]?jquery_ujs['"]?} do
588
+ "\n//= require dataTables/jquery.dataTables\n//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap"
589
+ end
590
+ end
591
+ create_file "app/models/datatable.rb", datatable_model
592
+ end
593
+ end
594
+
595
+ # >-----------------------------[ Kaminari ]------------------------------<
596
+
597
+ @current_recipe = "kaminari"
598
+ @before_configs["kaminari"].call if @before_configs["kaminari"]
599
+ say_recipe 'Kaminari'
600
+
601
+ gem 'kaminari'
602
+
603
+ after_bundler do
604
+ generate "kaminari:views bootstrap3" if @configs["bootstrap"]
605
+ end
606
+
607
+ # >----------------------------[ Home Controller ]-----------------------------<
608
+
609
+ @current_recipe = "views"
610
+ @before_configs["views"].call if @before_configs["views"]
611
+ say_recipe 'Home Controller'
612
+
613
+ after_bundler do
614
+ generate "controller home index"
615
+ inject_into_file "config/routes.rb", "\n root 'home#index'", :after => "devise_for :users"
616
+ end
617
+
618
+ # >---------------------------[ Deployment ]----------------------------<
619
+
620
+ @current_recipe = "deployment"
621
+ @before_configs["deployment"].call if @before_configs["deployment"]
622
+ say_recipe 'Deployment'
623
+
624
+ config['deployment'] = multiple_choice("Which deployment method are you using?", [["Heroku", "heroku"], ["Capistrano", "capistrano"], ["Engine Yard", "engineyard"], ["No Recipe", "none"]])
625
+
626
+ unicorn_config =<<-TEXT
627
+ # config/unicorn.rb
628
+ worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
629
+ timeout 15
630
+ preload_app true
631
+
632
+ before_fork do |server, worker|
633
+ Signal.trap 'TERM' do
634
+ puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
635
+ Process.kill 'QUIT', Process.pid
636
+ end
637
+
638
+ defined?(ActiveRecord::Base) and
639
+ ActiveRecord::Base.connection.disconnect!
640
+ end
641
+
642
+ after_fork do |server, worker|
643
+ Signal.trap 'TERM' do
644
+ puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
645
+ end
646
+
647
+ defined?(ActiveRecord::Base) and
648
+ ActiveRecord::Base.establish_connection
649
+ end
650
+ TEXT
651
+
652
+ ey_config = <<-TEXT
653
+ ---
654
+ # This is all you need for a typical rails application.
655
+ defaults:
656
+ migrate: true
657
+ migration_command: rake db:migrate
658
+ precompile_assets: true
659
+ TEXT
660
+
661
+ case config['deployment']
662
+ when "heroku"
663
+ gem 'unicorn'
664
+ gem 'rails_12factor', group: :production
665
+
666
+ after_bundler do
667
+ create_file "config/unicorn.rb", unicorn_config
668
+ create_file "Procfile", "web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb"
669
+ end
670
+ when "capistrano"
671
+ gem 'capistrano', '~> 3.3.0'
672
+
673
+ after_bundler do
674
+ run "bundle exec cap install"
675
+ end
676
+
677
+ when "engineyard"
678
+ after_bundler do
679
+ create_file "config/ey.yml", ey_config
680
+ end
681
+ end
682
+
683
+ # >----------------------------------[ Git ]----------------------------------<
684
+
685
+ @current_recipe = "git"
686
+ @before_configs["git"].call if @before_configs["git"]
687
+ say_recipe 'Git'
688
+
689
+ after_everything do
690
+ git :init
691
+ git :add => '.'
692
+ git :commit => '-m "Initial commit"'
693
+ end
694
+
695
+ # >-----------------------------[ Run Bundler ]-------------------------------<
696
+ @current_recipe = "bundler"
697
+
698
+ say_wizard "Running Bundler install. This will take a while."
699
+ run 'bundle install'
700
+ say_wizard "Running after Bundler callbacks."
701
+ @after_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call}
702
+
703
+ @current_recipe = nil
704
+ say_wizard "Running after everything callbacks."
705
+ @after_everything_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call}
706
+
707
+ @current_recipe = nil
708
+ say_wizard "==================================FINISH PROCESS================================="