template.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. end
  17. def add_users
  18. # Install Devise
  19. generate "devise:install"
  20. # Configure Devise
  21. environment "config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }",
  22. env: 'development'
  23. route "root to: 'home#index'"
  24. # Devise notices are installed via Bootstrap
  25. generate "devise:views:bootstrapped"
  26. # Create Devise User
  27. generate :devise, "User",
  28. "first_name",
  29. "last_name",
  30. "announcements_last_read_at:datetime",
  31. "admin:boolean"
  32. # Set admin default to false
  33. in_root do
  34. migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) }
  35. gsub_file migration, /:admin/, ":admin, default: false"
  36. end
  37. # Add Devise masqueradable to users
  38. #inject_into_file("app/models/user.rb", "masqueradable, :", :after => "devise :")
  39. end
  40. def add_bootstrap
  41. # Remove Application CSS
  42. run "rm app/assets/stylesheets/application.css"
  43. # Add Bootstrap JS
  44. insert_into_file(
  45. "app/assets/javascripts/application.js",
  46. "\n//= require jquery\n//= require popper\n//= require bootstrap",
  47. after: "//= require rails-ujs"
  48. )
  49. end
  50. def copy_templates
  51. directory "app", force: true
  52. directory "config", force: true
  53. route "get '/terms', to: 'home#terms'"
  54. route "get '/privacy', to: 'home#privacy'"
  55. end
  56. def add_webpack
  57. rails_command 'webpacker:install'
  58. end
  59. def add_sidekiq
  60. environment "config.active_job.queue_adapter = :sidekiq"
  61. insert_into_file "config/routes.rb",
  62. "require 'sidekiq/web'\n\n",
  63. before: "Rails.application.routes.draw do"
  64. insert_into_file "config/routes.rb",
  65. " authenticate :user, lambda { |u| u.admin? } do\n mount Sidekiq::Web => '/sidekiq'\n end\n\n",
  66. after: "Rails.application.routes.draw do\n"
  67. end
  68. def add_foreman
  69. copy_file "Procfile"
  70. end
  71. def add_announcements
  72. generate "model Announcement published_at:datetime announcement_type name description:text"
  73. route "resources :announcements, only: [:index]"
  74. end
  75. def add_administrate
  76. generate "administrate:install"
  77. gsub_file "app/dashboards/announcement_dashboard.rb",
  78. /announcement_type: Field::String/,
  79. "announcement_type: Field::Select.with_options(collection: Announcement::TYPES)"
  80. end
  81. # Main setup
  82. add_gems
  83. after_bundle do
  84. add_users
  85. add_bootstrap
  86. add_sidekiq
  87. add_foreman
  88. add_webpack
  89. add_announcements
  90. # Migrate
  91. rails_command "db:create"
  92. rails_command "db:migrate"
  93. # Migrations must be done before this
  94. add_administrate
  95. copy_templates
  96. git :init
  97. git add: "."
  98. git commit: %Q{ -m 'Initial commit' }
  99. end