123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- def source_paths
- [File.expand_path(File.dirname(__FILE__))]
- end
- def add_gems
- gem 'administrate', '~> 0.8.1'
- gem 'devise', '~> 4.3.0'
- gem 'devise-bootstrapped', github: 'excid3/devise-bootstrapped', branch: 'bootstrap4'
- gem 'devise_masquerade', '~> 0.6.0'
- gem 'font-awesome-sass', '~> 4.7'
- gem 'gravatar_image_tag', github: 'mdeering/gravatar_image_tag'
- gem 'jquery-rails', '~> 4.3.1'
- gem 'bootstrap', '~> 4.0.0.beta'
- gem 'webpacker', '~> 3.0'
- gem 'sidekiq', '~> 5.0'
- gem 'foreman', '~> 0.84.0'
- end
- def add_users
- # Install Devise
- generate "devise:install"
- # Configure Devise
- environment "config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }",
- env: 'development'
- route "root to: 'home#index'"
- # Devise notices are installed via Bootstrap
- generate "devise:views:bootstrapped"
- # Create Devise User
- generate :devise, "User",
- "first_name",
- "last_name",
- "announcements_last_read_at:datetime",
- "admin:boolean"
- # Set admin default to false
- in_root do
- migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) }
- gsub_file migration, /:admin/, ":admin, default: false"
- end
- # Add Devise masqueradable to users
- #inject_into_file("app/models/user.rb", "masqueradable, :", :after => "devise :")
- end
- def add_bootstrap
- # Remove Application CSS
- run "rm app/assets/stylesheets/application.css"
- # Add Bootstrap JS
- insert_into_file(
- "app/assets/javascripts/application.js",
- "\n//= require jquery\n//= require popper\n//= require bootstrap",
- after: "//= require rails-ujs"
- )
- end
- def copy_templates
- directory "app", force: true
- directory "config", force: true
- route "get '/terms', to: 'home#terms'"
- route "get '/privacy', to: 'home#privacy'"
- end
- def add_webpack
- rails_command 'webpacker:install'
- end
- def add_sidekiq
- environment "config.active_job.queue_adapter = :sidekiq"
- insert_into_file "config/routes.rb",
- "require 'sidekiq/web'\n\n",
- before: "Rails.application.routes.draw do"
- insert_into_file "config/routes.rb",
- " authenticate :user, lambda { |u| u.admin? } do\n mount Sidekiq::Web => '/sidekiq'\n end\n\n",
- after: "Rails.application.routes.draw do\n"
- end
- def add_foreman
- copy_file "Procfile"
- end
- def add_announcements
- generate "model Announcement published_at:datetime announcement_type name description:text"
- route "resources :announcements, only: [:index]"
- end
- def add_administrate
- generate "administrate:install"
- gsub_file "app/dashboards/announcement_dashboard.rb",
- /announcement_type: Field::String/,
- "announcement_type: Field::Select.with_options(collection: Announcement::TYPES)"
- end
- # Main setup
- add_gems
- after_bundle do
- add_users
- add_bootstrap
- add_sidekiq
- add_foreman
- add_webpack
- add_announcements
- # Migrate
- rails_command "db:create"
- rails_command "db:migrate"
- # Migrations must be done before this
- add_administrate
- copy_templates
- git :init
- git add: "."
- git commit: %Q{ -m 'Initial commit' }
- end
|