template.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 User"
  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. end
  49. def add_webpack
  50. rails_command 'webpacker:install'
  51. end
  52. def add_sidekiq
  53. environment "config.active_job.queue_adapter = :sidekiq"
  54. insert_into_file "config/routes.rb",
  55. "require 'sidekiq/web'\n\n",
  56. before: "Rails.application.routes.draw do"
  57. insert_into_file "config/routes.rb",
  58. " authenticate :user, lambda { |u| u.admin? } do\n mount Sidekiq::Web => '/sidekiq'\n end\n\n",
  59. after: "Rails.application.routes.draw do\n"
  60. end
  61. def add_foreman
  62. copy_file "Procfile"
  63. end
  64. # Main setup
  65. add_gems
  66. after_bundle do
  67. add_users
  68. add_bootstrap
  69. copy_templates
  70. add_sidekiq
  71. add_foreman
  72. add_webpack
  73. # Migrate
  74. rails_command "db:create"
  75. rails_command "db:migrate"
  76. git :init
  77. git add: "."
  78. git commit: %Q{ -m 'Initial commit' }
  79. end