Class Skates::Generator::ControllerGenerator
In: lib/skates/generator.rb
Parent: Templater::Generator

Generates a new controller, with the corresponding stanzas and routes.

Methods

Public Class methods

[Source]

    # File lib/skates/generator.rb, line 91
91:       def self.source_root
92:         File.join(File.dirname(__FILE__), '../../templates/skates/app/controllers')
93:       end

Public Instance methods

This is a hack since Templater doesn‘t offer any simple way to edit files right now…

[Source]

     # File lib/skates/generator.rb, line 105
105:       def add_route_for_actions_in_controller(actions, controller)
106:         sentinel = "Skates.router.draw do"
107:         router_path = "config/routes.rb"
108:         actions.each do |action|
109:           to_inject = "xpath(\"#{action[2]}\").to(:controller => \"#{controller}\", :action => \"#{action[0]}\").priority(#{action[1]})"
110:           if File.exist?(router_path)
111:             content = File.read(router_path).gsub(/(#{Regexp.escape(sentinel)})/mi){|match| "#{match}\n\t#{to_inject}"}
112:             File.open(router_path, 'wb') { |file| file.write(content) }
113:           end
114:         end
115:       end

[Source]

    # File lib/skates/generator.rb, line 95
95:       def controller_actions
96:         @controller_actions ||= actions_arg.map { |a| a.split(":") }
97:       end

[Source]

     # File lib/skates/generator.rb, line 99
 99:       def controller_class_name
100:         "#{controller_name.capitalize}Controller"
101:       end

[Validate]