Class: ExtensionControllerGenerator

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

Instance Method Summary collapse

Instance Method Details

#directoriesObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/generators/extension_controller/extension_controller_generator.rb', line 9

def directories
  empty_directory File.join(class_path, 'app/controllers')
  empty_directory File.join(class_path, 'app/helpers')
  empty_directory File.join(class_path, 'app/views', file_name)
  
  unless options.with_test_unit?
    empty_directory File.join(class_path, 'spec/controllers')
    empty_directory File.join(class_path, 'spec/helpers')
    empty_directory File.join(class_path, 'spec/views', file_name)
  end
end

#filesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/extension_controller/extension_controller_generator.rb', line 22

def files
  template 'controller_spec.rb',
           File.join(class_path, 'spec/controllers', "#{file_name}_controller_spec.rb")

  template 'helper_spec.rb',
           File.join(class_path, 'spec/helpers', "#{file_name}_helper_spec.rb")
  
  template 'controller.rb',
           File.join(class_path, 'app/controllers', "#{file_name}_controller.rb")
  
  template 'helper.rb',
           File.join(class_path, 'app/helpers', "#{file_name}_helper.rb")
end

#partsObject



36
37
38
39
40
41
42
43
44
# File 'lib/generators/extension_controller/extension_controller_generator.rb', line 36

def parts
  # Spec and view template for each action.
  actions.each do |a|
    @action = a
    template 'view_spec.rb', File.join(class_path, 'spec/views', file_name, "#{@action}_view_spec.rb")
    
    template 'view.html.haml', File.join(class_path, 'app/views', file_name, "#{@action}.html.haml")
  end
end