Class: Workarea::Content::Block
- Inherits:
-
Object
- Object
- Workarea::Content::Block
- Includes:
- ApplicationDocument, Ordering, Releasable
- Defined in:
- app/models/workarea/content/block.rb
Overview
This class represents a single block of content. These are grouped by their area field for display in the storefront.
The actual HTML rendered is defined by the type field. This field is used to decide which partial is used to display for storefront. The data field is passed to the partial as local assigns.
This flexibility makes it very easy to add a new type to the system: 1) Define the block type using the DSL (Workarea.define_content_block_types) 2) Add the storefront partial, e.g. workarea/storefront/content_blocks/types/_foo.html.haml
Instance Attribute Summary collapse
-
#area ⇒ String
What area on the page this block belongs to.
- #content ⇒ Content
-
#data ⇒ HashWithIndifferentAccess
The bag of data used to render this content block on the storefront.
-
#hidden_breakpoints ⇒ Array
The breakpoints for which the block will be hidden.
-
#type_id ⇒ Symbol
The content block type id.
Instance Method Summary collapse
-
#at_bottom? ⇒ Boolean
Whether this block is at the top of the blocks list.
-
#at_top? ⇒ Boolean
Whether this block is at the top of the blocks list.
-
#config ⇒ HashWithIndifferentAccess
Any miscellaneous config set on the #type by the content block DSL.
-
#name ⇒ String
Tries to find a unique name for this block relative to the other blocks in the content area.
- #to_draft ⇒ Object
-
#type ⇒ Workarea::Content::BlockType
The BlockType that this block is.
- #type=(value) ⇒ Object
Methods included from Ordering
#higher_siblings, #lower_siblings
Methods included from Releasable
#changesets_with_children, #destroy, #in_release, #release_changes, #release_originals, #save_changeset, #skip_changeset, #without_release
Methods included from Segmentable
#active?, #active_segment_ids_with_children, #segmented?, #segments
Methods included from Release::Activation
#activate_with?, #create_activation_changeset, #save_activate_with, #was_active?
Methods included from ApplicationDocument
Methods included from Sidekiq::Callbacks
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
Methods included from Mongoid::Document
Instance Attribute Details
#area ⇒ String
Returns what area on the page this block belongs to.
27 |
# File 'app/models/workarea/content/block.rb', line 27 field :area, type: String, default: 'default' |
#content ⇒ Content
45 46 47 |
# File 'app/models/workarea/content/block.rb', line 45 :content, class_name: 'Workarea::Content', inverse_of: :blocks |
#data ⇒ HashWithIndifferentAccess
The bag of data used to render this content block on the storefront. Any relevant data for rendering can be stored here. All data will be typecasted and validated by the Field system.
32 33 34 35 |
# File 'app/models/workarea/content/block.rb', line 32 field :data, type: HashWithIndifferentAccess, default: HashWithIndifferentAccess.new, localize: true |
#hidden_breakpoints ⇒ Array
Returns the breakpoints for which the block will be hidden.
40 |
# File 'app/models/workarea/content/block.rb', line 40 field :hidden_breakpoints, type: Array, default: [] |
#type_id ⇒ Symbol
Returns the content block type id.
22 |
# File 'app/models/workarea/content/block.rb', line 22 field :type_id, type: Symbol |
Instance Method Details
#at_bottom? ⇒ Boolean
Whether this block is at the top of the blocks list
126 127 128 |
# File 'app/models/workarea/content/block.rb', line 126 def at_bottom? self == siblings.select(&:active?).last end |
#at_top? ⇒ Boolean
Whether this block is at the top of the blocks list
118 119 120 |
# File 'app/models/workarea/content/block.rb', line 118 def at_top? self == siblings.select(&:active?).first end |
#config ⇒ HashWithIndifferentAccess
Any miscellaneous config set on the #type by the content block DSL.
110 111 112 |
# File 'app/models/workarea/content/block.rb', line 110 def config type.config.with_indifferent_access end |
#name ⇒ String
Tries to find a unique name for this block relative to the other blocks in the content area.
63 64 65 |
# File 'app/models/workarea/content/block.rb', line 63 def name BlockName.new(self).to_s end |
#to_draft ⇒ Object
130 131 132 133 134 |
# File 'app/models/workarea/content/block.rb', line 130 def to_draft result = Content::BlockDraft.instantiate(as_document.merge('content_id' => _parent.id)) result.new_record = true result end |
#type ⇒ Workarea::Content::BlockType
The Workarea::Content::BlockType that this block is. See documentation for Workarea.define_content_block_types for info how to define block types.
98 99 100 |
# File 'app/models/workarea/content/block.rb', line 98 def type Configuration::ContentBlocks.types.detect { |bt| bt.id == type_id } end |
#type=(value) ⇒ Object
102 103 104 |
# File 'app/models/workarea/content/block.rb', line 102 def type=(value) self.type_id = value.is_a?(BlockType) ? value.id : value end |