Class: NoCms::Blocks::Zone
- Inherits:
-
Object
- Object
- NoCms::Blocks::Zone
- Defined in:
- app/models/no_cms/blocks/zone.rb
Overview
This class will manage all the information about a zone of a template where the blocks are allowed or not.
Constant Summary collapse
- DEFAULT_ZONE_CONFIGURATION =
{ blocks: [ ], lazy_blocks: [ ] }
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#allowed_layouts(nest_level = nil) ⇒ Object
This method returns a mix of the blocks allowed for this zone and the ones allowed for the template gobally.
- #human_name ⇒ Object
-
#initialize(name, config, template) ⇒ Zone
constructor
We receive a name, a zone configuration hash like the ones defined in the configuration files and the template object associated.
-
#is_lazy_layout?(layout) ⇒ Boolean
This method checks that the layout sent as param is configured as a lazy block in this zone or in the whole template.
- #to_param ⇒ Object
Constructor Details
#initialize(name, config, template) ⇒ Zone
We receive a name, a zone configuration hash like the ones defined in the configuration files and the template object associated
13 14 15 16 17 |
# File 'app/models/no_cms/blocks/zone.rb', line 13 def initialize name, config, template @config = DEFAULT_ZONE_CONFIGURATION.merge config @name = name @template = template end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'app/models/no_cms/blocks/zone.rb', line 5 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'app/models/no_cms/blocks/zone.rb', line 6 def name @name end |
Instance Method Details
#allowed_layouts(nest_level = nil) ⇒ Object
This method returns a mix of the blocks allowed for this zone and the ones allowed for the template gobally. We can also filter the layouts for a certain level
23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/no_cms/blocks/zone.rb', line 23 def allowed_layouts nest_level = nil @allowed_layouts = [config[:blocks], config[:lazy_blocks], @template.allowed_layouts].compact.flatten.uniq @allowed_layouts = NoCms::Blocks.block_layouts.keys if @allowed_layouts.blank? @allowed_layouts = @allowed_layouts.select do |layout_name| layout = NoCms::Blocks.block_layouts[layout_name] layout[:nest_levels].blank? || layout[:nest_levels].include?(nest_level) end unless nest_level.nil? @allowed_layouts end |
#human_name ⇒ Object
45 46 47 |
# File 'app/models/no_cms/blocks/zone.rb', line 45 def human_name I18n.t("no_cms.blocks.template_zones.#{self.name}") end |
#is_lazy_layout?(layout) ⇒ Boolean
This method checks that the layout sent as param is configured as a lazy block in this zone or in the whole template
37 38 39 |
# File 'app/models/no_cms/blocks/zone.rb', line 37 def is_lazy_layout? layout config[:lazy_blocks].map(&:to_s).include?(layout) || @template.is_lazy_layout?(layout) end |
#to_param ⇒ Object
41 42 43 |
# File 'app/models/no_cms/blocks/zone.rb', line 41 def to_param name end |