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_admin_seedObject

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_admin_seed
  file='db/seeds.rb'
  add_if_missing(file, "AdminUser.create!(:email=>'[email protected]',:password=>'password')")
end

#add_gemsObject



19
20
21
22
# File 'lib/generators/frame/admin/admin_generator.rb', line 19

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

#cleanup_page_routesObject



50
51
52
53
54
# File 'lib/generators/frame/admin/admin_generator.rb', line 50

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



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/frame/admin/admin_generator.rb', line 24

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



56
57
58
59
60
61
62
63
64
# File 'lib/generators/frame/admin/admin_generator.rb', line 56

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



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

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

#update_dbObject



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

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

#update_pages_controllerObject



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

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