Sha256: 5f87b1bb2c71cc1b470692c54e575f252dd214ca0901f3d7785e63636f9c5823

Contents?: true

Size: 1.63 KB

Versions: 21

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require 'builder'

# This module provide Dublin Core export based on the document's semantic values
module Blacklight::Document::DublinCore
  def self.extended(document)
    # Register our exportable formats
    Blacklight::Document::DublinCore.register_export_formats(document)
  end

  def self.register_export_formats(document)
    document.will_export_as(:xml)
    document.will_export_as(:dc_xml, "text/xml")
    document.will_export_as(:oai_dc_xml, "text/xml")
  end

  def dublin_core_field_names
    [:contributor, :coverage, :creator, :date, :description, :format, :identifier, :language, :publisher, :relation, :rights, :source, :subject, :title, :type]
  end

  # dublin core elements are mapped against the #dublin_core_field_names whitelist.
  def export_as_oai_dc_xml
    xml = Builder::XmlMarkup.new
    xml.tag!("oai_dc:dc",
             'xmlns:oai_dc' => "http://www.openarchives.org/OAI/2.0/oai_dc/",
             'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
             'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
             'xsi:schemaLocation' => %(http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd)) do
      to_semantic_values.select { |field, _values| dublin_core_field_name? field }.each do |field, values|
        Array.wrap(values).each do |v|
          xml.tag! "dc:#{field}", v
        end
      end
    end
    xml.target!
  end

  alias_method :export_as_xml, :export_as_oai_dc_xml
  alias_method :export_as_dc_xml, :export_as_oai_dc_xml

  private

  def dublin_core_field_name? field
    dublin_core_field_names.include? field.to_sym
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
blacklight-8.6.1 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.6.0 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.5.1 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.5.0 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.4.0 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.3.0 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.2.2 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.2.1 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.2.0 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.1.0 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.0.1 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.0.0 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.0.0.beta8 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.0.0.beta7 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.0.0.beta6 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.0.0.beta5 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.0.0.beta4 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.0.0.beta3 app/models/concerns/blacklight/document/dublin_core.rb
blacklight-8.0.0.beta2 app/models/concerns/blacklight/document/dublin_core.rb