Module: Mack::Controller::ClassMethods
- Defined in:
- lib/mack/controller/controller.rb
Instance Method Summary collapse
-
#add_filter(type, meth, options) ⇒ Object
:nodoc:.
-
#after_filter(meth, options = {}) ⇒ Object
See Mack::Controller::Filter for more information.
-
#after_render_filter(meth, options = {}) ⇒ Object
See Mack::Controller::Filter for more information.
-
#before_filter(meth, options = {}) ⇒ Object
See Mack::Controller::Filter for more information.
-
#controller_filters ⇒ Object
:nodoc:.
-
#layout(lay) ⇒ Object
Sets a layout to be used by a particular controller.
Instance Method Details
#add_filter(type, meth, options) ⇒ Object
:nodoc:
310 311 312 |
# File 'lib/mack/controller/controller.rb', line 310 def add_filter(type, meth, ) # :nodoc: controller_filters[type.to_sym] << Mack::Controller::Filter.new(meth, self, ) end |
#after_filter(meth, options = {}) ⇒ Object
See Mack::Controller::Filter for more information.
301 302 303 |
# File 'lib/mack/controller/controller.rb', line 301 def after_filter(meth, = {}) add_filter(:after, meth, ) end |
#after_render_filter(meth, options = {}) ⇒ Object
See Mack::Controller::Filter for more information.
306 307 308 |
# File 'lib/mack/controller/controller.rb', line 306 def after_render_filter(meth, = {}) add_filter(:after_render, meth, ) end |
#before_filter(meth, options = {}) ⇒ Object
See Mack::Controller::Filter for more information.
296 297 298 |
# File 'lib/mack/controller/controller.rb', line 296 def before_filter(meth, = {}) add_filter(:before, meth, ) end |
#controller_filters ⇒ Object
:nodoc:
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/mack/controller/controller.rb', line 314 def controller_filters # :nodoc: unless @controller_filters @controller_filters = {:before => [], :after => [], :after_render => []} # inherit filters from the superclass, if any, to this parent sc = self.superclass if sc.class_is_a?(Mack::Controller) ch = sc.controller_filters [:before, :after, :after_render].each do |v| @controller_filters[v] << ch[v] @controller_filters[v].flatten! @controller_filters[v].uniq! end end end @controller_filters end |
#layout(lay) ⇒ Object
Sets a layout to be used by a particular controller.
Example:
class MyAwesomeController
include Mack::Controller
# Sets all actions to use: "#{Mack.root}/app/views/layouts/dark.html.erb" as they're layout.
layout :dark
def index
# Sets this action to use: "#{Mack.root}/app/views/layouts/bright.html.erb" as it's layout.
render(:text, "Welcome...", :layout => :bright)
end
def index
# This will no use a layout.
render(:text, "Welcome...", :layout => false)
end
end
The default layout is “#/app/views/layouts/application.<format>.erb”.
352 353 354 355 356 357 358 |
# File 'lib/mack/controller/controller.rb', line 352 def layout(lay) self.class_eval do define_method(:layout) do lay end end end |