Class: AbAdmin::Generators::ResourceGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::ResourceHelpers
Defined in:
lib/generators/ab_admin/resource/resource_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_menuObject


34
35
36
37
38
39
40
41
42
# File 'lib/generators/ab_admin/resource/resource_generator.rb', line 34

def add_menu
  menu_code = "model #{model.name}"
  log :menu, menu_code
  sentinel = /draw do$/

  in_root do
    inject_into_file 'app/models/admin_menu.rb', "\n    #{menu_code}\n", {after: sentinel, verbose: false}
  end
end

#add_routesObject


24
25
26
27
28
29
30
31
32
# File 'lib/generators/ab_admin/resource/resource_generator.rb', line 24

def add_routes
  routing_code = "resources(:#{controller_file_name}) { post :batch, on: :collection }"
  log :route, routing_code
  sentinel = /namespace :admin do$/

  in_root do
    inject_into_file 'config/routes.rb', "\n    #{routing_code}\n", {after: sentinel, verbose: false}
  end
end

#create_controller_filesObject


20
21
22
# File 'lib/generators/ab_admin/resource/resource_generator.rb', line 20

def create_controller_files
  template 'controller.erb', File.join('app/controllers/admin', "#{controller_file_name}_controller.rb")
end

#create_view_filesObject


44
45
46
47
48
49
50
# File 'lib/generators/ab_admin/resource/resource_generator.rb', line 44

def create_view_files
  empty_directory File.join('app/views', controller_file_path)
  available_views.each do |view|
    next if options.send("skip_#{view.sub(/^_/, '')}?")
    template "#{view}.#{options[:handler]}.erb", File.join('app/views/admin', controller_file_path, view_filename_with_extensions(view))
  end
end

#modelObject


52
53
54
# File 'lib/generators/ab_admin/resource/resource_generator.rb', line 52

def model
  @model ||= class_name.constantize
end