Class: PagesCms::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/pages_cms/Install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_filtersObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/pages_cms/Install_generator.rb', line 32

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    RUBY\n  end\nend\n"

#add_helpersObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/generators/pages_cms/Install_generator.rb', line 44

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  # added by PagesCMS. Use this helper to link to user created pages.\n  def slugged_path(page)\n    if page.class == String\n\"/\#{page}\"\n    else\n\"/\#{page.slug}\"\n    end\n  end\n    RUBY\n  end\nend\n"

#add_javascriptObject



62
63
64
65
66
# File 'lib/generators/pages_cms/Install_generator.rb', line 62

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

#add_routeObject



28
29
30
# File 'lib/generators/pages_cms/Install_generator.rb', line 28

def add_route
  route "mount PagesCms::Engine => '/'"
end

#copy_migrationsObject



6
7
8
9
10
11
12
# File 'lib/generators/pages_cms/Install_generator.rb', line 6

def copy_migrations
  puts ' '
  puts '              Installing PagesCMS'
  puts '              -------------------'
  puts '              installing migrations'
  `rake pages_cms:install:migrations`
end

#create_homeObject



19
20
21
22
23
24
25
26
# File 'lib/generators/pages_cms/Install_generator.rb', line 19

def create_home
  puts '              create initial homepage'
  page = Page.new(title: 'Home')
  if page.valid?
    page.save
    page.build_sidebar(show: true)
  end
end

#instructionsObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/generators/pages_cms/Install_generator.rb', line 68

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 bootstrap` to your `application.js`           '
  puts '      4.  Add: `*=  require pages_cms/pages_cms` to your `application.css`'
  puts '      5.  Run: `$ bundle install`                                         '
  puts '      '
  puts '      You should now be able to go to /admin/pages and start building pages!'
end

#run_migrationsObject



14
15
16
17
# File 'lib/generators/pages_cms/Install_generator.rb', line 14

def run_migrations
  puts '              migrating database'
  `rake db:migrate`
end