Class: Locomotive::Steam::Liquid::Drops::Section
- Inherits:
-
Liquid::Drop
- Object
- Liquid::Drop
- Locomotive::Steam::Liquid::Drops::Section
- Defined in:
- lib/locomotive/steam/liquid/drops/section.rb
Instance Method Summary collapse
- #anchor_id ⇒ Object
- #blocks ⇒ Object
- #blocks_as_tree ⇒ Object
- #css_class ⇒ Object
- #editor_setting_data ⇒ Object
-
#id ⇒ Object
FIXME: id acts as the domID to build HTML tags.
- #id=(id) ⇒ Object
-
#initialize(section, content) ⇒ Section
constructor
A new instance of Section.
- #locomotive_attributes ⇒ Object
- #settings ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(section, content) ⇒ Section
Returns a new instance of Section.
8 9 10 11 12 13 14 15 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 8 def initialize(section, content) @section = section @content = content if @content.blank? @content = section.definition['default'] || { 'settings' => {}, 'blocks' => [] } end end |
Instance Method Details
#anchor_id ⇒ Object
41 42 43 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 41 def anchor_id "#{@content['anchor'] || id}-section" end |
#blocks ⇒ Object
53 54 55 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 53 def blocks build_blocks(@content['blocks']) end |
#blocks_as_tree ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 57 def blocks_as_tree [].tap do |root| parents = [] build_blocks(@content['blocks']) do |block, previous_block| if block.depth == 0 parents = [block] root elsif block.depth > previous_block.depth (parents << previous_block).last.leaves elsif (diff = previous_block.depth - block.depth) > 0 parents[parents.size - diff - 1].tap { parents.pop(diff) }.leaves else parents.last.leaves end << block end end end |
#css_class ⇒ Object
37 38 39 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 37 def css_class @section.definition['class'] end |
#editor_setting_data ⇒ Object
76 77 78 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 76 def editor_setting_data SectionEditorSettingData.new(@section) end |
#id ⇒ Object
FIXME: id acts as the domID to build HTML tags
18 19 20 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 18 def id @content['id'] end |
#id=(id) ⇒ Object
22 23 24 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 22 def id=(id) @content['id'] = id end |
#locomotive_attributes ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 45 def locomotive_attributes %(data-locomotive-section-id="#{id}" data-locomotive-section-type="#{type}").tap do # let Steam know that we won't need to wrap the section HTML # into an extra DIV layer. @context['is_section_locomotive_attributes_displayed'] = true end end |
#settings ⇒ Object
30 31 32 33 34 35 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 30 def settings @content_proxy ||= SectionContentProxy.new( @content['settings'] || {}, @section.definition['settings'] || [] ) end |
#type ⇒ Object
26 27 28 |
# File 'lib/locomotive/steam/liquid/drops/section.rb', line 26 def type @section.type end |