Class: Ramaze::Controller
- Inherits:
-
Object
- Object
- Ramaze::Controller
- Includes:
- Innate::Node, Innate::Traited
- Defined in:
- lib/ramaze/controller.rb
Overview
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.
Direct Known Subclasses
Constant Summary
- CONTROLLER_LIST =
Set.new
- IRREGULAR_MAPPING =
Hash containing the names of two common controller names and the URIs they should be mapped to.
{ 'Controller' => nil, 'MainController' => '/' }
Constants included from Innate::Node
Instance Attribute Summary
Attributes included from Innate::Node
#layout_templates, #method_arities, #view_templates
Class Method Summary (collapse)
-
+ (Ramaze::App) app
Returns the application to which the controller belongs to.
-
+ (Object) engine(name)
Sets the view engine to use for pages with a content type of text/html.
-
+ (String) generate_mapping(klass_name = self.name)
Generates a URI for the full namespace of a class.
-
+ (Object) inherited(into)
Modifies the extending class so that it's properly set up to be used as a controller.
-
+ (Object) map(location, app_name = nil)
Maps the current class to the specified location.
-
+ (String) mapping
Returns the URI a controller is mapped to.
-
+ (Innate::Options) options
Returns all the options for the application the controller belongs to.
-
+ (Object) setup
Sets all the controllers up and loads a default controller in case no custom ones have been specified.
-
+ (Object) setup_procedure
Method that's used to setup each controller, called by Ramaze::Controller.setup.
Methods included from Innate::Node
#action_found, #action_missing, #alias_view, #binding, #call, #fill_action, #find_aliased_view, #find_layout, #find_method, #find_provide, #find_view, included, #layout, #layout_mappings, #map, #map_layouts, #map_views, #mapping, #needs_method?, #options, #patterns_for, #possible_exts_for, #possible_paths_for, #provide, #provide_handlers, #provide_set?, #provides, #resolve, #root_mappings, #to_layout, #to_template, #to_view, #try_resolve, #update_layout_mappings, #update_mapping_shared, #update_method_arities, #update_template_mappings, #update_view_mappings, #view_mappings
Methods included from Innate::Traited
#ancestral_trait, #ancestral_trait_values, #class_trait, #each_ancestral_trait, included, #trait
Class Method Details
+ (Ramaze::App) app
Returns the application to which the controller belongs to.
192 193 194 |
# File 'lib/ramaze/controller.rb', line 192 def self.app App[ancestral_trait[:app]] end |
+ (Object) engine(name)
Sets the view engine to use for pages with a content type of text/html.
121 122 123 |
# File 'lib/ramaze/controller.rb', line 121 def self.engine(name) provide(:html, name.to_sym) end |
+ (String) generate_mapping(klass_name = self.name)
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.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ramaze/controller.rb', line 146 def self.generate_mapping(klass_name = self.name) chunks = klass_name.to_s.split(/::/) return if chunks.empty? last = chunks.last if IRREGULAR_MAPPING.key?(last) irregular = IRREGULAR_MAPPING[last] return irregular if irregular.nil? || chunks.size == 1 chunks.pop chunks << irregular end chunks.unshift '' chunks.last.sub!(/Controller$/, '') chunks.map{|chunk| chunk.snake_case }.join('/').squeeze('/') end |
+ (Object) inherited(into)
Modifies the extending class so that it's properly set up to be used as a controller.
58 59 60 61 62 63 |
# File 'lib/ramaze/controller.rb', line 58 def self.inherited(into) Innate::Node.included(into) into.helper(:layout) CONTROLLER_LIST << into into.trait :skip_node_map => true end |
+ (Object) map(location, app_name = nil)
Maps the current class to the specified location.
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/ramaze/controller.rb', line 173 def self.map(location, app_name = nil) if app_name trait :app => app_name else app_name = ancestral_trait[:app] end trait :skip_controller_map => true App.find_or_create(app_name).map(location, self) end |
+ (String) mapping
Returns the URI a controller is mapped to.
132 133 134 |
# File 'lib/ramaze/controller.rb', line 132 def self.mapping Ramaze.to(self) end |
+ (Innate::Options) options
Returns all the options for the application the controller belongs to.
203 204 205 206 |
# File 'lib/ramaze/controller.rb', line 203 def self. return unless app = self.app app. end |
+ (Object) setup
Sets all the controllers up and loads a default controller in case no custom ones have been specified.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ramaze/controller.rb', line 72 def self.setup case CONTROLLER_LIST.size when 0 require 'ramaze/controller/default' when 1 controller = CONTROLLER_LIST.to_a.first begin controller.mapping rescue controller.map '/' end controller.setup_procedure else CONTROLLER_LIST.each do |list_controller| list_controller.setup_procedure end end end |
+ (Object) setup_procedure
Method that's used to setup each controller, called by Ramaze::Controller.setup.
100 101 102 103 104 105 106 107 |
# File 'lib/ramaze/controller.rb', line 100 def self.setup_procedure unless ancestral_trait[:provide_set] engine(:etanni) trait(:provide_set => false) end map(generate_mapping(name)) unless trait[:skip_controller_map] end |