Class: SirTrevorRails::Blocks::FeaturedPagesBlock
- Inherits:
-
SirTrevorRails::Block
- Object
- OpenStruct
- SirTrevorRails::Block
- SirTrevorRails::Blocks::FeaturedPagesBlock
- Includes:
- Displayable
- Defined in:
- app/models/sir_trevor_rails/blocks/featured_pages_block.rb
Overview
Multi-up featured page block
Constant Summary
Constants inherited from SirTrevorRails::Block
SirTrevorRails::Block::DEFAULT_FORMAT
Instance Attribute Summary
Attributes inherited from SirTrevorRails::Block
Instance Method Summary collapse
-
#as_json ⇒ Object
rubocop:disable Metrics/MethodLength.
- #page_options(id) ⇒ Object
- #pages ⇒ Object
- #pages? ⇒ Boolean
Methods included from Displayable
#item_ids, #items, #ordered_items
Methods inherited from SirTrevorRails::Block
#alt_text?, alt_text?, block_class, block_class!, custom_block_type_alt_text_settings, custom_block_types, #format, from_hash, #initialize, #to_partial_path, type_klass
Constructor Details
This class inherits a constructor from SirTrevorRails::Block
Instance Method Details
#as_json ⇒ Object
rubocop:disable Metrics/MethodLength
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/sir_trevor_rails/blocks/featured_pages_block.rb', line 25 def as_json(*) result = super result[:data][:item] ||= {} result[:data][:item].transform_values! do |v| begin v['thumbnail_image_url'] = parent.exhibit.pages.for_default_locale.find(v['id']).thumbnail_image_url rescue ActiveRecord::RecordNotFound v = nil end v end result[:data][:item].compact! result end |
#page_options(id) ⇒ Object
10 11 12 |
# File 'app/models/sir_trevor_rails/blocks/featured_pages_block.rb', line 10 def (id) (items.detect { |x| x[:id] == id }) || {} end |
#pages ⇒ Object
14 15 16 17 18 |
# File 'app/models/sir_trevor_rails/blocks/featured_pages_block.rb', line 14 def pages @pages ||= parent.exhibit.pages.for_default_locale.published.where(slug: item_ids).sort do |a, b| ordered_items.index(a.slug) <=> ordered_items.index(b.slug) end end |
#pages? ⇒ Boolean
20 21 22 |
# File 'app/models/sir_trevor_rails/blocks/featured_pages_block.rb', line 20 def pages? !pages.empty? end |