Class: SirTrevorRails::Blocks::FeaturedPagesBlock

Inherits:
SirTrevorRails::Block
  • Object
show all
Includes:
Displayable
Defined in:
app/models/sir_trevor_rails/blocks/featured_pages_block.rb

Overview

Multi-up featured page block

Instance Method Summary collapse

Methods included from Displayable

#item_ids, #items, #ordered_items

Instance Method Details

#as_jsonObject



22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/sir_trevor_rails/blocks/featured_pages_block.rb', line 22

def as_json
  result = super

  result[:data][:item] ||= {}

  result[:data][:item].each_value do |v|
    v['thumbnail_image_url'] = parent.exhibit.pages.find(v['id']).thumbnail_image_url
  end

  result
end

#page_options(id) ⇒ Object



8
9
10
# File 'app/models/sir_trevor_rails/blocks/featured_pages_block.rb', line 8

def page_options(id)
  (items.detect { |x| x[:id] == id }) || {}
end

#pagesObject



12
13
14
15
16
# File 'app/models/sir_trevor_rails/blocks/featured_pages_block.rb', line 12

def pages
  @pages ||= parent.exhibit.pages.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)


18
19
20
# File 'app/models/sir_trevor_rails/blocks/featured_pages_block.rb', line 18

def pages?
  !pages.empty?
end