Class: Nsweb::Generators::ControllerGenerator
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #create_controller ⇒ Object
-
#initialize(*args, &block) ⇒ ControllerGenerator
constructor
A new instance of ControllerGenerator.
Methods inherited from Base
Constructor Details
#initialize(*args, &block) ⇒ ControllerGenerator
Returns a new instance of ControllerGenerator.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/generators/nsweb/controller/controller_generator.rb', line 10 def initialize(*args, &block) super @controller_actions = [] actions.each do |action| @controller_actions << action @controller_actions << 'create' if action.eql?( 'new' ) @controller_actions << 'update' if action.eql?( 'edit' ) end @controller_actions.uniq! @controller_actions = all_actions if @controller_actions.empty? end |
Instance Method Details
#create_controller ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/generators/nsweb/controller/controller_generator.rb', line 24 def create_controller template 'controller.rb', File.join(plugin_path, 'app/controllers', "#{plural_file_path}_controller.rb") if test_framework == :rspec template 'tests/rspec.rb', File.join('spec', plugin_path, 'controllers', "#{plural_file_path}_controller_spec.rb") else end unless .skip_helper? template 'helper.rb', File.join(plugin_path, 'app/helpers', "#{plural_file_path}_helper.rb") end controller_actions.each do |action| if %w[index show new edit].include?(action) template "views/#{action}.html.erb", File.join(plugin_path, "app/views/#{file_name}/#{action}.html.erb") end end template 'views/_form.html.erb', File.join(plugin_path, "app/views/#{file_name}/_form.html.erb") if class_path.length < 0 plugin_route("resources #{plural_file_name.to_sym.inspect}, :controller => '#{(class_path + [plural_name]).join('/')}") else plugin_route("resources #{plural_name.to_sym.inspect}") end end |