template.rb 1.7 KB

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