Class: Maglev::Content::SectionContent
- Inherits:
-
Object
- Object
- Maglev::Content::SectionContent
show all
- Includes:
- ActiveModel::Model, EnhancedValueConcern
- Defined in:
- app/models/maglev/content/section_content.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#image, #image?, #label, #label?
Instance Attribute Details
#blocks ⇒ Object
Returns the value of attribute blocks.
9
10
11
|
# File 'app/models/maglev/content/section_content.rb', line 9
def blocks
@blocks
end
|
#definition ⇒ Object
Returns the value of attribute definition.
9
10
11
|
# File 'app/models/maglev/content/section_content.rb', line 9
def definition
@definition
end
|
#id ⇒ Object
Returns the value of attribute id.
9
10
11
|
# File 'app/models/maglev/content/section_content.rb', line 9
def id
@id
end
|
#lock_version ⇒ Object
Returns the value of attribute lock_version.
9
10
11
|
# File 'app/models/maglev/content/section_content.rb', line 9
def lock_version
@lock_version
end
|
#settings ⇒ Object
Returns the value of attribute settings.
9
10
11
|
# File 'app/models/maglev/content/section_content.rb', line 9
def settings
@settings
end
|
#theme_id ⇒ Object
Returns the value of attribute theme_id.
9
10
11
|
# File 'app/models/maglev/content/section_content.rb', line 9
def theme_id
@theme_id
end
|
#type ⇒ Object
Returns the value of attribute type.
9
10
11
|
# File 'app/models/maglev/content/section_content.rb', line 9
def type
@type
end
|
Class Method Details
.build(theme:, raw_section_content:) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'app/models/maglev/content/section_content.rb', line 71
def self.build(theme:, raw_section_content:)
new(
id: raw_section_content['id'],
definition: theme.sections.find(raw_section_content['type']),
type: raw_section_content['type'],
settings: Maglev::Content::SettingContent::AssociationProxy.new(raw_section_content['settings']),
theme_id: theme.id,
lock_version: raw_section_content['lock_version']
).tap do |section_content|
section_content.build_blocks(raw_section_content)
end
end
|
.build_many(theme:, content:) ⇒ Object
65
66
67
68
69
|
# File 'app/models/maglev/content/section_content.rb', line 65
def self.build_many(theme:, content:)
content.map do |raw_section_content|
build(theme: theme, raw_section_content: raw_section_content)
end
end
|
Instance Method Details
#block_definitions ⇒ Object
29
30
31
|
# File 'app/models/maglev/content/section_content.rb', line 29
def block_definitions
definition.blocks
end
|
#blocks? ⇒ Boolean
25
26
27
|
# File 'app/models/maglev/content/section_content.rb', line 25
def blocks?
blocks.present?
end
|
#blocks_label ⇒ Object
50
51
52
|
# File 'app/models/maglev/content/section_content.rb', line 50
def blocks_label
definition.human_blocks_label(::I18n.t('maglev.editor.section_blocks.breadcrumb'))
end
|
#build_blocks(raw_section_content) ⇒ Object
58
59
60
61
62
63
|
# File 'app/models/maglev/content/section_content.rb', line 58
def build_blocks(raw_section_content)
self.blocks = Maglev::Content::BlockContent::AssociationProxy.new(
section_content: self,
raw_blocks_content: raw_section_content['blocks']
)
end
|
#child_block_definitions_of(block_id) ⇒ Object
return the definitions of blocks that can be added as children of the given block
43
44
45
46
47
48
|
# File 'app/models/maglev/content/section_content.rb', line 43
def child_block_definitions_of(block_id)
accepted_block_types = blocks.find(block_id).accepted_child_types
definition.blocks.select do |block_definition|
accepted_block_types.include?(block_definition.type) && blocks.can_add?(block_definition.type)
end
end
|
#child_blocks_of(block_id) ⇒ Object
54
55
56
|
# File 'app/models/maglev/content/section_content.rb', line 54
def child_blocks_of(block_id)
blocks.select { |block| block.parent_id == block_id }
end
|
#persisted? ⇒ Boolean
11
12
13
|
# File 'app/models/maglev/content/section_content.rb', line 11
def persisted?
true
end
|
#root_block_definitions ⇒ Object
return the definitions of root blocks that can be added
38
39
40
|
# File 'app/models/maglev/content/section_content.rb', line 38
def root_block_definitions
definition.root_blocks.select { |block_definition| blocks.can_add?(block_definition.type) }
end
|
#root_blocks ⇒ Object
33
34
35
|
# File 'app/models/maglev/content/section_content.rb', line 33
def root_blocks
blocks.select(&:root?)
end
|
#sticky? ⇒ Boolean
15
16
17
|
# File 'app/models/maglev/content/section_content.rb', line 15
def sticky?
definition.viewport_fixed_position?
end
|
#type_name ⇒ Object
21
22
23
|
# File 'app/models/maglev/content/section_content.rb', line 21
def type_name
definition.human_name
end
|