Module: MotionPrime::ScreenSectionsMixin

Extended by:
MotionSupport::Concern
Includes:
HasClassFactory, HasNormalizer
Included in:
ScreenBaseMixin
Defined in:
motion-prime/screens/_sections_mixin.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasNormalizer

#normalize_object, #normalize_options

Methods included from HasClassFactory

#camelize_factory, #class_factory, #low_camelize_factory

Class Method Details

.included(base) ⇒ Object



8
9
10
# File 'motion-prime/screens/_sections_mixin.rb', line 8

def self.included(base)
  base.class_attribute :_section_options
end

Instance Method Details

#add_sectionsObject



12
13
14
15
# File 'motion-prime/screens/_sections_mixin.rb', line 12

def add_sections
  create_sections
  render_sections
end

#create_section(options) ⇒ Object



26
27
28
29
30
# File 'motion-prime/screens/_sections_mixin.rb', line 26

def create_section(options)
  section_class = class_factory("#{options.delete(:name)}_section")
  options = normalize_options(options).merge(screen: self)
  section_class.new(options)
end

#create_sectionsObject



17
18
19
20
21
22
23
24
# File 'motion-prime/screens/_sections_mixin.rb', line 17

def create_sections
  section_options = self.class._section_options
  return unless section_options
  @sections = {}
  section_options.map do |name, options|
    @sections[name] = create_section(options.clone)
  end
end

#main_sectionObject



42
43
44
# File 'motion-prime/screens/_sections_mixin.rb', line 42

def main_section
  @main_section || @sections.first
end

#render_sectionsObject



32
33
34
35
36
37
38
39
40
# File 'motion-prime/screens/_sections_mixin.rb', line 32

def render_sections
  return unless @sections
  if @sections.count > 1
    @main_section = MotionPrime::TableSection.new(model: @sections.values, screen: self)
    @main_section.render
  else
    @sections.first.render
  end
end