Sha256: a2d08c257e92da17753d021847ff9b68179ba48f8120eee9871336b2b19847a8

Contents?: true

Size: 1.06 KB

Versions: 39

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module SirTrevorRails
  module Blocks
    ##
    # Multi-up featured page block
    class FeaturedPagesBlock < SirTrevorRails::Block
      include Displayable

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

      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

      def pages?
        !pages.empty?
      end

      # rubocop:disable Metrics/MethodLength
      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
      # rubocop:enable Metrics/MethodLength
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
blacklight-spotlight-4.3.6 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.3.5 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.3.4 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.3.3 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.3.2 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.3.1 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.3.0 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.2.0 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.1.2 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.1.1 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.1.0 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.0.3 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.0.2 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.0.1 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-4.0.0 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.6.0.beta10 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.6.0.beta9 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.6.0.beta8 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.5.0.4 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.6.0.beta7 app/models/sir_trevor_rails/blocks/featured_pages_block.rb