Class: Frame::Generators::AdminGenerator

Inherits:
Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/frame/admin/admin_generator.rb

Instance Method Summary collapse

Methods inherited from Base

banner, source_root

Instance Method Details

#add_gemsObject

Need to seed the production environment with: AdminUser.create!(:email=>‘[email protected]’,:username=>‘test’,:password=>‘password’)



14
15
16
17
# File 'lib/generators/frame/admin/admin_generator.rb', line 14

def add_gems
  add_gem("sass-rails", :group => "test")
  add_gem("meta_search", :group => "test")
end

#cleanup_page_routesObject



45
46
47
48
49
# File 'lib/generators/frame/admin/admin_generator.rb', line 45

def cleanup_page_routes
  file='config/routes.rb'
  add_if_missing(file, "  match 'pages/:id' => 'pages#show', :as => :page", :after => "  resources :pages\n")
  comment_lines file, /  resources :pages/
end

#install_active_adminObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/frame/admin/admin_generator.rb', line 19

def install_active_admin
  if yes?("Would you like to install Active Admin?")
    gem("activeadmin")
    Bundler.with_clean_env do
      run "bundle install"
    end
    generate("active_admin:install")
    default_model = "page"
    generate("active_admin:resource #{default_model}")
  end
end

#remove_pages_cudObject



51
52
53
54
55
56
57
58
59
# File 'lib/generators/frame/admin/admin_generator.rb', line 51

def remove_pages_cud
  filenames = ["app/views/pages/new.html.erb", "app/views/pages/edit.html.erb", "app/views/pages/index.html.erb", "app/views/pages/_form.html.erb"]
    filenames.each { |filename|
      if File.exists?(filename) and yes?("Would you like to remove '#{filename}'?")
        remove_file filename
      end
    }
  template('app/views/pages/show.html.erb')
end

#update_admin_formObject



37
38
39
# File 'lib/generators/frame/admin/admin_generator.rb', line 37

def update_admin_form
  template('app/admin/pages.rb')
end

#update_dbObject



31
32
33
34
35
# File 'lib/generators/frame/admin/admin_generator.rb', line 31

def update_db
  if yes?("Would you like to migrate the database?")
    rake("db:migrate")
  end
end

#update_pages_controllerObject



41
42
43
# File 'lib/generators/frame/admin/admin_generator.rb', line 41

def update_pages_controller
  template('app/controllers/pages_controller.rb')
end