template.rb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 'jquery-rails', '~> 4.3.1'
  9. gem 'bootstrap', '~> 4.0.0.alpha6'
  10. gem 'rails-assets-tether', '>= 1.3.3', source: 'https://rails-assets.org'
  11. gem 'webpacker', '~> 1.1'
  12. gem 'sidekiq', '~> 5.0'
  13. gem 'foreman', '~> 0.84.0'
  14. end
  15. def add_users
  16. # Install Devise
  17. generate "devise:install"
  18. # Configure Devise
  19. environment "config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }",
  20. env: 'development'
  21. route "root to: 'home#index'"
  22. # Devise notices are installed via Bootstrap
  23. generate "devise:views:bootstrapped"
  24. # Create Devise User
  25. generate :devise, "User",
  26. "first_name",
  27. "last_name",
  28. "announcements_last_read_at:datetime",
  29. "admin:boolean"
  30. # Set admin default to false
  31. in_root do
  32. migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) }
  33. gsub_file migration, /:admin/, ":admin, default: false"
  34. end
  35. end
  36. def add_bootstrap
  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. route "get '/terms', to: 'home#terms'"
  49. route "get '/privacy', to: 'home#privacy'"
  50. end
  51. def add_webpack
  52. rails_command 'webpacker:install'
  53. end
  54. def add_sidekiq
  55. environment "config.active_job.queue_adapter = :sidekiq"
  56. insert_into_file "config/routes.rb",
  57. "require 'sidekiq/web'\n\n",
  58. before: "Rails.application.routes.draw do"
  59. insert_into_file "config/routes.rb",
  60. " authenticate :user, lambda { |u| u.admin? } do\n mount Sidekiq::Web => '/sidekiq'\n end\n\n",
  61. after: "Rails.application.routes.draw do\n"
  62. end
  63. def add_foreman
  64. copy_file "Procfile"
  65. end
  66. def add_announcements
  67. generate "model Announcement published_at:datetime announcement_type name description:text"
  68. route "resources :announcements, only: [:index]"
  69. end
  70. def add_administrate
  71. generate "administrate:install"
  72. gsub_file "app/dashboards/announcement_dashboard.rb",
  73. /announcement_type: Field::String/,
  74. "announcement_type: Field::Select.with_options(collection: Announcement::TYPES)"
  75. end
  76. # Main setup
  77. add_gems
  78. after_bundle do
  79. add_users
  80. add_bootstrap
  81. add_sidekiq
  82. add_foreman
  83. add_webpack
  84. add_announcements
  85. # Migrate
  86. rails_command "db:create"
  87. rails_command "db:migrate"
  88. # Migrations must be done before this
  89. add_administrate
  90. copy_templates
  91. git :init
  92. git add: "."
  93. git commit: %Q{ -m 'Initial commit' }
  94. end