Class Babylon::Generator::ControllerGenerator
In: lib/babylon/generator.rb
Parent: Templater::Generator

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

Methods

Public Class methods

[Source]

    # File lib/babylon/generator.rb, line 88
88:       def self.source_root
89:         File.join(File.dirname(__FILE__), '../../templates/babylon/app/controllers')
90:       end

Public Instance methods

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

[Source]

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

[Source]

    # File lib/babylon/generator.rb, line 92
92:       def controller_actions
93:         @controller_actions ||= actions_arg.map { |a| a.split(":") }
94:       end

[Source]

    # File lib/babylon/generator.rb, line 96
96:       def controller_class_name
97:         "#{controller_name.capitalize}Controller"
98:       end

[Validate]