template.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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: 'excid3/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. 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. generate "devise:views:bootstrapped"
  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. # Remove Application CSS
  37. run "rm app/assets/stylesheets/application.css"
  38. # Add Bootstrap JS
  39. insert_into_file(
  40. "app/assets/javascripts/application.js",
  41. "\n//= require jquery\n//= require tether\n//= require bootstrap",
  42. after: "//= require rails-ujs"
  43. )
  44. end
  45. def copy_templates
  46. directory "app", force: true
  47. route "get '/terms', to: 'home#terms'"
  48. route "get '/privacy', to: 'home#privacy'"
  49. end
  50. def add_webpack
  51. rails_command 'webpacker:install'
  52. end
  53. def add_sidekiq
  54. environment "config.active_job.queue_adapter = :sidekiq"
  55. insert_into_file "config/routes.rb",
  56. "require 'sidekiq/web'\n\n",
  57. before: "Rails.application.routes.draw do"
  58. insert_into_file "config/routes.rb",
  59. " authenticate :user, lambda { |u| u.admin? } do\n mount Sidekiq::Web => '/sidekiq'\n end\n\n",
  60. after: "Rails.application.routes.draw do\n"
  61. end
  62. def add_foreman
  63. copy_file "Procfile"
  64. end
  65. def add_announcements
  66. generate "model Announcement published_at:datetime announcement_type name description:text"
  67. route "resources :announcements, only: [:index]"
  68. end
  69. # Main setup
  70. add_gems
  71. after_bundle do
  72. add_users
  73. add_bootstrap
  74. add_sidekiq
  75. add_foreman
  76. add_webpack
  77. add_announcements
  78. copy_templates
  79. # Migrate
  80. rails_command "db:create"
  81. rails_command "db:migrate"
  82. git :init
  83. git add: "."
  84. git commit: %Q{ -m 'Initial commit' }
  85. end