Class: PagesCms::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- PagesCms::Generators::InstallGenerator
- Defined in:
- lib/generators/pages_cms/Install_generator.rb
Instance Method Summary collapse
- #add_filters ⇒ Object
- #add_helpers ⇒ Object
- #add_route ⇒ Object
- #copy_migrations ⇒ Object
- #create_home ⇒ Object
- #instructions ⇒ Object
- #run_migrations ⇒ Object
Instance Method Details
#add_filters ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/generators/pages_cms/Install_generator.rb', line 27 def add_filters inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do " # added by PagesCMS. Fill out this helper to protect your controllers.\n def logged_in_admin\n # Do something if admin\n # is not logged in\n # ie: redirect_to root_path unless current_user.admin\n end\n # added by PagesCMS. Use this helper to link to user created pages.\n def slugged_path(page)\n \"/\#{page.slug}\"\n end\n RUBY\n end\nend\n" |
#add_helpers ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/pages_cms/Install_generator.rb', line 43 def add_helpers inject_into_file 'app/helpers/application_helper.rb', after: "module ApplicationHelper\n" do " # added by PagesCMS. Fill out this helper to protect your views.\n def current_user_is_admin?\n true\n end\n RUBY\n end\nend\n" |
#add_route ⇒ Object
23 24 25 |
# File 'lib/generators/pages_cms/Install_generator.rb', line 23 def add_route route "mount PagesCms::Engine => '/'" end |
#copy_migrations ⇒ Object
6 7 8 9 |
# File 'lib/generators/pages_cms/Install_generator.rb', line 6 def copy_migrations puts ' installing migrations' `rake pages_cms:install:migrations` end |
#create_home ⇒ Object
16 17 18 19 20 21 |
# File 'lib/generators/pages_cms/Install_generator.rb', line 16 def create_home puts ' create homepage' page = Page.create(title: 'Home') page.save! page.(show: true) end |
#instructions ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/generators/pages_cms/Install_generator.rb', line 53 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 |
#run_migrations ⇒ Object
11 12 13 14 |
# File 'lib/generators/pages_cms/Install_generator.rb', line 11 def run_migrations puts ' migrating database' `rake db:migrate` end |