Module: MotionPrime::ScreenSectionsMixin
Defined Under Namespace
Modules: ClassMethods
Class Method Summary
collapse
Instance Method Summary
collapse
#normalize_object, #normalize_options
#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_sections ⇒ Object
12
13
14
15
|
# File 'motion-prime/screens/_sections_mixin.rb', line 12
def add_sections
create_sections
render_sections
end
|
#all_sections ⇒ Object
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_sections ⇒ Object
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_section ⇒ Object
47
48
49
|
# File 'motion-prime/screens/_sections_mixin.rb', line 47
def main_section
@main_section || all_sections.first
end
|
#render_sections ⇒ Object
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
|