require 'rails/generators' module PagesCms module Generators class InstallGenerator < Rails::Generators::Base def copy_migrations puts ' installing migrations' `rake pages_cms:install:migrations` end def run_migrations puts ' migrating database' `rake db:migrate` end def create_home puts ' create homepage' page = Page.create(title: 'Home') page.save! page.build_sidebar(show: true) 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 # added by PagesCMS. Use this helper to link to user created pages. def slugged_path(page) "/#{page.slug}" 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 instructions puts ' ' puts ' To get hacking immediately:' puts ' 1. Run: rails generate pages_cms:views' puts ' 2. Add: gem "bootstrap-sass" to your gemfile' puts ' 3. Add: `//= require cocoon` to your application.js' puts ' 4. Add: `//= require bootstrap` to your application.js' puts ' 5. Add: `*= require pages_cms/pages_cms` to your application.css' puts ' ' puts ' You should now be able to go to /admin/pages and start building pages!' puts ' ' puts ' This generator has added a `logged_in_admin` method to your application controller which will authorize the controllers in pages_cms/admin.' puts ' It has also added a helper method `current_user_is_admin?` to your application helper, this verifies in the view that a user is an admin.' puts ' It has also added a `slugged_path` helper method to your application helper, this provides a path helper to link to user pages.' puts ' Make sure to fill these methods out to secure your application.' end end end end