template.rb 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. "name",
  32. "announcements_last_read_at:datetime",
  33. "admin:boolean"
  34. # Set admin default to false
  35. in_root do
  36. migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) }
  37. gsub_file migration, /:admin/, ":admin, default: false"
  38. end
  39. # Add Devise masqueradable to users
  40. #inject_into_file("app/models/user.rb", "masqueradable, :", :after => "devise :")
  41. end
  42. def add_bootstrap
  43. # Remove Application CSS
  44. run "rm app/assets/stylesheets/application.css"
  45. # Add Bootstrap JS
  46. insert_into_file(
  47. "app/assets/javascripts/application.js",
  48. "\n//= require jquery\n//= require popper\n//= require bootstrap",
  49. after: "//= require rails-ujs"
  50. )
  51. end
  52. def copy_templates
  53. directory "app", force: true
  54. directory "config", force: true
  55. route "get '/terms', to: 'home#terms'"
  56. route "get '/privacy', to: 'home#privacy'"
  57. end
  58. def add_webpack
  59. rails_command 'webpacker:install'
  60. end
  61. def add_sidekiq
  62. environment "config.active_job.queue_adapter = :sidekiq"
  63. insert_into_file "config/routes.rb",
  64. "require 'sidekiq/web'\n\n",
  65. before: "Rails.application.routes.draw do"
  66. insert_into_file "config/routes.rb",
  67. " authenticate :user, lambda { |u| u.admin? } do\n mount Sidekiq::Web => '/sidekiq'\n end\n\n",
  68. after: "Rails.application.routes.draw do\n"
  69. end
  70. def add_foreman
  71. copy_file "Procfile"
  72. end
  73. def add_announcements
  74. generate "model Announcement published_at:datetime announcement_type name description:text"
  75. route "resources :announcements, only: [:index]"
  76. end
  77. def add_notifications
  78. generate "model Notification recipient_id:integer actor_id:integer read_at:datetime action:string notifiable_id:integer notifiable_type:string"
  79. route "resources :notifications, only: [:index]"
  80. end
  81. def add_administrate
  82. generate "administrate:install"
  83. gsub_file "app/dashboards/announcement_dashboard.rb",
  84. /announcement_type: Field::String/,
  85. "announcement_type: Field::Select.with_options(collection: Announcement::TYPES)"
  86. end
  87. def add_multiple_authentication
  88. insert_into_file "config/routes.rb",
  89. ', controllers: { omniauth_callbacks: "users/omniauth_callbacks" }',
  90. after: " devise_for :users"
  91. generate "model Service user:references provider uid access_token access_token_secret refresh_token expires_at:datetime auth:text"
  92. insert_into_file "config/initializers/devise.rb",
  93. " if Rails.application.secrets.facebook_app_id.present? && Rails.application.secrets.facebook_app_secret.present? then (config.omniauth :facebook, Rails.application.secrets.facebook_app_id, Rails.application.secrets.facebook_app_secret, scope: 'email,user_posts') end \n
  94. if Rails.application.secrets.twitter_app_id.present? && Rails.application.secrets.twitter_app_secret.present? then (config.omniauth :twitter, Rails.application.secrets.twitter_app_id, Rails.application.secrets.twitter_app_secret) end \n
  95. if Rails.application.secrets.github_app_id.present? && Rails.application.secrets.github_app_secret.present? then (config.omniauth :github, Rails.application.secrets.github_app_id, Rails.application.secrets.github_app_secret) end\n",
  96. before: " # ==> Warden configuration"
  97. end
  98. # Main setup
  99. add_gems
  100. after_bundle do
  101. add_users
  102. add_bootstrap
  103. add_sidekiq
  104. add_foreman
  105. add_webpack
  106. add_announcements
  107. add_notifications
  108. add_multiple_authentication
  109. # Migrate
  110. rails_command "db:create"
  111. rails_command "db:migrate"
  112. # Migrations must be done before this
  113. add_administrate
  114. copy_templates
  115. git :init
  116. git add: "."
  117. git commit: %Q{ -m 'Initial commit' }
  118. end