Class: NoCms::Blocks::BlockSlot

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/no_cms/blocks/block_slot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dup_block_when_duping_slotObject

This configuration is received via an attr_accessor because we can’t modify the dup method signature, as it would be non-compatible with the standard dup method from Ruby



71
72
73
# File 'app/models/no_cms/blocks/block_slot.rb', line 71

def dup_block_when_duping_slot
  @dup_block_when_duping_slot
end

Instance Method Details

#block_layout_belongs_to_template?Boolean

This method checks that the block layout is valid in the context of the contaienr template and the slot zone (if they have restrictions)

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
# File 'app/models/no_cms/blocks/block_slot.rb', line 51

def block_layout_belongs_to_template?
  if template_zone_config
    template_zone_config.allowed_layouts.map(&:to_s).include?(block.layout.to_s)
  else
    # If there's no template configuration that means we have no
    # restrictions and must return true always
    true
  end
end

#dupObject

In the dup implementation we check for the value of the ‘dup_block_when_duping_slot` virtual attribute and then dup the block instead of linking to the same instance.



77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/no_cms/blocks/block_slot.rb', line 77

def dup
  dupped = super
  (dupped.block = block.dup) if dup_block_when_duping_slot
  children.each do |child|
    # The child dup with children asign, will change the child parent
    # and the ensure_container callback, will set the right container
    child.dup_block_when_duping_slot = dup_block_when_duping_slot
    dupped.children << child.dup
  end
  dupped
end

#ensure_containerObject



27
28
29
# File 'app/models/no_cms/blocks/block_slot.rb', line 27

def ensure_container
  self.container = parent.container if parent
end

#template_zone_configObject



17
18
19
20
21
# File 'app/models/no_cms/blocks/block_slot.rb', line 17

def template_zone_config
  if container && container.class.include?(NoCms::Blocks::Concerns::ModelWithTemplate)
    container.template_config.zone(template_zone)
  end
end