Module: ViewDriver::ActionControllerExtensions::ClassMethods

Defined in:
lib/view_driver/action_controller_extensions.rb

Instance Method Summary collapse

Instance Method Details

#default_section_templates(section, action_name) ⇒ Object



51
52
53
# File 'lib/view_driver/action_controller_extensions.rb', line 51

def default_section_templates(section, action_name)
  [action_name, 'default'].map{|action| controller_path + "/#{action}_#{section}"} + [ViewDriver::SECTIONS_DIR + "/default_#{section}"]
end

#sections(*args) ⇒ Object

Filter to define sections in a controller

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/view_driver/action_controller_extensions.rb', line 14

def sections(*args)
  method = "_sections_#{args.to_s.gsub(/[^a-z_]/, '_')}"
  options = args.extract_options!
  raise(ArgumentError, "Only one argument is allowed") if args.size > 1

  before_filter method, options.slice(*FILTER_OPTIONS)

  define_method method do        
    @sections_collection ||= SectionsCollection.new(self)
    section_templates = options.except(*FILTER_OPTIONS)
    section_templates.each{|k,v| section_templates[k] = parse_argument_for_sections(v)}
    @sections_collection << Sections.new(parse_argument_for_sections(args.first), section_templates)
  end

  protected method.to_sym
end

#sublayout(*args) ⇒ Object

Filter to define a sublayout in a controller



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/view_driver/action_controller_extensions.rb', line 32

def sublayout(*args)
  method = "_sublayout_#{args.to_s.gsub(/[^a-z_]/, '_')}"
  options = args.extract_options!

  before_filter method, options.slice(*FILTER_OPTIONS)

  define_method method do
    @sublayout = case (sublayout = args.first)
      when Symbol
        send(sublayout)
      when Proc
        sublayout.call(self)
      else
        sublayout
    end
  end
  protected method.to_sym
end