template.rb 3.1 KB

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