engine/lib/locomotive/action_controller/section_helpers.rb

33 lines
711 B
Ruby
Raw Normal View History

module Locomotive
module ActionController
module SectionHelpers
extend ActiveSupport::Concern
module InstanceMethods
def sections(key = nil)
if !key.nil? && key.to_sym == :sub
@locomotive_sections[:sub] || self.controller_name.dasherize
else
@locomotive_sections[:main]
end
end
end
module ClassMethods
def sections(main, sub = nil)
before_filter do |c|
sub = sub.call(c) if sub.respond_to?(:call)
sections = { :main => main, :sub => sub }
c.instance_variable_set(:@locomotive_sections, sections)
end
end
end
end
end
end