Module: Mack::Controller::ClassMethods

Defined in:
lib/mack/controller/controller.rb

Instance Method Summary collapse

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, options) # :nodoc:
  controller_filters[type.to_sym] << Mack::Controller::Filter.new(meth, self, options)
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, options = {})
  add_filter(:after, meth, options)
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, options = {})
  add_filter(:after_render, meth, options)
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, options = {})
  add_filter(:before, meth, options)
end

#controller_filtersObject

: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