Class: Admin::Generators::ScaffoldControllerGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::ResourceHelpers
Defined in:
lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, *options) ⇒ ScaffoldControllerGenerator

:nodoc:


37
38
39
# File 'lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb', line 37

def initialize(args, *options) #:nodoc:
  super
end

Instance Method Details

#copy_view_filesObject


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb', line 67

def copy_view_files
  available_views.each do |view|
    filename = filename_with_extensions(view)
    if bootstrap
      template_path = "views/#{handler}_bootstrap/#{filename}.erb"
    else
      template_path = "views/#{handler}/#{filename}.erb"
    end
    template template_path, File.join("app/views", prefix, controller_file_path, filename)
  end

  # I think there should be a better way to detect if jbuilder is in use
  if Gem::Specification.find_all_by_name('jbuilder').length >= 1
    %w(index show).each do |view|
      template "views/jbuilder/#{view}.json.jbuilder.erb", File.join("app/views", prefix, controller_file_path, "#{view}.json.jbuilder")
    end
  end
end

#create_controller_filesObject


45
46
47
48
49
50
51
52
53
# File 'lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb', line 45

def create_controller_files
  # I think there should be a better way to detect if jbuilder is in use
  # If you know it, please let me know
  if Gem::Specification.find_all_by_name('jbuilder').length >= 1
    template "controllers/jbuilder/controller.rb.erb", File.join('app/controllers', prefix, class_path, "#{controller_file_name}_controller.rb")
  else
    template "controllers/railties/controller.rb.erb", File.join('app/controllers', prefix, class_path, "#{controller_file_name}_controller.rb")
  end
end

#create_root_folderObject


63
64
65
# File 'lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb', line 63

def create_root_folder
  empty_directory File.join("app/views", prefix, controller_file_path)
end

#create_test_filesObject


55
56
57
# File 'lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb', line 55

def create_test_files
  template "tests/test_unit/functional_test.rb.erb", File.join("test/controllers", prefix, controller_class_path, "#{controller_file_name}_controller_test.rb")
end