Sha256: 10e3102e16f763e42111df89f0493584329e6e686755776cb86f6570ee5e35a8

Contents?: true

Size: 1.02 KB

Versions: 24

Compression:

Stored size: 1.02 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.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.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

24 entries across 24 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.1 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.rc6 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.rc5 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.rc4 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.rc3 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.rc2 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.rc1 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.alpha.10 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.alpha.9 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.alpha.8 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.alpha.7 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.alpha.6 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.alpha.5 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.alpha.4 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.alpha.3 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.alpha.2 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-3.0.0.alpha.1 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-2.13.0 app/models/sir_trevor_rails/blocks/featured_pages_block.rb
blacklight-spotlight-2.12.1 app/models/sir_trevor_rails/blocks/featured_pages_block.rb