Sha256: 215cca1d74cc5958a58fe1966bf5a9e48dab79cc3985c24703fc3f843e5a658a

Contents?: true

Size: 1.39 KB

Versions: 33

Compression:

Stored size: 1.39 KB

Contents

module SirTrevorRails
  module Blocks
    ##
    # Multi-up document viewer with text block
    class SolrDocumentsBlock < SirTrevorRails::Block
      include Textable
      include Displayable
      attr_reader :solr_helper

      def with_solr_helper(solr_helper)
        @solr_helper = solr_helper
      end

      def each_document
        return to_enum(:each_document) unless block_given?

        items.each do |i|
          document = documents.detect { |doc| doc.id == i[:id] }
          i[:iiif_tilesource_base] = i.fetch(:iiif_tilesource, '').sub('/info.json', '')
          yield i, document if document
        end
      end

      def documents
        @documents ||= begin
          doc_ids = items.map { |v| v[:id] }
          _, documents = solr_helper.fetch(doc_ids)
          documents
        end
      end

      def documents?
        each_document.any?
      end

      def primary_caption?
        primary_caption_field.present? && send(:'show-primary-caption')
      end

      def secondary_caption?
        secondary_caption_field.present? && send(:'show-secondary-caption')
      end

      def zpr_link?
        zpr_link == 'true'
      end

      def primary_caption_field
        val = send(:'primary-caption-field')
        val unless val.blank?
      end

      def secondary_caption_field
        val = send(:'secondary-caption-field')
        val unless val.blank?
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
blacklight-spotlight-2.4.1 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.4.0 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.3.3 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.3.2 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.3.1 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.3.0 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.2.1 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.2.0 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.1.0 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.0.2 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.0.1 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.0.0 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.0.0.rc6 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.0.0.rc5 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.0.0.rc4 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.0.0.rc3 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.0.0.rc2 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-2.0.0.rc1 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-1.5.1 app/models/sir_trevor_rails/blocks/solr_documents_block.rb
blacklight-spotlight-1.4.1 app/models/sir_trevor_rails/blocks/solr_documents_block.rb