Ramaze::Controller is the base controller of all controllers when developing applications in Ramaze. It acts as a nice wrapper around Innate::Node and allows for a more traditional MVC approach.
@example An example controller
class Posts < Ramaze::Controller map '/posts' def index end end
@author Michael Fellinger @since 04-01-2009
Hash containing the names of two common controller names and the URIs they should be mapped to.
@author Michael Fellinger @since 04-01-2009
Returns the application to which the controller belongs to.
@author Michael Fellinger @since 04-01-2009 @return [Ramaze::App]
# File lib/ramaze/controller.rb, line 185 185: def self.app 186: App[ancestral_trait[:app]] 187: end
Sets the view engine to use for pages with a content type of text/html.
@example
class Posts < Ramaze::Controller engine :etanni end
@author Michael Fellinger @since 04-01-2009 @param [#] name The name of the view engine to use.
# File lib/ramaze/controller.rb, line 121 121: def self.engine(name) 122: provide(:html, name.to_sym) 123: end
Generates a URI for the full namespace of a class. If a class is named A::B::C the URI would be /a/b/c.
@author Michael Fellinger @since 04-01-2009 @param [String] klass_name The name of the class for which to generate
the mapping, defaults to the current class.
@return [String]
# File lib/ramaze/controller.rb, line 146 146: def self.generate_mapping(klass_name = self.name) 147: chunks = klass_name.to_s.split(/::/) 148: return if chunks.empty? 149: 150: last = chunks.last 151: return IRREGULAR_MAPPING[last] if IRREGULAR_MAPPING.key?(last) 152: 153: last.sub!(/Controller$/, '') 154: '/' << chunks.map{|chunk| chunk.snake_case }.join('/') 155: end
Modifies the extending class so that it’s properly set up to be used as a controller.
@author Michael Fellinger @since 04-01-2009 @param [Class] into The class that extended Ramaze::Controller (or a sub
class).
# File lib/ramaze/controller.rb, line 58 58: def self.inherited(into) 59: Innate::Node.included(into) 60: into.helper(:layout) 61: CONTROLLER_LIST << into 62: into.trait :skip_node_map => true 63: end
Maps the current class to the specified location.
@author Michael Fellinger @since 04-01-2009 @param [String] location The URI to map the controller to. @param [String] app_name The name of the application the controller
belongs to.
# File lib/ramaze/controller.rb, line 166 166: def self.map(location, app_name = nil) 167: if app_name 168: trait :app => app_name 169: else 170: app_name = ancestral_trait[:app] 171: end 172: 173: trait :skip_controller_map => true 174: 175: App.find_or_create(app_name).map(location, self) 176: end
Returns the URI a controller is mapped to.
@author Michael Fellinger @since 04-01-2009 @return [String]
# File lib/ramaze/controller.rb, line 132 132: def self.mapping 133: Ramaze.to(self) 134: end
Returns all the options for the application the controller belongs to.
@author Michael Fellinger @since 04-01-2009 @return [Innate::Options]
# File lib/ramaze/controller.rb, line 196 196: def self.options 197: return unless app = self.app 198: app.options 199: end
Sets all the controllers up and loads a default controller in case no custom ones have been specified.
@author Michael Fellinger @since 04-01-2009
# File lib/ramaze/controller.rb, line 72 72: def self.setup 73: case CONTROLLER_LIST.size 74: when 0 75: require 'ramaze/controller/default' 76: when 1 77: controller = CONTROLLER_LIST.to_a.first 78: 79: begin 80: controller.mapping 81: rescue 82: controller.map '/' 83: end 84: 85: controller.setup_procedure 86: else 87: CONTROLLER_LIST.each do |list_controller| 88: list_controller.setup_procedure 89: end 90: end 91: end
Method that’s used to setup each controller, called by Ramaze::Controller.setup.
@author Michael Fellinger @since 04-01-2009
# File lib/ramaze/controller.rb, line 100 100: def self.setup_procedure 101: unless ancestral_trait[:provide_set] 102: engine(:etanni) 103: trait(:provide_set => false) 104: end 105: 106: map(generate_mapping(name)) unless trait[:skip_controller_map] 107: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.