Class: ChiliprojectPluginControllerGenerator

Inherits:
ControllerGenerator
  • Object
show all
Defined in:
lib/generators/chiliproject_plugin_controller/chiliproject_plugin_controller_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_args, runtime_options = {}) ⇒ ChiliprojectPluginControllerGenerator

Returns a new instance of ChiliprojectPluginControllerGenerator.


21
22
23
24
25
26
27
28
# File 'lib/generators/chiliproject_plugin_controller/chiliproject_plugin_controller_generator.rb', line 21

def initialize(runtime_args, runtime_options = {})
  runtime_args = runtime_args.dup
  usage if runtime_args.empty?
  @plugin_name = "chiliproject_" + runtime_args.shift.underscore
  @plugin_pretty_name = plugin_name.titleize
  @plugin_path = "vendor/plugins/#{plugin_name}"
  super(runtime_args, runtime_options)
end

Instance Attribute Details

#plugin_nameObject (readonly)

Returns the value of attribute plugin_name


19
20
21
# File 'lib/generators/chiliproject_plugin_controller/chiliproject_plugin_controller_generator.rb', line 19

def plugin_name
  @plugin_name
end

#plugin_pathObject (readonly)

Returns the value of attribute plugin_path


19
20
21
# File 'lib/generators/chiliproject_plugin_controller/chiliproject_plugin_controller_generator.rb', line 19

def plugin_path
  @plugin_path
end

#plugin_pretty_nameObject (readonly)

Returns the value of attribute plugin_pretty_name


19
20
21
# File 'lib/generators/chiliproject_plugin_controller/chiliproject_plugin_controller_generator.rb', line 19

def plugin_pretty_name
  @plugin_pretty_name
end

Instance Method Details

#destination_rootObject


30
31
32
# File 'lib/generators/chiliproject_plugin_controller/chiliproject_plugin_controller_generator.rb', line 30

def destination_root
  File.join(RAILS_ROOT, plugin_path)
end

#manifestObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/generators/chiliproject_plugin_controller/chiliproject_plugin_controller_generator.rb', line 34

def manifest
  record do |m|
    # Check for class naming collisions.
    m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"

    # Controller, helper, views, and test directories.
    m.directory File.join('app/controllers', class_path)
    m.directory File.join('app/helpers', class_path)
    m.directory File.join('app/views', class_path, file_name)
    m.directory File.join('test/functional', class_path)

    # Controller class, functional test, and helper class.
    m.template 'controller.rb.erb',
                File.join('app/controllers',
                          class_path,
                          "#{file_name}_controller.rb")

    m.template 'functional_test.rb.erb',
                File.join('test/functional',
                          class_path,
                          "#{file_name}_controller_test.rb")

    m.template 'helper.rb.erb',
                File.join('app/helpers',
                          class_path,
                          "#{file_name}_helper.rb")

    # View template for each action.
    actions.each do |action|
      path = File.join('app/views', class_path, file_name, "#{action}.html.erb")
      m.template 'view.html.erb', path,
        :assigns => { :action => action, :path => path }
    end
  end
end