Sha256: 6c3337fc4b917b724587c2842ffee5e8ad67e8e2da03799490eb08336f69e6f6

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module SirTrevorRails::Blocks
  class SolrDocumentsBlock < SirTrevorRails::Block
    include Textable
    attr_reader :solr_helper
  
    def with_solr_helper solr_helper
      @solr_helper = solr_helper
    end

    def document_options id
      (items.find { |x| x[:id] == id }) || {}
    end

    def documents
      @documents ||= begin
        doc_ids = items.map { |v| v[:id] }
        _, documents = solr_helper.fetch(doc_ids)
        documents.sort { |a,b| document_order.index(a.id) <=> document_order.index(b.id) }
      end
    end

    def documents?
      documents.present?
    end

    def items
      (item || {}).values.select { |x| x[:display] == "true" }
    end

    def document_order
      items.sort_by { |x| x[:weight] }.map { |x| x[:id] }
    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 primary_caption_field
      val = send(:'primary-caption-field')
      unless val.blank?
        val
      end
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blacklight-spotlight-0.4.1 app/models/sir_trevor_rails/blocks/solr_documents_block.rb