Class: Spree::PageSection
- Inherits:
-
Object
- Object
- Spree::PageSection
show all
- Includes:
- HasPageLinks
- Defined in:
- app/models/spree/page_section.rb
Direct Known Subclasses
Spree::PageSections::AnnouncementBar, Spree::PageSections::Breadcrumbs, Spree::PageSections::CollectionBanner, Spree::PageSections::CustomCode, Spree::PageSections::FeaturedPosts, Spree::PageSections::FeaturedProduct, Spree::PageSections::FeaturedTaxon, Spree::PageSections::FeaturedTaxons, Spree::PageSections::Footer, Spree::PageSections::Header, Spree::PageSections::ImageBanner, Spree::PageSections::ImageWithText, Spree::PageSections::MainPasswordFooter, Spree::PageSections::MainPasswordHeader, Spree::PageSections::Newsletter, Spree::PageSections::PageTitle, Spree::PageSections::PostDetails, Spree::PageSections::PostGrid, Spree::PageSections::ProductDetails, Spree::PageSections::ProductGrid, Spree::PageSections::RelatedProducts, Spree::PageSections::RichText, Spree::PageSections::TaxonBanner, Spree::PageSections::TaxonGrid, Spree::PageSections::Video
Constant Summary
collapse
- TEXT_COLOR_DEFAULT =
nil
- BACKGROUND_COLOR_DEFAULT =
nil
- BORDER_COLOR_DEFAULT =
nil
- TOP_PADDING_DEFAULT =
40
- BOTTOM_PADDING_DEFAULT =
40
- TOP_BORDER_WIDTH_DEFAULT =
1
- BOTTOM_BORDER_WIDTH_DEFAULT =
0
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.role ⇒ Object
this should be overridden in subclasses content - can be managed by the user system - main parts of the page eg.
Instance Method Summary
collapse
Instance Attribute Details
#default_blocks ⇒ Object
this should be overridden in subclasses
80
81
82
|
# File 'app/models/spree/page_section.rb', line 80
def default_blocks
@default_blocks
end
|
Class Method Details
.role ⇒ Object
this should be overridden in subclasses content - can be managed by the user system - main parts of the page eg. product details, login form header - header section footer - footer section
101
102
103
|
# File 'app/models/spree/page_section.rb', line 101
def self.role
'content'
end
|
Instance Method Details
#available_blocks_to_add ⇒ Object
88
89
90
|
# File 'app/models/spree/page_section.rb', line 88
def available_blocks_to_add
[]
end
|
#blocks_available? ⇒ Boolean
84
85
86
|
# File 'app/models/spree/page_section.rb', line 84
def blocks_available?
false
end
|
#can_be_deleted? ⇒ Boolean
121
122
123
|
# File 'app/models/spree/page_section.rb', line 121
def can_be_deleted?
role == 'content'
end
|
#can_be_sorted? ⇒ Boolean
125
126
127
|
# File 'app/models/spree/page_section.rb', line 125
def can_be_sorted?
true
end
|
#can_sort_blocks? ⇒ Boolean
92
93
94
|
# File 'app/models/spree/page_section.rb', line 92
def can_sort_blocks?
false
end
|
#copy_rich_text_fields_from(other) ⇒ Object
143
144
145
146
147
|
# File 'app/models/spree/page_section.rb', line 143
def copy_rich_text_fields_from(other)
rich_text_fields.each do |field|
send(field).body = other.send(field).body
end
end
|
#deep_clone(target) ⇒ Object
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'app/models/spree/page_section.rb', line 149
def deep_clone(target)
new_section = type.constantize.new(
preferences: preferences,
position: position,
pageable: target
)
new_section.copy_rich_text_fields_from(self)
new_section.do_not_create_blocks = true
new_section.do_not_create_links = true
new_section.save!
new_section.asset.attach(asset.blob) if asset.attached?
blocks.includes(:links, asset_attachment: :blob).each do |block|
new_block = block.type.constantize.new(
preferences: block.preferences,
position: block.position,
section: new_section
)
new_block.do_not_create_links = true
new_block.text = block.text if block.respond_to?(:text) new_block.save!
new_block.asset.attach(block.asset.blob) if block.asset.attached?
deep_clone_links(block, new_block)
end
deep_clone_links(self, new_section)
end
|
#deep_clone_links(section_or_block, new_section_or_block) ⇒ Object
180
181
182
183
184
185
186
|
# File 'app/models/spree/page_section.rb', line 180
def deep_clone_links(section_or_block, new_section_or_block)
section_or_block.links.each do |link|
new_link = link.dup
new_link.parent = new_section_or_block
new_link.save!
end
end
|
#display_name ⇒ Object
201
202
203
|
# File 'app/models/spree/page_section.rb', line 201
def display_name
name
end
|
#dup ⇒ Object
190
191
192
193
194
|
# File 'app/models/spree/page_section.rb', line 190
def dup
super.tap do |object|
object.copy_rich_text_fields_from(self)
end
end
|
#icon_name ⇒ Object
117
118
119
|
# File 'app/models/spree/page_section.rb', line 117
def icon_name
'text-caption'
end
|
#lazy? ⇒ Boolean
129
130
131
|
# File 'app/models/spree/page_section.rb', line 129
def lazy?
false
end
|
#lazy_path(variables) ⇒ Object
133
134
135
136
137
|
# File 'app/models/spree/page_section.rb', line 133
def lazy_path(variables)
url_options = variables[:url_options] || {}
Spree::Core::Engine.routes.url_helpers.page_section_path(self, **url_options)
end
|
#restore_design_settings_to_defaults ⇒ Object
196
197
198
199
|
# File 'app/models/spree/page_section.rb', line 196
def restore_design_settings_to_defaults
restore_preferences_for(design_settings_to_restore)
save
end
|
#rich_text_fields ⇒ Object
139
140
141
|
# File 'app/models/spree/page_section.rb', line 139
def rich_text_fields
self.class.rich_text_association_names.map { |rt| rt.to_s.sub('rich_text_', '') }
end
|
#role ⇒ Object
105
106
107
|
# File 'app/models/spree/page_section.rb', line 105
def role
self.class.role
end
|
#theme ⇒ Object
109
110
111
112
113
114
115
|
# File 'app/models/spree/page_section.rb', line 109
def theme
@theme ||= if pageable.is_a?(Spree::Theme)
pageable
else
pageable.theme
end
end
|
#to_partial_path ⇒ Object
75
76
77
|
# File 'app/models/spree/page_section.rb', line 75
def to_partial_path
"spree/page_sections/#{type.to_s.demodulize.underscore}"
end
|