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

#all_sectionsObject



17
18
19
# File 'motion-prime/screens/_sections_mixin.rb', line 17

def all_sections
  @sections.values
end

#create_section(options) ⇒ Object



31
32
33
34
35
# File 'motion-prime/screens/_sections_mixin.rb', line 31

def create_section(options)
  section_class = class_factory("#{options.delete(:name)}_section")
  options = normalize_options(options).merge(screen: self)
  !options.has_key?(:if) || options[:if] ? section_class.new(options) : nil
end

#create_sectionsObject



21
22
23
24
25
26
27
28
29
# File 'motion-prime/screens/_sections_mixin.rb', line 21

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

#main_sectionObject



47
48
49
# File 'motion-prime/screens/_sections_mixin.rb', line 47

def main_section
  @main_section || all_sections.first
end

#render_sectionsObject



37
38
39
40
41
42
43
44
45
# File 'motion-prime/screens/_sections_mixin.rb', line 37

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