require 'rails/generators' module PagesCms module Generators class InstallGenerator < Rails::Generators::Base def copy_migrations puts ' ' puts ' Installing PagesCMS' puts ' -------------------' puts ' installing migrations' `rake pages_cms:install:migrations` end def run_migrations puts ' migrating database' `rake db:migrate` end def add_route route "mount PagesCms::Engine => '/'" end def add_filters inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do <<-'RUBY' # added by PagesCMS. Fill out this helper to protect your controllers. def logged_in_admin # Do something if admin # is not logged in # ie: redirect_to root_path unless current_user.admin end RUBY end end def add_helpers inject_into_file 'app/helpers/application_helper.rb', after: "module ApplicationHelper\n" do <<-'RUBY' # added by PagesCMS. Fill out this helper to protect your views. def current_user_is_admin? true end RUBY end end def add_javascript js_manifest = 'app/assets/javascripts/application.js' js_require_block = " //= require cocoon\n" insert_into_file js_manifest, js_require_block, :after => "//= require jquery\n" end def instructions puts ' ' puts ' To get hacking immediately it is recommended that you install bootstrap:' puts ' 1. Add: `gem "bootstrap-sass"` to your `Gemfile` ' puts ' 2. Add: `//= require bootstrap` to your `application.js` ' puts ' 3. Run: `$ bundle install` ' puts ' ' puts ' To get hacking the views and stylesheets: `$ rails generate pages_cms:views` ' puts ' ' puts ' To learn more: https://github.com/ColDog/PagesCMS' end end end end