Class: FlexibleAdmin::FlexibleAdminGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_to_navigation_menuObject



56
57
58
# File 'lib/generators/flexible_admin/flexible_admin_generator.rb', line 56

def add_to_navigation_menu
  gsub_file 'app/views/layouts/admin/_navigation.html.erb', "models = %w(", "models = %w(#{resources_name} "
end

#create_resources_controllerObject



51
52
53
54
# File 'lib/generators/flexible_admin/flexible_admin_generator.rb', line 51

def create_resources_controller
  template "admin_resources_controller.rb", "app/controllers/admin/resources_controller.rb"
  template "resources_controller.rb", "app/controllers/admin/#{resources_name}_controller.rb"
end

#creates_resource_viewsObject



15
16
17
18
19
20
# File 'lib/generators/flexible_admin/flexible_admin_generator.rb', line 15

def creates_resource_views
  template "resources/index.html.erb", "app/views/admin/#{resources_name}/index.html.erb"
  template "resources/new.html.erb", "app/views/admin/#{resources_name}/new.html.erb"
  template "resources/edit.html.erb", "app/views/admin/#{resources_name}/edit.html.erb"
  template "resources/form.html.erb", "app/views/admin/#{resources_name}/_form.html.erb"
end

#make_routesObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/flexible_admin/flexible_admin_generator.rb', line 26

def make_routes
  if has_admin_route_namespace?
    routing_code = "
resources :#{resources_name}, :except => :show do
  member do
    get 'toggle'
  end
end"
    sentinel = /namespace :admin do$/
    in_root do
      inject_into_file 'config/routes.rb', "\n          #{routing_code}", { :after => sentinel, :verbose => true }
    end
  else
    route_info = "
namespace :admin do
  resources :#{resources_name}, :except => :show do
    member do
      get 'toggle'
    end
  end
end"
    route(route_info)
  end
end

#remove_any_namespace_admin_comments_in_routesObject



22
23
24
# File 'lib/generators/flexible_admin/flexible_admin_generator.rb', line 22

def remove_any_namespace_admin_comments_in_routes
  gsub_file 'config/routes.rb', /#\s*(namespace :admin do)/, ''
end