Class: SirTrevorRails::Blocks::FeaturedPagesBlock

Inherits:
SirTrevorRails::Block show all
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

#parent, #type

Instance Method Summary collapse

Methods included from Displayable

#item_ids, #items, #ordered_items

Methods inherited from SirTrevorRails::Block

block_class, block_class!, 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_jsonObject

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 page_options(id)
  (items.detect { |x| x[:id] == id }) || {}
end

#pagesObject



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

Returns:

  • (Boolean)


20
21
22
# File 'app/models/sir_trevor_rails/blocks/featured_pages_block.rb', line 20

def pages?
  !pages.empty?
end