template.rb 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. def source_paths
  2. [File.expand_path(File.dirname(__FILE__))]
  3. end
  4. def add_gems
  5. gem 'administrate', '~> 0.8.1'
  6. gem 'devise', '~> 4.3.0'
  7. gem 'devise-bootstrapped', github: 'excid3/devise-bootstrapped', branch: 'bootstrap4'
  8. gem 'devise_masquerade', '~> 0.6.0'
  9. gem 'font-awesome-sass', '~> 4.7'
  10. gem 'gravatar_image_tag', github: 'mdeering/gravatar_image_tag'
  11. gem 'jquery-rails', '~> 4.3.1'
  12. gem 'bootstrap', '~> 4.0.0.beta'
  13. gem 'webpacker', '~> 3.0'
  14. gem 'sidekiq', '~> 5.0'
  15. gem 'foreman', '~> 0.84.0'
  16. gem 'omniauth-facebook', '~> 4.0'
  17. gem 'omniauth-twitter', '~> 1.4'
  18. gem 'omniauth-github', '~> 1.3'
  19. end
  20. def add_users
  21. # Install Devise
  22. generate "devise:install"
  23. # Configure Devise
  24. environment "config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }",
  25. env: 'development'
  26. route "root to: 'home#index'"
  27. # Devise notices are installed via Bootstrap
  28. generate "devise:views:bootstrapped"
  29. # Create Devise User
  30. generate :devise, "User",
  31. "first_name",
  32. "last_name",
  33. "announcements_last_read_at:datetime",
  34. "admin:boolean"
  35. # Set admin default to false
  36. in_root do
  37. migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) }
  38. gsub_file migration, /:admin/, ":admin, default: false"
  39. end
  40. # Add Devise masqueradable to users
  41. #inject_into_file("app/models/user.rb", "masqueradable, :", :after => "devise :")
  42. end
  43. def add_bootstrap
  44. # Remove Application CSS
  45. run "rm app/assets/stylesheets/application.css"
  46. # Add Bootstrap JS
  47. insert_into_file(
  48. "app/assets/javascripts/application.js",
  49. "\n//= require jquery\n//= require popper\n//= require bootstrap",
  50. after: "//= require rails-ujs"
  51. )
  52. end
  53. def copy_templates
  54. directory "app", force: true
  55. directory "config", force: true
  56. route "get '/terms', to: 'home#terms'"
  57. route "get '/privacy', to: 'home#privacy'"
  58. end
  59. def add_webpack
  60. rails_command 'webpacker:install'
  61. end
  62. def add_sidekiq
  63. environment "config.active_job.queue_adapter = :sidekiq"
  64. insert_into_file "config/routes.rb",
  65. "require 'sidekiq/web'\n\n",
  66. before: "Rails.application.routes.draw do"
  67. insert_into_file "config/routes.rb",
  68. " authenticate :user, lambda { |u| u.admin? } do\n mount Sidekiq::Web => '/sidekiq'\n end\n\n",
  69. after: "Rails.application.routes.draw do\n"
  70. end
  71. def add_foreman
  72. copy_file "Procfile"
  73. end
  74. def add_announcements
  75. generate "model Announcement published_at:datetime announcement_type name description:text"
  76. route "resources :announcements, only: [:index]"
  77. end
  78. def add_notifications
  79. generate "model Notification recipient_id:integer actor_id:integer read_at:datetime action:string notifiable_id:integer notifiable_type:string"
  80. route "resources :notifications, only: [:index]"
  81. end
  82. def add_administrate
  83. generate "administrate:install"
  84. gsub_file "app/dashboards/announcement_dashboard.rb",
  85. /announcement_type: Field::String/,
  86. "announcement_type: Field::Select.with_options(collection: Announcement::TYPES)"
  87. end
  88. def add_multiple_authentication
  89. insert_into_file "config/routes.rb",
  90. ', controllers: { omniauth_callbacks: "users/omniauth_callbacks" }',
  91. after: " devise_for :users"
  92. insert_into_file "app/models/user.rb",
  93. ', :omniauthable',
  94. after: ' :recoverable, :rememberable, :trackable, :validatable'
  95. generate "model Service user:references provider uid access_token access_token_secret refresh_token expires_at:datetime auth:text"
  96. end
  97. # Main setup
  98. add_gems
  99. after_bundle do
  100. add_users
  101. add_bootstrap
  102. add_sidekiq
  103. add_foreman
  104. add_webpack
  105. add_announcements
  106. add_notifications
  107. add_multiple_authentication
  108. # Migrate
  109. rails_command "db:create"
  110. rails_command "db:migrate"
  111. # Migrations must be done before this
  112. add_administrate
  113. copy_templates
  114. git :init
  115. git add: "."
  116. git commit: %Q{ -m 'Initial commit' }
  117. end