template.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. def source_paths
  2. [File.expand_path(File.dirname(__FILE__))]
  3. end
  4. def add_gems
  5. gem 'devise', github: 'plataformatec/devise' #, '~> 4.2.1'
  6. gem 'devise-bootstrapped', github: 'king601/devise-bootstrapped', branch: 'bootstrap4'
  7. gem 'jquery-rails', '~> 4.3.1'
  8. gem 'bootstrap', '~> 4.0.0.alpha6'
  9. gem 'rails-assets-tether', '>= 1.3.3', source: 'https://rails-assets.org'
  10. gem 'webpacker', '~> 1.1'
  11. gem 'sidekiq', '~> 5.0'
  12. gem 'foreman', '~> 0.84.0'
  13. end
  14. def add_users
  15. # Install Devise
  16. rails_command "generate devise:install"
  17. # Configure Devise
  18. environment "config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }",
  19. env: 'development'
  20. route "root to: 'home#index'"
  21. # Devise notices are installed via Bootstrap
  22. rails_command "generate devise:views"
  23. # Create Devise User
  24. generate :devise, "User",
  25. "first_name",
  26. "last_name",
  27. "announcements_last_read_at:datetime",
  28. "admin:boolean"
  29. # Set admin default to false
  30. in_root do
  31. migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) }
  32. gsub_file migration, /:admin/, ":admin, default: false"
  33. end
  34. end
  35. def add_bootstrap
  36. generate "devise:views:bootstrapped"
  37. # Remove Application CSS
  38. run "rm app/assets/stylesheets/application.css"
  39. # Add Bootstrap JS
  40. insert_into_file(
  41. "app/assets/javascripts/application.js",
  42. "\n//= require jquery\n//= require tether\n//= require bootstrap",
  43. after: "//= require rails-ujs"
  44. )
  45. end
  46. def copy_templates
  47. directory "app", force: true
  48. route "get '/terms', to: 'home#terms'"
  49. route "get '/privacy', to: 'home#privacy'"
  50. end
  51. def add_webpack
  52. rails_command 'webpacker:install'
  53. end
  54. def add_sidekiq
  55. environment "config.active_job.queue_adapter = :sidekiq"
  56. insert_into_file "config/routes.rb",
  57. "require 'sidekiq/web'\n\n",
  58. before: "Rails.application.routes.draw do"
  59. insert_into_file "config/routes.rb",
  60. " authenticate :user, lambda { |u| u.admin? } do\n mount Sidekiq::Web => '/sidekiq'\n end\n\n",
  61. after: "Rails.application.routes.draw do\n"
  62. end
  63. def add_foreman
  64. copy_file "Procfile"
  65. end
  66. # Main setup
  67. add_gems
  68. after_bundle do
  69. add_users
  70. add_bootstrap
  71. copy_templates
  72. add_sidekiq
  73. add_foreman
  74. add_webpack
  75. # Migrate
  76. rails_command "db:create"
  77. rails_command "db:migrate"
  78. git :init
  79. git add: "."
  80. git commit: %Q{ -m 'Initial commit' }
  81. end